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