|
1 // Copyright (c) 1997-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 <e32base.h> |
|
17 #include <e32def.h> |
|
18 |
|
19 #include <f32file.h> // for CFileImportBuffer |
|
20 #include <s32file.h> |
|
21 #include <s32stor.h> |
|
22 |
|
23 #include <inbuf.h> |
|
24 |
|
25 // |
|
26 // class CImportBufferBase |
|
27 // |
|
28 |
|
29 EXPORT_C CImportBufferBase::CImportBufferBase(TInt aSize) |
|
30 :iMaxSize(aSize) |
|
31 {} |
|
32 |
|
33 EXPORT_C CImportBufferBase::~CImportBufferBase() |
|
34 { |
|
35 delete iImportBuffer; |
|
36 } |
|
37 |
|
38 EXPORT_C void CImportBufferBase::ConstructL() |
|
39 { |
|
40 iImportBuffer=HBufC8::NewL(iMaxSize); |
|
41 ResetImportBuffer(); |
|
42 } |
|
43 |
|
44 EXPORT_C void CImportBufferBase::ResetImportBuffer() |
|
45 // |
|
46 { |
|
47 iReadPtr=CONST_CAST(TText8*,iImportBuffer->Ptr()); |
|
48 iTBase=iReadPtr; |
|
49 iEndBuf=iReadPtr; |
|
50 } |
|
51 |
|
52 EXPORT_C void CImportBufferBase::ResetReadPtr() |
|
53 { |
|
54 iReadPtr=iTBase; |
|
55 } |
|
56 |
|
57 EXPORT_C TInt CImportBufferBase::ReadL(TText8& aByte) |
|
58 { |
|
59 if (iReadPtr == iEndBuf) |
|
60 { |
|
61 TInt err = FillImportBuf(); |
|
62 if (err) |
|
63 return err; |
|
64 } |
|
65 aByte = *(iReadPtr++); |
|
66 return KErrNone; |
|
67 } |
|
68 |
|
69 EXPORT_C TInt CImportBufferBase::SeekL(TSeek /*aSeekMode*/, TInt /*anOffset*/) |
|
70 { |
|
71 // not implemented |
|
72 return KErrNotSupported; |
|
73 } |
|
74 |
|
75 EXPORT_C TInt CImportBufferBase::MaxSize() |
|
76 { |
|
77 return iMaxSize; |
|
78 } |
|
79 |
|
80 EXPORT_C void CImportBufferBase::SetLength(TInt aLength) |
|
81 { |
|
82 iEndBuf=iTBase+aLength; |
|
83 } |
|
84 |
|
85 // |
|
86 // class CFileImportBuffer |
|
87 // |
|
88 |
|
89 EXPORT_C CFileImportBuffer::CFileImportBuffer(RFile aSource, TInt aMaxSize) |
|
90 : CImportBufferBase(aMaxSize), iSource(aSource) |
|
91 {} |
|
92 |
|
93 EXPORT_C TInt CFileImportBuffer::SeekL(TSeek aSeekMode, TInt anOffset) |
|
94 { |
|
95 TInt err=iSource.Seek(aSeekMode, anOffset); |
|
96 if (err==KErrNone) |
|
97 return FillImportBuf(); |
|
98 else |
|
99 return err; |
|
100 } |
|
101 |
|
102 EXPORT_C TInt CFileImportBuffer::FillImportBuf() |
|
103 { |
|
104 TPtr8 buf=iImportBuffer->Des(); |
|
105 iSource.Read(buf,MaxSize()); |
|
106 SetLength(buf.Length()); |
|
107 ResetReadPtr(); |
|
108 if (buf.Length() == 0) |
|
109 return KErrEndOfInput; |
|
110 else |
|
111 return KErrNone; |
|
112 } |