| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * FileMode describes the modes in which a file can be opened. | 8 * FileMode describes the modes in which a file can be opened. |
| 9 */ | 9 */ |
| 10 class FileMode { | 10 class FileMode { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 * existing file might fail if there are restrictive permissions on | 53 * existing file might fail if there are restrictive permissions on |
| 54 * the file. | 54 * the file. |
| 55 */ | 55 */ |
| 56 Future<File> create(); | 56 Future<File> create(); |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * Synchronously create the file. Existing files are left untouched | 59 * Synchronously create the file. Existing files are left untouched |
| 60 * by [createSync]. Calling [createSync] on an existing file might fail | 60 * by [createSync]. Calling [createSync] on an existing file might fail |
| 61 * if there are restrictive permissions on the file. | 61 * if there are restrictive permissions on the file. |
| 62 * | 62 * |
| 63 * Throws a [FileIOException] if the operation fails. | 63 * Throws a [FileException] if the operation fails. |
| 64 */ | 64 */ |
| 65 void createSync(); | 65 void createSync(); |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * Delete the file. Returns a [:Future<File>:] that completes with | 68 * Delete the file. Returns a [:Future<File>:] that completes with |
| 69 * the file when it has been deleted. Only a file or a link to a file | 69 * the file when it has been deleted. Only a file or a link to a file |
| 70 * can be deleted with this method, not a directory or a broken link. | 70 * can be deleted with this method, not a directory or a broken link. |
| 71 */ | 71 */ |
| 72 Future<File> delete(); | 72 Future<File> delete(); |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * Synchronously delete the file. Only a file or a link to a file | 75 * Synchronously delete the file. Only a file or a link to a file |
| 76 * can be deleted with this method, not a directory or a broken link. | 76 * can be deleted with this method, not a directory or a broken link. |
| 77 * | 77 * |
| 78 * Throws a [FileIOException] if the operation fails. | 78 * Throws a [FileException] if the operation fails. |
| 79 */ | 79 */ |
| 80 void deleteSync(); | 80 void deleteSync(); |
| 81 | 81 |
| 82 /** | 82 /** |
| 83 * Get a [Directory] object for the directory containing this | 83 * Get a [Directory] object for the directory containing this |
| 84 * file. | 84 * file. |
| 85 */ | 85 */ |
| 86 Directory get directory; | 86 Directory get directory; |
| 87 | 87 |
| 88 /** | 88 /** |
| 89 * Get the length of the file. Returns a [:Future<int>:] that | 89 * Get the length of the file. Returns a [:Future<int>:] that |
| 90 * completes with the length in bytes. | 90 * completes with the length in bytes. |
| 91 */ | 91 */ |
| 92 Future<int> length(); | 92 Future<int> length(); |
| 93 | 93 |
| 94 /** | 94 /** |
| 95 * Synchronously get the length of the file. | 95 * Synchronously get the length of the file. |
| 96 * | 96 * |
| 97 * Throws a [FileIOException] if the operation fails. | 97 * Throws a [FileException] if the operation fails. |
| 98 */ | 98 */ |
| 99 int lengthSync(); | 99 int lengthSync(); |
| 100 | 100 |
| 101 /** | 101 /** |
| 102 * Get the last-modified time of the file. Returns a | 102 * Get the last-modified time of the file. Returns a |
| 103 * [:Future<DateTime>:] that completes with a [DateTime] object for the | 103 * [:Future<DateTime>:] that completes with a [DateTime] object for the |
| 104 * modification date. | 104 * modification date. |
| 105 */ | 105 */ |
| 106 Future<DateTime> lastModified(); | 106 Future<DateTime> lastModified(); |
| 107 | 107 |
| 108 /** | 108 /** |
| 109 * Get the last-modified time of the file. Throws an exception | 109 * Get the last-modified time of the file. Throws an exception |
| 110 * if the file does not exist. | 110 * if the file does not exist. |
| 111 * | 111 * |
| 112 * Throws a [FileIOException] if the operation fails. | 112 * Throws a [FileException] if the operation fails. |
| 113 */ | 113 */ |
| 114 DateTime lastModifiedSync(); | 114 DateTime lastModifiedSync(); |
| 115 | 115 |
| 116 /** | 116 /** |
| 117 * Open the file for random access operations. Returns a | 117 * Open the file for random access operations. Returns a |
| 118 * [:Future<RandomAccessFile>:] that completes with the opened | 118 * [:Future<RandomAccessFile>:] that completes with the opened |
| 119 * random access file. [RandomAccessFile]s must be closed using the | 119 * random access file. [RandomAccessFile]s must be closed using the |
| 120 * [RandomAccessFile.close] method. | 120 * [RandomAccessFile.close] method. |
| 121 * | 121 * |
| 122 * Files can be opened in three modes: | 122 * Files can be opened in three modes: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 133 Future<RandomAccessFile> open({FileMode mode: FileMode.READ}); | 133 Future<RandomAccessFile> open({FileMode mode: FileMode.READ}); |
| 134 | 134 |
| 135 /** | 135 /** |
| 136 * Synchronously open the file for random access operations. The | 136 * Synchronously open the file for random access operations. The |
| 137 * result is a [RandomAccessFile] on which random access operations | 137 * result is a [RandomAccessFile] on which random access operations |
| 138 * can be performed. Opened [RandomAccessFile]s must be closed using | 138 * can be performed. Opened [RandomAccessFile]s must be closed using |
| 139 * the [RandomAccessFile.close] method. | 139 * the [RandomAccessFile.close] method. |
| 140 * | 140 * |
| 141 * See [open] for information on the [mode] argument. | 141 * See [open] for information on the [mode] argument. |
| 142 * | 142 * |
| 143 * Throws a [FileIOException] if the operation fails. | 143 * Throws a [FileException] if the operation fails. |
| 144 */ | 144 */ |
| 145 RandomAccessFile openSync({FileMode mode: FileMode.READ}); | 145 RandomAccessFile openSync({FileMode mode: FileMode.READ}); |
| 146 | 146 |
| 147 /** | 147 /** |
| 148 * Get the canonical full path corresponding to the file path. | 148 * Get the canonical full path corresponding to the file path. |
| 149 * Returns a [:Future<String>:] that completes with the path. | 149 * Returns a [:Future<String>:] that completes with the path. |
| 150 */ | 150 */ |
| 151 Future<String> fullPath(); | 151 Future<String> fullPath(); |
| 152 | 152 |
| 153 /** | 153 /** |
| 154 * Synchronously get the canonical full path corresponding to the file path. | 154 * Synchronously get the canonical full path corresponding to the file path. |
| 155 * | 155 * |
| 156 * Throws a [FileIOException] if the operation fails. | 156 * Throws a [FileException] if the operation fails. |
| 157 */ | 157 */ |
| 158 String fullPathSync(); | 158 String fullPathSync(); |
| 159 | 159 |
| 160 /** | 160 /** |
| 161 * Create a new independent [Stream] for the contents of this file. | 161 * Create a new independent [Stream] for the contents of this file. |
| 162 * | 162 * |
| 163 * If [start] is present, the file will be read from byte-offset [start]. | 163 * If [start] is present, the file will be read from byte-offset [start]. |
| 164 * Otherwise from the beginning (index 0). | 164 * Otherwise from the beginning (index 0). |
| 165 * | 165 * |
| 166 * If [end] is present, only up to byte-index [end] will be read. Otherwise, | 166 * If [end] is present, only up to byte-index [end] will be read. Otherwise, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 194 /** | 194 /** |
| 195 * Read the entire file contents as a list of bytes. Returns a | 195 * Read the entire file contents as a list of bytes. Returns a |
| 196 * [:Future<List<int>>:] that completes with the list of bytes that | 196 * [:Future<List<int>>:] that completes with the list of bytes that |
| 197 * is the contents of the file. | 197 * is the contents of the file. |
| 198 */ | 198 */ |
| 199 Future<List<int>> readAsBytes(); | 199 Future<List<int>> readAsBytes(); |
| 200 | 200 |
| 201 /** | 201 /** |
| 202 * Synchronously read the entire file contents as a list of bytes. | 202 * Synchronously read the entire file contents as a list of bytes. |
| 203 * | 203 * |
| 204 * Throws a [FileIOException] if the operation fails. | 204 * Throws a [FileException] if the operation fails. |
| 205 */ | 205 */ |
| 206 List<int> readAsBytesSync(); | 206 List<int> readAsBytesSync(); |
| 207 | 207 |
| 208 /** | 208 /** |
| 209 * Read the entire file contents as a string using the given | 209 * Read the entire file contents as a string using the given |
| 210 * [Encoding]. | 210 * [Encoding]. |
| 211 * | 211 * |
| 212 * Returns a [:Future<String>:] that completes with the string once | 212 * Returns a [:Future<String>:] that completes with the string once |
| 213 * the file contents has been read. | 213 * the file contents has been read. |
| 214 */ | 214 */ |
| 215 Future<String> readAsString({Encoding encoding: Encoding.UTF_8}); | 215 Future<String> readAsString({Encoding encoding: Encoding.UTF_8}); |
| 216 | 216 |
| 217 /** | 217 /** |
| 218 * Synchronously read the entire file contents as a string using the | 218 * Synchronously read the entire file contents as a string using the |
| 219 * given [Encoding]. | 219 * given [Encoding]. |
| 220 * | 220 * |
| 221 * Throws a [FileIOException] if the operation fails. | 221 * Throws a [FileException] if the operation fails. |
| 222 */ | 222 */ |
| 223 String readAsStringSync({Encoding encoding: Encoding.UTF_8}); | 223 String readAsStringSync({Encoding encoding: Encoding.UTF_8}); |
| 224 | 224 |
| 225 /** | 225 /** |
| 226 * Read the entire file contents as lines of text using the given | 226 * Read the entire file contents as lines of text using the given |
| 227 * [Encoding]. | 227 * [Encoding]. |
| 228 * | 228 * |
| 229 * Returns a [:Future<List<String>>:] that completes with the lines | 229 * Returns a [:Future<List<String>>:] that completes with the lines |
| 230 * once the file contents has been read. | 230 * once the file contents has been read. |
| 231 */ | 231 */ |
| 232 Future<List<String>> readAsLines({Encoding encoding: Encoding.UTF_8}); | 232 Future<List<String>> readAsLines({Encoding encoding: Encoding.UTF_8}); |
| 233 | 233 |
| 234 /** | 234 /** |
| 235 * Synchronously read the entire file contents as lines of text | 235 * Synchronously read the entire file contents as lines of text |
| 236 * using the given [Encoding]. | 236 * using the given [Encoding]. |
| 237 * | 237 * |
| 238 * Throws a [FileIOException] if the operation fails. | 238 * Throws a [FileException] if the operation fails. |
| 239 */ | 239 */ |
| 240 List<String> readAsLinesSync({Encoding encoding: Encoding.UTF_8}); | 240 List<String> readAsLinesSync({Encoding encoding: Encoding.UTF_8}); |
| 241 | 241 |
| 242 /** | 242 /** |
| 243 * Write a list of bytes to a file. | 243 * Write a list of bytes to a file. |
| 244 * | 244 * |
| 245 * Opens the file, writes the list of bytes to it, and closes the file. | 245 * Opens the file, writes the list of bytes to it, and closes the file. |
| 246 * Returns a [:Future<File>:] that completes with this [File] object once | 246 * Returns a [:Future<File>:] that completes with this [File] object once |
| 247 * the entire operation has completed. | 247 * the entire operation has completed. |
| 248 * | 248 * |
| 249 * By default [writeAsBytes] creates the file for writing and truncates the | 249 * By default [writeAsBytes] creates the file for writing and truncates the |
| 250 * file if it already exists. In order to append the bytes to an existing | 250 * file if it already exists. In order to append the bytes to an existing |
| 251 * file, pass [FileMode.APPEND] as the optional mode parameter. | 251 * file, pass [FileMode.APPEND] as the optional mode parameter. |
| 252 */ | 252 */ |
| 253 Future<File> writeAsBytes(List<int> bytes, {FileMode mode: FileMode.WRITE}); | 253 Future<File> writeAsBytes(List<int> bytes, {FileMode mode: FileMode.WRITE}); |
| 254 | 254 |
| 255 /** | 255 /** |
| 256 * Synchronously write a list of bytes to a file. | 256 * Synchronously write a list of bytes to a file. |
| 257 * | 257 * |
| 258 * Opens the file, writes the list of bytes to it and closes the file. | 258 * Opens the file, writes the list of bytes to it and closes the file. |
| 259 * | 259 * |
| 260 * By default [writeAsBytesSync] creates the file for writing and truncates | 260 * By default [writeAsBytesSync] creates the file for writing and truncates |
| 261 * the file if it already exists. In order to append the bytes to an existing | 261 * the file if it already exists. In order to append the bytes to an existing |
| 262 * file, pass [FileMode.APPEND] as the optional mode parameter. | 262 * file, pass [FileMode.APPEND] as the optional mode parameter. |
| 263 * | 263 * |
| 264 * Throws a [FileIOException] if the operation fails. | 264 * Throws a [FileException] if the operation fails. |
| 265 */ | 265 */ |
| 266 void writeAsBytesSync(List<int> bytes, {FileMode mode: FileMode.WRITE}); | 266 void writeAsBytesSync(List<int> bytes, {FileMode mode: FileMode.WRITE}); |
| 267 | 267 |
| 268 /** | 268 /** |
| 269 * Write a string to a file. | 269 * Write a string to a file. |
| 270 * | 270 * |
| 271 * Opens the file, writes the string in the given encoding, and closes the | 271 * Opens the file, writes the string in the given encoding, and closes the |
| 272 * file. Returns a [:Future<File>:] that completes with this [File] object | 272 * file. Returns a [:Future<File>:] that completes with this [File] object |
| 273 * once the entire operation has completed. | 273 * once the entire operation has completed. |
| 274 * | 274 * |
| 275 * By default [writeAsString] creates the file for writing and truncates the | 275 * By default [writeAsString] creates the file for writing and truncates the |
| 276 * file if it already exists. In order to append the bytes to an existing | 276 * file if it already exists. In order to append the bytes to an existing |
| 277 * file, pass [FileMode.APPEND] as the optional mode parameter. | 277 * file, pass [FileMode.APPEND] as the optional mode parameter. |
| 278 */ | 278 */ |
| 279 Future<File> writeAsString(String contents, | 279 Future<File> writeAsString(String contents, |
| 280 {FileMode mode: FileMode.WRITE, | 280 {FileMode mode: FileMode.WRITE, |
| 281 Encoding encoding: Encoding.UTF_8}); | 281 Encoding encoding: Encoding.UTF_8}); |
| 282 | 282 |
| 283 /** | 283 /** |
| 284 * Synchronously write a string to a file. | 284 * Synchronously write a string to a file. |
| 285 * | 285 * |
| 286 * Opens the file, writes the string in the given encoding, and closes the | 286 * Opens the file, writes the string in the given encoding, and closes the |
| 287 * file. | 287 * file. |
| 288 * | 288 * |
| 289 * By default [writeAsStringSync] creates the file for writing and | 289 * By default [writeAsStringSync] creates the file for writing and |
| 290 * truncates the file if it already exists. In order to append the bytes | 290 * truncates the file if it already exists. In order to append the bytes |
| 291 * to an existing file, pass [FileMode.APPEND] as the optional mode | 291 * to an existing file, pass [FileMode.APPEND] as the optional mode |
| 292 * parameter. | 292 * parameter. |
| 293 * | 293 * |
| 294 * Throws a [FileIOException] if the operation fails. | 294 * Throws a [FileException] if the operation fails. |
| 295 */ | 295 */ |
| 296 void writeAsStringSync(String contents, | 296 void writeAsStringSync(String contents, |
| 297 {FileMode mode: FileMode.WRITE, | 297 {FileMode mode: FileMode.WRITE, |
| 298 Encoding encoding: Encoding.UTF_8}); | 298 Encoding encoding: Encoding.UTF_8}); |
| 299 | 299 |
| 300 /** | 300 /** |
| 301 * Get the path of the file. | 301 * Get the path of the file. |
| 302 */ | 302 */ |
| 303 String get path; | 303 String get path; |
| 304 } | 304 } |
| 305 | 305 |
| 306 | 306 |
| 307 /** | 307 /** |
| 308 * [RandomAccessFile] provides random access to the data in a | 308 * [RandomAccessFile] provides random access to the data in a |
| 309 * file. [RandomAccessFile] objects are obtained by calling the | 309 * file. [RandomAccessFile] objects are obtained by calling the |
| 310 * [:open:] method on a [File] object. | 310 * [:open:] method on a [File] object. |
| 311 */ | 311 */ |
| 312 abstract class RandomAccessFile { | 312 abstract class RandomAccessFile { |
| 313 /** | 313 /** |
| 314 * Closes the file. Returns a [:Future<RandomAccessFile>:] that | 314 * Closes the file. Returns a [:Future<RandomAccessFile>:] that |
| 315 * completes with this RandomAccessFile when it has been closed. | 315 * completes with this RandomAccessFile when it has been closed. |
| 316 */ | 316 */ |
| 317 Future<RandomAccessFile> close(); | 317 Future<RandomAccessFile> close(); |
| 318 | 318 |
| 319 /** | 319 /** |
| 320 * Synchronously closes the file. | 320 * Synchronously closes the file. |
| 321 * | 321 * |
| 322 * Throws a [FileIOException] if the operation fails. | 322 * Throws a [FileException] if the operation fails. |
| 323 */ | 323 */ |
| 324 void closeSync(); | 324 void closeSync(); |
| 325 | 325 |
| 326 /** | 326 /** |
| 327 * Reads a byte from the file. Returns a [:Future<int>:] that | 327 * Reads a byte from the file. Returns a [:Future<int>:] that |
| 328 * completes with the byte, or with -1 if end-of-file has been reached. | 328 * completes with the byte, or with -1 if end-of-file has been reached. |
| 329 */ | 329 */ |
| 330 Future<int> readByte(); | 330 Future<int> readByte(); |
| 331 | 331 |
| 332 /** | 332 /** |
| 333 * Synchronously reads a single byte from the file. If end-of-file | 333 * Synchronously reads a single byte from the file. If end-of-file |
| 334 * has been reached -1 is returned. | 334 * has been reached -1 is returned. |
| 335 * | 335 * |
| 336 * Throws a [FileIOException] if the operation fails. | 336 * Throws a [FileException] if the operation fails. |
| 337 */ | 337 */ |
| 338 int readByteSync(); | 338 int readByteSync(); |
| 339 | 339 |
| 340 /** | 340 /** |
| 341 * Reads [bytes] bytes from a file and returns the result as a list of bytes. | 341 * Reads [bytes] bytes from a file and returns the result as a list of bytes. |
| 342 */ | 342 */ |
| 343 Future<List<int>> read(int bytes); | 343 Future<List<int>> read(int bytes); |
| 344 | 344 |
| 345 /** | 345 /** |
| 346 * Synchronously reads a maximum of [bytes] bytes from a file and | 346 * Synchronously reads a maximum of [bytes] bytes from a file and |
| 347 * returns the result in a list of bytes. | 347 * returns the result in a list of bytes. |
| 348 * | 348 * |
| 349 * Throws a [FileIOException] if the operation fails. | 349 * Throws a [FileException] if the operation fails. |
| 350 */ | 350 */ |
| 351 List<int> readSync(int bytes); | 351 List<int> readSync(int bytes); |
| 352 | 352 |
| 353 /** | 353 /** |
| 354 * Reads into an existing List<int> from the file. If [start] is present, the | 354 * Reads into an existing List<int> from the file. If [start] is present, the |
| 355 * bytes will be filled into [buffer] from at index [start], otherwise index | 355 * bytes will be filled into [buffer] from at index [start], otherwise index |
| 356 * 0. If [end] is present, the [end] - [start] bytes will be read into | 356 * 0. If [end] is present, the [end] - [start] bytes will be read into |
| 357 * [buffer], otherwise up to [buffer.length]. If [end] == [start] nothing | 357 * [buffer], otherwise up to [buffer.length]. If [end] == [start] nothing |
| 358 * happends. | 358 * happends. |
| 359 * | 359 * |
| 360 * Returns a [:Future<int>:] that completes with the number of bytes read. | 360 * Returns a [:Future<int>:] that completes with the number of bytes read. |
| 361 */ | 361 */ |
| 362 Future<int> readInto(List<int> buffer, [int start, int end]); | 362 Future<int> readInto(List<int> buffer, [int start, int end]); |
| 363 | 363 |
| 364 /** | 364 /** |
| 365 * Synchronously reads into an existing List<int> from the file. If [start] is | 365 * Synchronously reads into an existing List<int> from the file. If [start] is |
| 366 * present, the bytes will be filled into [buffer] from at index [start], | 366 * present, the bytes will be filled into [buffer] from at index [start], |
| 367 * otherwise index 0. If [end] is present, the [end] - [start] bytes will be | 367 * otherwise index 0. If [end] is present, the [end] - [start] bytes will be |
| 368 * read into [buffer], otherwise up to [buffer.length]. If [end] == [start] | 368 * read into [buffer], otherwise up to [buffer.length]. If [end] == [start] |
| 369 * nothing happends. | 369 * nothing happends. |
| 370 * | 370 * |
| 371 * Throws a [FileIOException] if the operation fails. | 371 * Throws a [FileException] if the operation fails. |
| 372 */ | 372 */ |
| 373 int readIntoSync(List<int> buffer, [int start, int end]); | 373 int readIntoSync(List<int> buffer, [int start, int end]); |
| 374 | 374 |
| 375 /** | 375 /** |
| 376 * Writes a single byte to the file. Returns a | 376 * Writes a single byte to the file. Returns a |
| 377 * [:Future<RandomAccessFile>:] that completes with this | 377 * [:Future<RandomAccessFile>:] that completes with this |
| 378 * RandomAccessFile when the write completes. | 378 * RandomAccessFile when the write completes. |
| 379 */ | 379 */ |
| 380 Future<RandomAccessFile> writeByte(int value); | 380 Future<RandomAccessFile> writeByte(int value); |
| 381 | 381 |
| 382 /** | 382 /** |
| 383 * Synchronously writes a single byte to the file. Returns the | 383 * Synchronously writes a single byte to the file. Returns the |
| 384 * number of bytes successfully written. | 384 * number of bytes successfully written. |
| 385 * | 385 * |
| 386 * Throws a [FileIOException] if the operation fails. | 386 * Throws a [FileException] if the operation fails. |
| 387 */ | 387 */ |
| 388 int writeByteSync(int value); | 388 int writeByteSync(int value); |
| 389 | 389 |
| 390 /** | 390 /** |
| 391 * Writes from a [List<int>] to the file. It will read the buffer from index | 391 * Writes from a [List<int>] to the file. It will read the buffer from index |
| 392 * [start] to index [end]. If [start] is omitted, it'll start from index 0. | 392 * [start] to index [end]. If [start] is omitted, it'll start from index 0. |
| 393 * If [end] is omitted, it will write to end of [buffer]. | 393 * If [end] is omitted, it will write to end of [buffer]. |
| 394 * | 394 * |
| 395 * Returns a [:Future<RandomAccessFile>:] that completes with this | 395 * Returns a [:Future<RandomAccessFile>:] that completes with this |
| 396 * [RandomAccessFile] when the write completes. | 396 * [RandomAccessFile] when the write completes. |
| 397 */ | 397 */ |
| 398 Future<RandomAccessFile> writeFrom(List<int> buffer, [int start, int end]); | 398 Future<RandomAccessFile> writeFrom(List<int> buffer, [int start, int end]); |
| 399 | 399 |
| 400 /** | 400 /** |
| 401 * Synchronously writes from a [List<int>] to the file. It will read the | 401 * Synchronously writes from a [List<int>] to the file. It will read the |
| 402 * buffer from index [start] to index [end]. If [start] is omitted, it'll | 402 * buffer from index [start] to index [end]. If [start] is omitted, it'll |
| 403 * start from index 0. If [end] is omitted, it will write to the end of | 403 * start from index 0. If [end] is omitted, it will write to the end of |
| 404 * [buffer]. | 404 * [buffer]. |
| 405 * | 405 * |
| 406 * Throws a [FileIOException] if the operation fails. | 406 * Throws a [FileException] if the operation fails. |
| 407 */ | 407 */ |
| 408 void writeFromSync(List<int> buffer, [int start, int end]); | 408 void writeFromSync(List<int> buffer, [int start, int end]); |
| 409 | 409 |
| 410 /** | 410 /** |
| 411 * Writes a string to the file using the given [Encoding]. Returns a | 411 * Writes a string to the file using the given [Encoding]. Returns a |
| 412 * [:Future<RandomAccessFile>:] that completes with this | 412 * [:Future<RandomAccessFile>:] that completes with this |
| 413 * RandomAccessFile when the write completes. | 413 * RandomAccessFile when the write completes. |
| 414 */ | 414 */ |
| 415 Future<RandomAccessFile> writeString(String string, | 415 Future<RandomAccessFile> writeString(String string, |
| 416 {Encoding encoding: Encoding.UTF_8}); | 416 {Encoding encoding: Encoding.UTF_8}); |
| 417 | 417 |
| 418 /** | 418 /** |
| 419 * Synchronously writes a single string to the file using the given | 419 * Synchronously writes a single string to the file using the given |
| 420 * [Encoding]. | 420 * [Encoding]. |
| 421 * | 421 * |
| 422 * Throws a [FileIOException] if the operation fails. | 422 * Throws a [FileException] if the operation fails. |
| 423 */ | 423 */ |
| 424 void writeStringSync(String string, | 424 void writeStringSync(String string, |
| 425 {Encoding encoding: Encoding.UTF_8}); | 425 {Encoding encoding: Encoding.UTF_8}); |
| 426 | 426 |
| 427 /** | 427 /** |
| 428 * Gets the current byte position in the file. Returns a | 428 * Gets the current byte position in the file. Returns a |
| 429 * [:Future<int>:] that completes with the position. | 429 * [:Future<int>:] that completes with the position. |
| 430 */ | 430 */ |
| 431 Future<int> position(); | 431 Future<int> position(); |
| 432 | 432 |
| 433 /** | 433 /** |
| 434 * Synchronously gets the current byte position in the file. | 434 * Synchronously gets the current byte position in the file. |
| 435 * | 435 * |
| 436 * Throws a [FileIOException] if the operation fails. | 436 * Throws a [FileException] if the operation fails. |
| 437 */ | 437 */ |
| 438 int positionSync(); | 438 int positionSync(); |
| 439 | 439 |
| 440 /** | 440 /** |
| 441 * Sets the byte position in the file. Returns a | 441 * Sets the byte position in the file. Returns a |
| 442 * [:Future<RandomAccessFile>:] that completes with this | 442 * [:Future<RandomAccessFile>:] that completes with this |
| 443 * RandomAccessFile when the position has been set. | 443 * RandomAccessFile when the position has been set. |
| 444 */ | 444 */ |
| 445 Future<RandomAccessFile> setPosition(int position); | 445 Future<RandomAccessFile> setPosition(int position); |
| 446 | 446 |
| 447 /** | 447 /** |
| 448 * Synchronously sets the byte position in the file. | 448 * Synchronously sets the byte position in the file. |
| 449 * | 449 * |
| 450 * Throws a [FileIOException] if the operation fails. | 450 * Throws a [FileException] if the operation fails. |
| 451 */ | 451 */ |
| 452 void setPositionSync(int position); | 452 void setPositionSync(int position); |
| 453 | 453 |
| 454 /** | 454 /** |
| 455 * Truncates (or extends) the file to [length] bytes. Returns a | 455 * Truncates (or extends) the file to [length] bytes. Returns a |
| 456 * [:Future<RandomAccessFile>:] that completes with this | 456 * [:Future<RandomAccessFile>:] that completes with this |
| 457 * RandomAccessFile when the truncation has been performed. | 457 * RandomAccessFile when the truncation has been performed. |
| 458 */ | 458 */ |
| 459 Future<RandomAccessFile> truncate(int length); | 459 Future<RandomAccessFile> truncate(int length); |
| 460 | 460 |
| 461 /** | 461 /** |
| 462 * Synchronously truncates (or extends) the file to [length] bytes. | 462 * Synchronously truncates (or extends) the file to [length] bytes. |
| 463 * | 463 * |
| 464 * Throws a [FileIOException] if the operation fails. | 464 * Throws a [FileException] if the operation fails. |
| 465 */ | 465 */ |
| 466 void truncateSync(int length); | 466 void truncateSync(int length); |
| 467 | 467 |
| 468 /** | 468 /** |
| 469 * Gets the length of the file. Returns a [:Future<int>:] that | 469 * Gets the length of the file. Returns a [:Future<int>:] that |
| 470 * completes with the length in bytes. | 470 * completes with the length in bytes. |
| 471 */ | 471 */ |
| 472 Future<int> length(); | 472 Future<int> length(); |
| 473 | 473 |
| 474 /** | 474 /** |
| 475 * Synchronously gets the length of the file. | 475 * Synchronously gets the length of the file. |
| 476 * | 476 * |
| 477 * Throws a [FileIOException] if the operation fails. | 477 * Throws a [FileException] if the operation fails. |
| 478 */ | 478 */ |
| 479 int lengthSync(); | 479 int lengthSync(); |
| 480 | 480 |
| 481 /** | 481 /** |
| 482 * Flushes the contents of the file to disk. Returns a | 482 * Flushes the contents of the file to disk. Returns a |
| 483 * [:Future<RandomAccessFile>:] that completes with this | 483 * [:Future<RandomAccessFile>:] that completes with this |
| 484 * RandomAccessFile when the flush operation completes. | 484 * RandomAccessFile when the flush operation completes. |
| 485 */ | 485 */ |
| 486 Future<RandomAccessFile> flush(); | 486 Future<RandomAccessFile> flush(); |
| 487 | 487 |
| 488 /** | 488 /** |
| 489 * Synchronously flushes the contents of the file to disk. | 489 * Synchronously flushes the contents of the file to disk. |
| 490 * | 490 * |
| 491 * Throws a [FileIOException] if the operation fails. | 491 * Throws a [FileException] if the operation fails. |
| 492 */ | 492 */ |
| 493 void flushSync(); | 493 void flushSync(); |
| 494 | 494 |
| 495 /** | 495 /** |
| 496 * Returns a human-readable string for this RandomAccessFile instance. | 496 * Returns a human-readable string for this RandomAccessFile instance. |
| 497 */ | 497 */ |
| 498 String toString(); | 498 String toString(); |
| 499 | 499 |
| 500 /** | 500 /** |
| 501 * Gets the path of the file underlying this RandomAccessFile. | 501 * Gets the path of the file underlying this RandomAccessFile. |
| 502 */ | 502 */ |
| 503 String get path; | 503 String get path; |
| 504 } | 504 } |
| 505 | 505 |
| 506 | 506 |
| 507 class FileIOException implements Exception { | 507 class FileException implements IOException { |
| 508 const FileIOException([String this.message = "", | 508 const FileException([String this.message = "", |
| 509 OSError this.osError = null]); | 509 OSError this.osError = null]); |
| 510 String toString() { | 510 String toString() { |
| 511 StringBuffer sb = new StringBuffer(); | 511 StringBuffer sb = new StringBuffer(); |
| 512 sb.write("FileIOException"); | 512 sb.write("FileException"); |
| 513 if (!message.isEmpty) { | 513 if (!message.isEmpty) { |
| 514 sb.write(": $message"); | 514 sb.write(": $message"); |
| 515 if (osError != null) { | 515 if (osError != null) { |
| 516 sb.write(" ($osError)"); | 516 sb.write(" ($osError)"); |
| 517 } | 517 } |
| 518 } else if (osError != null) { | 518 } else if (osError != null) { |
| 519 sb.write(": osError"); | 519 sb.write(": osError"); |
| 520 } | 520 } |
| 521 return sb.toString(); | 521 return sb.toString(); |
| 522 } | 522 } |
| 523 final String message; | 523 final String message; |
| 524 final OSError osError; | 524 final OSError osError; |
| 525 } | 525 } |
| OLD | NEW |