1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/test/tcryptospi/src/filewriter.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,88 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +/**
1.23 + @file
1.24 + @internalTechnology
1.25 +*/
1.26 +#include "filewriter.h"
1.27 +
1.28 +#include "cryptospi/cryptospidef.h"
1.29 +#include <e32std.h>
1.30 +#include <e32def.h>
1.31 +#include <f32file.h>
1.32 +
1.33 +// a simple utility class to write to a text file given the path in its
1.34 +// NewLC / NewL
1.35 +
1.36 +CFileWriter* CFileWriter::NewL(TPtrC aFilePath)
1.37 + {
1.38 + CFileWriter* self=CFileWriter::NewLC(aFilePath);
1.39 + CleanupStack::Pop(self);
1.40 + return self;
1.41 + }
1.42 +
1.43 +CFileWriter* CFileWriter::NewLC(TPtrC aFilePath)
1.44 + {
1.45 + CFileWriter* self=new(ELeave) CFileWriter();
1.46 + CleanupStack::PushL(self);
1.47 + self->ConstructL(aFilePath);
1.48 + return self;
1.49 + }
1.50 +
1.51 +
1.52 +CFileWriter::~CFileWriter()
1.53 + {
1.54 + // nulled in constructor so safe to call
1.55 + delete iFilePath;
1.56 +
1.57 + iFile.Close();
1.58 + iRfs.Close();
1.59 + }
1.60 +
1.61 +CFileWriter::CFileWriter() : iFilePath(0)
1.62 + {
1.63 + }
1.64 +
1.65 +void CFileWriter::WriteBlockL(TPtrC8 aData)
1.66 + {
1.67 + iFile.Write(aData);
1.68 + }
1.69 +
1.70 +
1.71 +void CFileWriter::CreateFileL()
1.72 +{
1.73 + CleanupClosePushL(iRfs);
1.74 +
1.75 + iRfs.Delete(iFilePath->Des());
1.76 +
1.77 + User::LeaveIfError(iFile.Create(iRfs, iFilePath->Des(), EFileWrite));
1.78 +
1.79 + CleanupStack::Pop(&iRfs);
1.80 +}
1.81 +
1.82 +void CFileWriter::ConstructL(TPtrC aFilePath)
1.83 + {
1.84 + iFilePath = HBufC::NewL(aFilePath.Length());
1.85 +
1.86 + iFilePath->Des().Copy(aFilePath);
1.87 +
1.88 + User::LeaveIfError(iRfs.Connect());
1.89 +
1.90 + CreateFileL();
1.91 + }