OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 /** | 6 /** |
7 * FileMode describes the modes in which a file can be opened. | 7 * FileMode describes the modes in which a file can be opened. |
8 */ | 8 */ |
9 class FileMode { | 9 class FileMode { |
10 static const READ = const FileMode._internal(0); | 10 static const READ = const FileMode._internal(0); |
11 static const WRITE = const FileMode._internal(1); | 11 static const WRITE = const FileMode._internal(1); |
12 static const APPEND = const FileMode._internal(2); | 12 static const APPEND = const FileMode._internal(2); |
13 const FileMode._internal(int this._mode); | 13 const FileMode._internal(int this._mode); |
14 final int _mode; | 14 final int _mode; |
15 } | 15 } |
16 | 16 |
17 | 17 |
18 /** | 18 /** |
19 * [File] objects are references to files. | 19 * [File] objects are references to files. |
20 * | 20 * |
21 * To operate on the underlying file data you need to either get | 21 * To operate on the underlying file data you need to either get |
22 * streams using [openInputStream] and [openOutputStream] or open the | 22 * streams using [openInputStream] and [openOutputStream] or open the |
23 * file for random access operations using [open]. | 23 * file for random access operations using [open]. |
24 */ | 24 */ |
25 interface File default _File { | 25 abstract class File { |
26 /** | 26 /** |
27 * Create a File object. | 27 * Create a File object. |
28 */ | 28 */ |
29 File(String name); | 29 factory File(String name) => new _File(name); |
30 | 30 |
31 /** | 31 /** |
32 * Create a File object from a Path object. | 32 * Create a File object from a Path object. |
33 */ | 33 */ |
34 File.fromPath(Path path); | 34 factory File.fromPath(Path path) => new _File.fromPath(path); |
35 | 35 |
36 /** | 36 /** |
37 * Check if the file exists. Does not block and returns a | 37 * Check if the file exists. Does not block and returns a |
38 * [:Future<bool>:]. | 38 * [:Future<bool>:]. |
39 */ | 39 */ |
40 Future<bool> exists(); | 40 Future<bool> exists(); |
41 | 41 |
42 /** | 42 /** |
43 * Synchronously check if the file exists. | 43 * Synchronously check if the file exists. |
44 */ | 44 */ |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 * | 119 * |
120 * FileMode.READ: open the file for reading. | 120 * FileMode.READ: open the file for reading. |
121 * | 121 * |
122 * FileMode.WRITE: open the file for both reading and writing and | 122 * FileMode.WRITE: open the file for both reading and writing and |
123 * truncate the file to length zero. If the file does not exist the | 123 * truncate the file to length zero. If the file does not exist the |
124 * file is created. | 124 * file is created. |
125 * | 125 * |
126 * FileMode.APPEND: same as FileMode.WRITE except that the file is | 126 * FileMode.APPEND: same as FileMode.WRITE except that the file is |
127 * not truncated. | 127 * not truncated. |
128 * | 128 * |
129 * The default value for [mode] is [:FileMode.READ:]. | 129 * The default value for [mode] is [:FileMode.READ:]. |
Søren Gjesse
2012/09/18 09:34:16
No need for documentation of the default value.
Mads Ager (google)
2012/09/18 10:46:39
Done.
| |
130 */ | 130 */ |
131 Future<RandomAccessFile> open([FileMode mode]); | 131 Future<RandomAccessFile> open([FileMode mode = FileMode.READ]); |
132 | 132 |
133 /** | 133 /** |
134 * Synchronously open the file for random access operations. The | 134 * Synchronously open the file for random access operations. The |
135 * result is a RandomAccessFile on which random access operations | 135 * result is a RandomAccessFile on which random access operations |
136 * can be performed. Opened RandomAccessFiles must be closed using | 136 * can be performed. Opened RandomAccessFiles must be closed using |
137 * the [close] method. | 137 * the [close] method. |
138 * | 138 * |
139 * The default value for [mode] is [:FileMode.READ:]. | 139 * The default value for [mode] is [:FileMode.READ:]. |
Søren Gjesse
2012/09/18 09:34:16
Ditto.
Mads Ager (google)
2012/09/18 10:46:39
Done.
| |
140 * | 140 * |
141 * See [open] for information on the [mode] argument. | 141 * See [open] for information on the [mode] argument. |
142 */ | 142 */ |
143 RandomAccessFile openSync([FileMode mode]); | 143 RandomAccessFile openSync([FileMode mode = FileMode.READ]); |
144 | 144 |
145 /** | 145 /** |
146 * Get the canonical full path corresponding to the file name. | 146 * Get the canonical full path corresponding to the file name. |
147 * Returns a [:Future<String>:] that completes with the path. | 147 * Returns a [:Future<String>:] that completes with the path. |
148 */ | 148 */ |
149 Future<String> fullPath(); | 149 Future<String> fullPath(); |
150 | 150 |
151 /** | 151 /** |
152 * Synchronously get the canonical full path corresponding to the file name. | 152 * Synchronously get the canonical full path corresponding to the file name. |
153 */ | 153 */ |
(...skipping 12 matching lines...) Expand all Loading... | |
166 * system resources. | 166 * system resources. |
167 * | 167 * |
168 * An output stream can be opened in two modes: | 168 * An output stream can be opened in two modes: |
169 * | 169 * |
170 * FileMode.WRITE: create the stream and truncate the underlying | 170 * FileMode.WRITE: create the stream and truncate the underlying |
171 * file to length zero. | 171 * file to length zero. |
172 * | 172 * |
173 * FileMode.APPEND: create the stream and set the position to the end of | 173 * FileMode.APPEND: create the stream and set the position to the end of |
174 * the underlying file. | 174 * the underlying file. |
175 * | 175 * |
176 * By default the mode is FileMode.WRITE. | 176 * By default the mode is FileMode.WRITE. |
Søren Gjesse
2012/09/18 09:34:16
Ditto.
Mads Ager (google)
2012/09/18 10:46:39
Done.
| |
177 */ | 177 */ |
178 OutputStream openOutputStream([FileMode mode]); | 178 OutputStream openOutputStream([FileMode mode = FileMode.WRITE]); |
179 | 179 |
180 /** | 180 /** |
181 * Read the entire file contents as a list of bytes. Returns a | 181 * Read the entire file contents as a list of bytes. Returns a |
182 * [:Future<List<int>>:] that completes with the list of bytes that | 182 * [:Future<List<int>>:] that completes with the list of bytes that |
183 * is the contents of the file. | 183 * is the contents of the file. |
184 */ | 184 */ |
185 Future<List<int>> readAsBytes(); | 185 Future<List<int>> readAsBytes(); |
186 | 186 |
187 /** | 187 /** |
188 * Synchronously read the entire file contents as a list of bytes. | 188 * Synchronously read the entire file contents as a list of bytes. |
189 */ | 189 */ |
190 List<int> readAsBytesSync(); | 190 List<int> readAsBytesSync(); |
191 | 191 |
192 /** | 192 /** |
193 * Read the entire file contents as text using the given | 193 * Read the entire file contents as text using the given |
194 * [encoding]. The default encoding is [:Encoding.UTF_8:]. | 194 * [encoding]. The default encoding is [:Encoding.UTF_8:]. |
Søren Gjesse
2012/09/18 09:34:16
Ditto.
Mads Ager (google)
2012/09/18 10:46:39
Done.
| |
195 * | 195 * |
196 * Returns a [:Future<String>:] that completes with the string once | 196 * Returns a [:Future<String>:] that completes with the string once |
197 * the file contents has been read. | 197 * the file contents has been read. |
198 */ | 198 */ |
199 Future<String> readAsText([Encoding encoding]); | 199 Future<String> readAsText([Encoding encoding = Encoding.UTF_8]); |
200 | 200 |
201 /** | 201 /** |
202 * Synchronously read the entire file contents as text using the | 202 * Synchronously read the entire file contents as text using the |
203 * given [encoding]. The default encoding is [:Encoding.UTF_8:]. | 203 * given [encoding]. The default encoding is [:Encoding.UTF_8:]. |
Søren Gjesse
2012/09/18 09:34:16
Ditto.
Mads Ager (google)
2012/09/18 10:46:39
Done.
| |
204 */ | 204 */ |
205 String readAsTextSync([Encoding encoding]); | 205 String readAsTextSync([Encoding encoding = Encoding.UTF_8]); |
206 | 206 |
207 /** | 207 /** |
208 * Read the entire file contents as lines of text using the give | 208 * Read the entire file contents as lines of text using the give |
209 * [encoding]. The default encoding is [:Encoding.UTF_8:]. | 209 * [encoding]. The default encoding is [:Encoding.UTF_8:]. |
Søren Gjesse
2012/09/18 09:34:16
Ditto.
Mads Ager (google)
2012/09/18 10:46:39
Done.
| |
210 * | 210 * |
211 * Returns a [:Future<List<String>>:] that completes with the lines | 211 * Returns a [:Future<List<String>>:] that completes with the lines |
212 * once the file contents has been read. | 212 * once the file contents has been read. |
213 */ | 213 */ |
214 Future<List<String>> readAsLines([Encoding encoding]); | 214 Future<List<String>> readAsLines([Encoding encoding = Encoding.UTF_8]); |
215 | 215 |
216 /** | 216 /** |
217 * Synchronously read the entire file contents as lines of text | 217 * Synchronously read the entire file contents as lines of text |
218 * using the given [encoding] The default encoding is | 218 * using the given [encoding] The default encoding is |
219 * [:Encoding.UTF_8:]. | 219 * [:Encoding.UTF_8:]. |
Søren Gjesse
2012/09/18 09:34:16
Ditto.
Mads Ager (google)
2012/09/18 10:46:39
Done.
| |
220 */ | 220 */ |
221 List<String> readAsLinesSync([Encoding encoding]); | 221 List<String> readAsLinesSync([Encoding encoding = Encoding.UTF_8]); |
222 | 222 |
223 /** | 223 /** |
224 * Get the name of the file. | 224 * Get the name of the file. |
225 */ | 225 */ |
226 String get name; | 226 String get name; |
227 } | 227 } |
228 | 228 |
229 | 229 |
230 /** | 230 /** |
231 * [RandomAccessFile] provides random access to the data in a | 231 * [RandomAccessFile] provides random access to the data in a |
232 * file. [RandomAccessFile] objects are obtained by calling the | 232 * file. [RandomAccessFile] objects are obtained by calling the |
233 * [:open:] method on a [File] object. | 233 * [:open:] method on a [File] object. |
234 */ | 234 */ |
235 interface RandomAccessFile { | 235 abstract class RandomAccessFile { |
236 /** | 236 /** |
237 * Close the file. Returns a [:Future<RandomAccessFile>:] that | 237 * Close the file. Returns a [:Future<RandomAccessFile>:] that |
238 * completes with this RandomAccessFile when it has been closed. | 238 * completes with this RandomAccessFile when it has been closed. |
239 */ | 239 */ |
240 Future<RandomAccessFile> close(); | 240 Future<RandomAccessFile> close(); |
241 | 241 |
242 /** | 242 /** |
243 * Synchronously close the file. | 243 * Synchronously close the file. |
244 */ | 244 */ |
245 void closeSync(); | 245 void closeSync(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 Future<RandomAccessFile> writeList(List<int> buffer, int offset, int bytes); | 289 Future<RandomAccessFile> writeList(List<int> buffer, int offset, int bytes); |
290 | 290 |
291 /** | 291 /** |
292 * Synchronously write a List<int> to the file. Returns the number | 292 * Synchronously write a List<int> to the file. Returns the number |
293 * of bytes successfully written. | 293 * of bytes successfully written. |
294 */ | 294 */ |
295 int writeListSync(List<int> buffer, int offset, int bytes); | 295 int writeListSync(List<int> buffer, int offset, int bytes); |
296 | 296 |
297 /** | 297 /** |
298 * Write a string to the file using the given [encoding]. The | 298 * Write a string to the file using the given [encoding]. The |
299 * default encoding is UTF-8 - [:Encoding.UTF_8:]. Returns a | 299 * default encoding is UTF-8 - [:Encoding.UTF_8:]. Returns a |
Søren Gjesse
2012/09/18 09:34:16
Ditto.
Mads Ager (google)
2012/09/18 10:46:39
Done.
| |
300 * [:Future<RandomAccessFile>:] that completes with this | 300 * [:Future<RandomAccessFile>:] that completes with this |
301 * RandomAccessFile when the write completes. | 301 * RandomAccessFile when the write completes. |
302 */ | 302 */ |
303 Future<RandomAccessFile> writeString(String string, [Encoding encoding]); | 303 Future<RandomAccessFile> writeString(String string, |
304 [Encoding encoding = Encoding.UTF_8]); | |
304 | 305 |
305 /** | 306 /** |
306 * Synchronously write a single string to the file using the given | 307 * Synchronously write a single string to the file using the given |
307 * [encoding]. Returns the number of characters successfully | 308 * [encoding]. Returns the number of characters successfully |
308 * written. The default encoding is UTF-8 - [:Encoding.UTF_8:]. | 309 * written. The default encoding is UTF-8 - [:Encoding.UTF_8:]. |
Søren Gjesse
2012/09/18 09:34:16
Ditto.
Mads Ager (google)
2012/09/18 10:46:39
Done.
| |
309 */ | 310 */ |
310 int writeStringSync(String string, [Encoding encoding]); | 311 int writeStringSync(String string, |
312 [Encoding encoding = Encoding.UTF_8]); | |
311 | 313 |
312 /** | 314 /** |
313 * Get the current byte position in the file. Returns a | 315 * Get the current byte position in the file. Returns a |
314 * [:Future<int>:] that completes with the position. | 316 * [:Future<int>:] that completes with the position. |
315 */ | 317 */ |
316 Future<int> position(); | 318 Future<int> position(); |
317 | 319 |
318 /** | 320 /** |
319 * Synchronously get the current byte position in the file. | 321 * Synchronously get the current byte position in the file. |
320 */ | 322 */ |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 sb.add(" ($osError)"); | 388 sb.add(" ($osError)"); |
387 } | 389 } |
388 } else if (osError != null) { | 390 } else if (osError != null) { |
389 sb.add(": osError"); | 391 sb.add(": osError"); |
390 } | 392 } |
391 return sb.toString(); | 393 return sb.toString(); |
392 } | 394 } |
393 final String message; | 395 final String message; |
394 final OSError osError; | 396 final OSError osError; |
395 } | 397 } |
OLD | NEW |