|
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: FileUtilities - Provied file utilities |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef FILEUTILITIES_H |
|
20 #define FILEUTILITIES_H |
|
21 |
|
22 #include <list> |
|
23 #include <string> |
|
24 |
|
25 namespace java |
|
26 { |
|
27 namespace fileutils |
|
28 { |
|
29 |
|
30 OS_NONSHARABLE_CLASS(FileUtilities) |
|
31 { |
|
32 public: |
|
33 |
|
34 /** |
|
35 * Returns boolean value indicating if the path specified pointed to a file. |
|
36 * |
|
37 * @param[in] aPath: Absolute path of the file/directory |
|
38 * @return true if the path specified was a file. false otherwise. |
|
39 */ |
|
40 OS_IMPORT static bool isFile(const std::wstring& aPath); |
|
41 |
|
42 /** |
|
43 * Returns boolean value indicating if the path specified pointed to a directory. |
|
44 * |
|
45 * @param[in] aPath: Absolute path of the file/directory |
|
46 * @return true if the path specified was a directory. false otherwise. |
|
47 */ |
|
48 OS_IMPORT static bool isDirectory(const std::wstring& aPath); |
|
49 |
|
50 /** |
|
51 * Checks to see if the path specified exists. |
|
52 * |
|
53 * @param[in] aPath: Absolute path of the file/directory |
|
54 * @return true if the path specified exists. false otherwise. |
|
55 */ |
|
56 OS_IMPORT static bool exists(const std::wstring& aPath); |
|
57 |
|
58 /** |
|
59 * Checks to see if the path specified can be read. |
|
60 * |
|
61 * @param[in] aPath: Absolute path of the file/directory |
|
62 * @return true if the path specified can be read. false otherwise. |
|
63 */ |
|
64 OS_IMPORT static bool canRead(const std::wstring& aPath); |
|
65 |
|
66 /** |
|
67 * Checks to see if the path specified can be written into. |
|
68 * |
|
69 * @param[in] aPath: Absolute path of the file/directory |
|
70 * @return true if the path specified can be written. false otherwise. |
|
71 */ |
|
72 OS_IMPORT static bool canWrite(const std::wstring& aPath); |
|
73 |
|
74 /** |
|
75 * Returns the size of the file. |
|
76 * |
|
77 * @param[in] aPath: Absolute path of the file |
|
78 * @return size of the file in bytes. |
|
79 * @throws errno value in case of error |
|
80 */ |
|
81 OS_IMPORT static long fileSize(const std::wstring& aPath); |
|
82 |
|
83 /** |
|
84 * Returns the last modified time of the file/directory |
|
85 * |
|
86 * @param[in] aPath: Absolute path of the file/directory |
|
87 * @return last modified time of the file. |
|
88 * @throws errno value in case of error |
|
89 */ |
|
90 OS_IMPORT static long lastModified(const std::wstring& aPath); |
|
91 |
|
92 /** |
|
93 * Changes the readable attribute of the file based on the aReadable attribute |
|
94 * |
|
95 * @param[in] aFile: Absolute path of the file/directory |
|
96 * @param[in] aReadable: boolean indicating if read must be allowed or not. |
|
97 * @return 0 in case of success, errno value in case of failure |
|
98 */ |
|
99 OS_IMPORT static int setReadable(const std::wstring& aFile, bool aReadable); |
|
100 |
|
101 /** |
|
102 * Changes the writable attribute of the file based on the aWritable attribute |
|
103 * |
|
104 * @param[in] aFile: Absolute path of the file/directory |
|
105 * @param[in] aWritable: boolean indicating if write must be allowed or not. |
|
106 * @return 0 in case of success, errno value in case of failure |
|
107 */ |
|
108 OS_IMPORT static int setWritable(const std::wstring& aFile, bool aWritable); |
|
109 |
|
110 /** |
|
111 * Returns the available size of the file system. |
|
112 * |
|
113 * @param[in] aFile: Absolute path of the file. |
|
114 * @return Available size of File System, -1 if error during access or |
|
115 * process does not have access to the file system. |
|
116 */ |
|
117 OS_IMPORT static long long availableSize(const std::wstring& aFile); |
|
118 |
|
119 /** |
|
120 * Returns the Total Size of the File System. |
|
121 * |
|
122 * @param[in] aFile: Absolute path of the file. |
|
123 * @return Total Size of File System, -1 if error during access or |
|
124 * process does not have access to the file system. |
|
125 */ |
|
126 OS_IMPORT static long long totalSize(const std::wstring& aFile); |
|
127 |
|
128 /** |
|
129 * Returns the Used Size of the File System. |
|
130 * |
|
131 * @param[in] aFile: Absolute path of the file. |
|
132 * @return Used Size in File System, -1 if error during access or |
|
133 * process does not have access to the file system. |
|
134 */ |
|
135 OS_IMPORT static long long usedSize(const std::wstring& aFile); |
|
136 |
|
137 /** |
|
138 * Checks if the File/Directory is hidden. |
|
139 * In Linux, it is simply a check to see if the File begins with a "." |
|
140 * In File Systems that rely on attributes to differentiate between hidden |
|
141 * and visible files, the method checks those attributes. |
|
142 * |
|
143 * @param[in] aFile: Absolute path of the file. |
|
144 * @return true of the file is hidden, false otherwise |
|
145 */ |
|
146 OS_IMPORT static bool isHidden(const std::wstring& aPath); |
|
147 |
|
148 /** |
|
149 * Lists the roots of the File System. Roots are synonymous to mount points |
|
150 * in Linux file system. |
|
151 * |
|
152 * @return string containing the roots. Delimited by "*" Character. |
|
153 * The implementation using this is responsible to split it into |
|
154 * multiple tokens. |
|
155 */ |
|
156 OS_IMPORT static std::wstring listRoots(); |
|
157 |
|
158 /** |
|
159 * Method to get the contents of a Directory. By default, hidden files are |
|
160 * also included. |
|
161 * |
|
162 * @param[in] dirName: Directory name with path included. |
|
163 * @return string of names delimited by "*" |
|
164 */ |
|
165 OS_IMPORT static std::wstring getDirContents(const std::wstring& aDirName); |
|
166 |
|
167 /** |
|
168 * Method to get the contents of a Directory. |
|
169 * |
|
170 * @param[in] aDirName: Directory name with path included. |
|
171 * @param[in] aIncludeHidden: specifies if hidden files must be included |
|
172 * @return string of names delimited by "*" |
|
173 */ |
|
174 OS_IMPORT static std::wstring getDirContents(const std::wstring& aDirName, const bool aIncludeHidden); |
|
175 |
|
176 /** |
|
177 * Method to get the contents of a Directory. |
|
178 * |
|
179 * @param[in] aDirName: Directory name with path included. |
|
180 * @return a list of strings containing the names of the contents |
|
181 */ |
|
182 OS_IMPORT static std::list<std::wstring> getDirContentsList(const std::wstring& aDirName); |
|
183 |
|
184 /** |
|
185 * Returns the size of the Directory |
|
186 * |
|
187 * @param[in] aDirName: Directory name with complete path |
|
188 * @param[in] aIncludeSubDirs: To specify if the contents of the |
|
189 * sub-directories also needs to be taken while calculating the |
|
190 * size of the file. |
|
191 * @return the size of the Directory |
|
192 */ |
|
193 OS_IMPORT static long getDirSize(const std::wstring& aDirName, const bool aIncludeSubDirs); |
|
194 |
|
195 /** |
|
196 * Creates a directory tree specified. |
|
197 * |
|
198 * @param[in] aDirPath: Directory name with complete path |
|
199 * @return 0 on success, -1 on failure |
|
200 */ |
|
201 OS_IMPORT static int makeDirAll(const std::wstring& aDirPath); |
|
202 |
|
203 }; //end class |
|
204 |
|
205 } //end namespace fileutils |
|
206 } //end namespace java |
|
207 |
|
208 #endif // FILEUTILITIES_H |