compressionlibs/ziplib/test/oldezlib/EZLib/FileBuffer.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "OldEZFilebuffer.h"
       
    17 #include "OldEZstream.h"
       
    18 
       
    19 using namespace TOLDEZLIB;
       
    20 
       
    21 _LIT(KFileBuffer,"FileBuffer");
       
    22 
       
    23 void CEZFileBufferManager::ConstructL(TInt aBufferSize)
       
    24 	{
       
    25 	__ASSERT_ALWAYS(aBufferSize > 0, User::Panic(KFileBuffer, EBadInitialization));
       
    26 
       
    27 	iBufferSize = aBufferSize;
       
    28 
       
    29 	iInputBuffer = new (ELeave) TUint8[iBufferSize];
       
    30 	iOutputBuffer = new (ELeave) TUint8[iBufferSize];
       
    31 
       
    32 	iInputDescriptor.Set(iInputBuffer,0,iBufferSize);
       
    33 	iOutputDescriptor.Set(iOutputBuffer,0,iBufferSize);
       
    34 	}
       
    35 
       
    36 CEZFileBufferManager::~CEZFileBufferManager()
       
    37 	{
       
    38 	delete[] iInputBuffer;
       
    39 	delete[] iOutputBuffer;
       
    40 	}
       
    41 
       
    42 CEZFileBufferManager::CEZFileBufferManager(RFile &aInput, RFile &aOutput) : 
       
    43 	iInputFile(aInput), iOutputFile(aOutput), iInputDescriptor(NULL,0), iOutputDescriptor(NULL,0)
       
    44 	{
       
    45 
       
    46 	}
       
    47 
       
    48 /**
       
    49 Creates a new CEZFileBufferManager object and leave it on the CleanupStack
       
    50 
       
    51 @param aInput the input file
       
    52 @param aOutput the output file
       
    53 @param aBufferSize the required size of the buffers
       
    54 @return the new CEZFileBufferManager object, on the CleanupStack
       
    55 */
       
    56 EXPORT_C CEZFileBufferManager* CEZFileBufferManager::NewLC(RFile &aInput, RFile &aOutput, TInt aBufferSize)
       
    57 	{
       
    58 	CEZFileBufferManager *fb = new (ELeave) CEZFileBufferManager(aInput,aOutput);
       
    59 	CleanupStack::PushL(fb);
       
    60 	fb->ConstructL(aBufferSize);
       
    61 	return fb;
       
    62 	}
       
    63 
       
    64 /**
       
    65 Creates a new CEZFileBufferManager object
       
    66 
       
    67 @param aInput the input file
       
    68 @param aOutput the output file
       
    69 @param aBufferSize the required size of the buffers
       
    70 @return the new CEZFileBufferManager object
       
    71 */
       
    72 EXPORT_C CEZFileBufferManager* CEZFileBufferManager::NewL(RFile &aInput, RFile &aOutput, TInt aBufferSize)
       
    73 	{
       
    74 	CEZFileBufferManager *fb = new (ELeave) CEZFileBufferManager(aInput,aOutput);
       
    75 	CleanupStack::PushL(fb);
       
    76 	fb->ConstructL(aBufferSize);
       
    77 	CleanupStack::Pop();
       
    78 	return fb;
       
    79 	}
       
    80 
       
    81 
       
    82 void CEZFileBufferManager::InitializeL(CEZZStream &aZStream)
       
    83 	{
       
    84 	User::LeaveIfError(iInputFile.Read(iInputDescriptor));
       
    85 	aZStream.SetInput(iInputDescriptor);
       
    86 	aZStream.SetOutput(iOutputDescriptor);
       
    87 	}
       
    88 
       
    89 void CEZFileBufferManager::NeedInputL(CEZZStream &aZStream)
       
    90 	{
       
    91 	User::LeaveIfError(iInputFile.Read(iInputDescriptor));
       
    92 	aZStream.SetInput(iInputDescriptor);
       
    93 	}
       
    94 
       
    95 void CEZFileBufferManager::NeedOutputL(CEZZStream &aZStream)
       
    96 	{
       
    97 	TPtrC8 od = aZStream.OutputDescriptor();
       
    98 	User::LeaveIfError(iOutputFile.Write(od));
       
    99 	aZStream.SetOutput(iOutputDescriptor);
       
   100 	}
       
   101 
       
   102 void CEZFileBufferManager::FinalizeL(CEZZStream &aZStream)
       
   103 	{
       
   104 	TPtrC8 od = aZStream.OutputDescriptor();
       
   105 	User::LeaveIfError(iOutputFile.Write(od));
       
   106 	}