|
1 /* |
|
2 * Copyright (c) 2008 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 "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: Handler for File IO Operations |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef NATIVEFILEIOHANDLER_H |
|
20 #define NATIVEFILEIOHANDLER_H |
|
21 |
|
22 #include <string> |
|
23 |
|
24 namespace java |
|
25 { |
|
26 namespace fileutils |
|
27 { |
|
28 |
|
29 /** |
|
30 * Implements methods to read/write data from the native file system. |
|
31 */ |
|
32 OS_NONSHARABLE_CLASS(NativeFileIOHandler) |
|
33 { |
|
34 public: |
|
35 NativeFileIOHandler(const std::wstring aName); |
|
36 virtual ~NativeFileIOHandler(); |
|
37 |
|
38 /** |
|
39 * Reads data from the file into aBuffer upto aLength bytes. |
|
40 * Returns the amount of data read. |
|
41 * In case of errors, exception is thrown with errno value. |
|
42 */ |
|
43 virtual int readBytes(char* aBuffer, int aLength); |
|
44 |
|
45 /** |
|
46 * Writes data from aBuffer into the file upto aLength bytes. |
|
47 * Returns the amount of data written. |
|
48 * In case of errors, exception is thrown with errno value. |
|
49 */ |
|
50 virtual int writeBytes(char* aBuffer, int aLength); |
|
51 |
|
52 /** |
|
53 * Stops read operation. In case the file is opened in read-write mode and |
|
54 * if the write operations are in progress, the file is kept open to allow |
|
55 * for write operations. Else the file is closed. |
|
56 */ |
|
57 virtual void stopReading(); |
|
58 |
|
59 /** |
|
60 * Stops write operation. In case the file is opened in read-write mode and |
|
61 * if the read operations are in progress, the file is kept open to allow |
|
62 * for read operations. Else the file is closed. |
|
63 */ |
|
64 virtual void stopWriting(); |
|
65 |
|
66 /** |
|
67 * Opens the file specified during the construction of the object for read |
|
68 * operations. |
|
69 * @throws errno value in case open failed. |
|
70 */ |
|
71 virtual void openForReading(); |
|
72 |
|
73 /** |
|
74 * Opens the file specified during the construction of the object for write |
|
75 * operations. |
|
76 * @throws errno value in case open failed. |
|
77 */ |
|
78 virtual void openForWriting(const long aOffset); |
|
79 |
|
80 /** |
|
81 * Skips aOffset number of bytes. |
|
82 * Positive value of aOffset moves the position forward and negatve backwards. |
|
83 * Return value is the actual value that can be skipped. |
|
84 */ |
|
85 virtual long skip(const long aOffset); |
|
86 |
|
87 /** |
|
88 * Closes the file descriptors but will not delete all data. |
|
89 * On next call to read or write, we continue from previous offset. |
|
90 */ |
|
91 virtual void closeFileToReopen(); |
|
92 |
|
93 /** |
|
94 * Returns the amount of data available in the file from current read offset. |
|
95 */ |
|
96 virtual long available(); |
|
97 |
|
98 protected: |
|
99 virtual void handleReopenCase(); |
|
100 |
|
101 private: |
|
102 void closeStream(); |
|
103 |
|
104 NativeFileIOHandler(); |
|
105 |
|
106 protected: |
|
107 // Name of the file to which the stream is opened |
|
108 std::wstring mFileName; |
|
109 |
|
110 // Will be set in case the descriptors were closed temporarily. On next call |
|
111 // to read or write, we re-open the file and continue with previous offset. |
|
112 bool mClosedTemporarily; |
|
113 private: |
|
114 // Stream to do read and write |
|
115 int mFileDescriptor; |
|
116 |
|
117 // Holds the mode in which the file has to be opened |
|
118 int mFileAccessMode; |
|
119 |
|
120 // Holds the current read position |
|
121 long mReadPosition; |
|
122 |
|
123 // Holds the current write position |
|
124 long mWritePosition; |
|
125 |
|
126 }; |
|
127 |
|
128 } // end namespace fileutils |
|
129 } // end namespace java |
|
130 |
|
131 #endif // NATIVEFILEIOHANDLER_H |