sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: #include "OldEZFilebuffer.h"
sl@0: #include "OldEZstream.h"
sl@0: 
sl@0: using namespace TOLDEZLIB;
sl@0: 
sl@0: _LIT(KFileBuffer,"FileBuffer");
sl@0: 
sl@0: void CEZFileBufferManager::ConstructL(TInt aBufferSize)
sl@0: 	{
sl@0: 	__ASSERT_ALWAYS(aBufferSize > 0, User::Panic(KFileBuffer, EBadInitialization));
sl@0: 
sl@0: 	iBufferSize = aBufferSize;
sl@0: 
sl@0: 	iInputBuffer = new (ELeave) TUint8[iBufferSize];
sl@0: 	iOutputBuffer = new (ELeave) TUint8[iBufferSize];
sl@0: 
sl@0: 	iInputDescriptor.Set(iInputBuffer,0,iBufferSize);
sl@0: 	iOutputDescriptor.Set(iOutputBuffer,0,iBufferSize);
sl@0: 	}
sl@0: 
sl@0: CEZFileBufferManager::~CEZFileBufferManager()
sl@0: 	{
sl@0: 	delete[] iInputBuffer;
sl@0: 	delete[] iOutputBuffer;
sl@0: 	}
sl@0: 
sl@0: CEZFileBufferManager::CEZFileBufferManager(RFile &aInput, RFile &aOutput) : 
sl@0: 	iInputFile(aInput), iOutputFile(aOutput), iInputDescriptor(NULL,0), iOutputDescriptor(NULL,0)
sl@0: 	{
sl@0: 
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: Creates a new CEZFileBufferManager object and leave it on the CleanupStack
sl@0: 
sl@0: @param aInput the input file
sl@0: @param aOutput the output file
sl@0: @param aBufferSize the required size of the buffers
sl@0: @return the new CEZFileBufferManager object, on the CleanupStack
sl@0: */
sl@0: EXPORT_C CEZFileBufferManager* CEZFileBufferManager::NewLC(RFile &aInput, RFile &aOutput, TInt aBufferSize)
sl@0: 	{
sl@0: 	CEZFileBufferManager *fb = new (ELeave) CEZFileBufferManager(aInput,aOutput);
sl@0: 	CleanupStack::PushL(fb);
sl@0: 	fb->ConstructL(aBufferSize);
sl@0: 	return fb;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: Creates a new CEZFileBufferManager object
sl@0: 
sl@0: @param aInput the input file
sl@0: @param aOutput the output file
sl@0: @param aBufferSize the required size of the buffers
sl@0: @return the new CEZFileBufferManager object
sl@0: */
sl@0: EXPORT_C CEZFileBufferManager* CEZFileBufferManager::NewL(RFile &aInput, RFile &aOutput, TInt aBufferSize)
sl@0: 	{
sl@0: 	CEZFileBufferManager *fb = new (ELeave) CEZFileBufferManager(aInput,aOutput);
sl@0: 	CleanupStack::PushL(fb);
sl@0: 	fb->ConstructL(aBufferSize);
sl@0: 	CleanupStack::Pop();
sl@0: 	return fb;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: void CEZFileBufferManager::InitializeL(CEZZStream &aZStream)
sl@0: 	{
sl@0: 	User::LeaveIfError(iInputFile.Read(iInputDescriptor));
sl@0: 	aZStream.SetInput(iInputDescriptor);
sl@0: 	aZStream.SetOutput(iOutputDescriptor);
sl@0: 	}
sl@0: 
sl@0: void CEZFileBufferManager::NeedInputL(CEZZStream &aZStream)
sl@0: 	{
sl@0: 	User::LeaveIfError(iInputFile.Read(iInputDescriptor));
sl@0: 	aZStream.SetInput(iInputDescriptor);
sl@0: 	}
sl@0: 
sl@0: void CEZFileBufferManager::NeedOutputL(CEZZStream &aZStream)
sl@0: 	{
sl@0: 	TPtrC8 od = aZStream.OutputDescriptor();
sl@0: 	User::LeaveIfError(iOutputFile.Write(od));
sl@0: 	aZStream.SetOutput(iOutputDescriptor);
sl@0: 	}
sl@0: 
sl@0: void CEZFileBufferManager::FinalizeL(CEZZStream &aZStream)
sl@0: 	{
sl@0: 	TPtrC8 od = aZStream.OutputDescriptor();
sl@0: 	User::LeaveIfError(iOutputFile.Write(od));
sl@0: 	}