os/security/crypto/weakcryptospi/test/tcryptospi/src/filewriter.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 /**
    20  @file
    21  @internalTechnology
    22 */
    23 #include "filewriter.h"
    24 
    25 #include "cryptospi/cryptospidef.h"
    26 #include <e32std.h>
    27 #include <e32def.h>
    28 #include <f32file.h>
    29 
    30 // a simple utility class to write to a text file given the path in its 
    31 // NewLC / NewL 
    32 
    33 CFileWriter* CFileWriter::NewL(TPtrC aFilePath)
    34 	{
    35 	CFileWriter* self=CFileWriter::NewLC(aFilePath);
    36 	CleanupStack::Pop(self);
    37 	return self;				
    38 	}
    39 
    40 CFileWriter* CFileWriter::NewLC(TPtrC aFilePath)
    41 	{
    42 	CFileWriter* self=new(ELeave) CFileWriter();
    43 	CleanupStack::PushL(self);
    44 	self->ConstructL(aFilePath);
    45 	return self;				
    46 	}
    47 
    48 	
    49 CFileWriter::~CFileWriter()
    50 	{
    51 	// nulled in constructor so safe to call
    52 	delete iFilePath;
    53 	
    54 	iFile.Close();
    55 	iRfs.Close();
    56 	}
    57 	
    58 CFileWriter::CFileWriter() : iFilePath(0)
    59 	{
    60 	}
    61 
    62 void CFileWriter::WriteBlockL(TPtrC8 aData)
    63 	{
    64 	iFile.Write(aData);
    65 	}
    66 	
    67 	
    68 void CFileWriter::CreateFileL()
    69 {
    70 	CleanupClosePushL(iRfs);
    71 	
    72 	iRfs.Delete(iFilePath->Des());
    73 
    74 	User::LeaveIfError(iFile.Create(iRfs, iFilePath->Des(), EFileWrite));
    75 
    76 	CleanupStack::Pop(&iRfs);
    77 }	
    78 	
    79 void CFileWriter::ConstructL(TPtrC aFilePath)	
    80 	{
    81 	iFilePath = HBufC::NewL(aFilePath.Length());
    82 	
    83 	iFilePath->Des().Copy(aFilePath);
    84 
    85 	User::LeaveIfError(iRfs.Connect());
    86 	
    87 	CreateFileL();
    88 	}