| OLD | NEW |
| 1 // Copyright (c) 2011, 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 final READ = const FileMode(0); | 10 static final READ = const FileMode(0); |
| 11 static final WRITE = const FileMode(1); | 11 static final WRITE = const FileMode(1); |
| 12 static final APPEND = const FileMode(2); | 12 static final APPEND = const FileMode(2); |
| 13 const FileMode(int this.mode); | 13 const FileMode(int this._mode); |
| 14 final int mode; | 14 final int _mode; |
| 15 } | 15 } |
| 16 | 16 |
| 17 |
| 18 /** |
| 19 * [File] objects are references to files. |
| 20 * |
| 21 * To operate on the underlying file data you need to either get |
| 22 * streams using [openInputStream] and [openOutputStream] or open the |
| 23 * file for random access operations using [open]. |
| 24 */ |
| 17 interface File default _File { | 25 interface File default _File { |
| 18 /** | 26 /** |
| 19 * Create a File object. | 27 * Create a File object. |
| 20 */ | 28 */ |
| 21 File(String name); | 29 File(String name); |
| 22 | 30 |
| 23 /** | 31 /** |
| 24 * Check if the file exists. The [existsHandler] is called with the | 32 * Check if the file exists. The [existsHandler] is called with the |
| 25 * result when the operation completes. | 33 * result when the operation completes. |
| 26 */ | 34 */ |
| 27 void exists(); | 35 void exists(); |
| 28 | 36 |
| 29 /** | 37 /** |
| 30 * Synchronously check if the file exists. | 38 * Synchronously check if the file exists. |
| 31 */ | 39 */ |
| 32 bool existsSync(); | 40 bool existsSync(); |
| 33 | 41 |
| 34 /** | 42 /** |
| 35 * Create the file. The [createHandler] is called when the file has | 43 * Create the file. The [createHandler] is called when the file has |
| 36 * been created. The errorHandler is called if the file cannot be | 44 * been created. The [errorHandler] is called if the file cannot be |
| 37 * created. Existing files are left untouched by create. Calling | 45 * created. Existing files are left untouched by create. Calling |
| 38 * create on an existing file might fail if there are restrictive | 46 * create on an existing file might fail if there are restrictive |
| 39 * permissions on the file. | 47 * permissions on the file. |
| 40 */ | 48 */ |
| 41 void create(); | 49 void create(); |
| 42 | 50 |
| 43 /** | 51 /** |
| 44 * Synchronously create the file. Existing files are left untouched | 52 * Synchronously create the file. Existing files are left untouched |
| 45 * by create. Calling create on an existing file might fail if there | 53 * by create. Calling create on an existing file might fail if there |
| 46 * are restrictive permissions on the file. | 54 * are restrictive permissions on the file. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 * output stream must be closed when no longer used to free up | 136 * output stream must be closed when no longer used to free up |
| 129 * system resources. | 137 * system resources. |
| 130 */ | 138 */ |
| 131 OutputStream openOutputStream(); | 139 OutputStream openOutputStream(); |
| 132 | 140 |
| 133 /** | 141 /** |
| 134 * Get the name of the file. | 142 * Get the name of the file. |
| 135 */ | 143 */ |
| 136 String get name(); | 144 String get name(); |
| 137 | 145 |
| 138 // Event handlers. | 146 /** |
| 147 * Sets the handler that gets called when an [exists] operation |
| 148 * completes. |
| 149 */ |
| 139 void set existsHandler(void handler(bool exists)); | 150 void set existsHandler(void handler(bool exists)); |
| 151 |
| 152 /** |
| 153 * Sets the handler that gets called when a [create] operation |
| 154 * completes. |
| 155 */ |
| 140 void set createHandler(void handler()); | 156 void set createHandler(void handler()); |
| 157 |
| 158 /** |
| 159 * Sets the handler that gets called when a [delete] operation |
| 160 * completes. |
| 161 */ |
| 141 void set deleteHandler(void handler()); | 162 void set deleteHandler(void handler()); |
| 163 |
| 164 /** |
| 165 * Sets the handler that gets called when an [open] operation |
| 166 * completes. |
| 167 */ |
| 142 void set openHandler(void handler(RandomAccessFile openedFile)); | 168 void set openHandler(void handler(RandomAccessFile openedFile)); |
| 169 |
| 170 /** |
| 171 * Sets the handler that gets called when a [fullPath] operation |
| 172 * completes. |
| 173 */ |
| 143 void set fullPathHandler(void handler(String path)); | 174 void set fullPathHandler(void handler(String path)); |
| 175 |
| 176 /** |
| 177 * Sets the handler that gets called when errors occur during |
| 178 * operations on this file. |
| 179 */ |
| 144 void set errorHandler(void handler(String error)); | 180 void set errorHandler(void handler(String error)); |
| 145 } | 181 } |
| 146 | 182 |
| 147 | 183 |
| 184 /** |
| 185 * [RandomAccessFile] provides random access to the data in a |
| 186 * file. [RandomAccessFile] objects are obtained by calling the |
| 187 * [:open:] method on a [File] object. |
| 188 */ |
| 148 interface RandomAccessFile { | 189 interface RandomAccessFile { |
| 149 /** | 190 /** |
| 150 * Close the file. When the file is closed the closeHandler is | 191 * Close the file. When the file is closed the [closeHandler] is |
| 151 * called. | 192 * called. |
| 152 */ | 193 */ |
| 153 void close(); | 194 void close(); |
| 154 | 195 |
| 155 /** | 196 /** |
| 156 * Synchronously close the file. | 197 * Synchronously close the file. |
| 157 */ | 198 */ |
| 158 void closeSync(); | 199 void closeSync(); |
| 159 | 200 |
| 160 /** | 201 /** |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 /** | 316 /** |
| 276 * Synchronously flush the contents of the file to disk. | 317 * Synchronously flush the contents of the file to disk. |
| 277 */ | 318 */ |
| 278 void flushSync(); | 319 void flushSync(); |
| 279 | 320 |
| 280 /** | 321 /** |
| 281 * Get the name of the file. | 322 * Get the name of the file. |
| 282 */ | 323 */ |
| 283 String get name(); | 324 String get name(); |
| 284 | 325 |
| 326 /** |
| 327 * Sets the handler that gets called when a [close] operation |
| 328 * completes. |
| 329 */ |
| 285 void set closeHandler(void handler()); | 330 void set closeHandler(void handler()); |
| 331 |
| 332 /** |
| 333 * Sets the handler that gets called when a [readByte] operation |
| 334 * completes. |
| 335 */ |
| 286 void set readByteHandler(void handler(int byte)); | 336 void set readByteHandler(void handler(int byte)); |
| 337 |
| 338 /** |
| 339 * Sets the handler that gets called when a [readList] operation |
| 340 * completes. |
| 341 */ |
| 287 void set readListHandler(void handler(int read)); | 342 void set readListHandler(void handler(int read)); |
| 343 |
| 344 /** |
| 345 * Sets the handler that gets called when there are no more write |
| 346 * operations pending for this file. |
| 347 */ |
| 288 void set noPendingWriteHandler(void handler()); | 348 void set noPendingWriteHandler(void handler()); |
| 349 |
| 350 /** |
| 351 * Sets the handler that gets called when a [position] operation |
| 352 * completes. |
| 353 */ |
| 289 void set positionHandler(void handler(int position)); | 354 void set positionHandler(void handler(int position)); |
| 355 |
| 356 /** |
| 357 * Sets the handler that gets called when a [setPosition] operation |
| 358 * completes. |
| 359 */ |
| 290 void set setPositionHandler(void handler()); | 360 void set setPositionHandler(void handler()); |
| 361 |
| 362 /** |
| 363 * Sets the handler that gets called when a [truncate] operation |
| 364 * completes. |
| 365 */ |
| 291 void set truncateHandler(void handler()); | 366 void set truncateHandler(void handler()); |
| 367 |
| 368 /** |
| 369 * Sets the handler that gets called when a [length] operation |
| 370 * completes. |
| 371 */ |
| 292 void set lengthHandler(void handler(int length)); | 372 void set lengthHandler(void handler(int length)); |
| 373 |
| 374 /** |
| 375 * Sets the handler that gets called when a [flush] operation |
| 376 * completes. |
| 377 */ |
| 293 void set flushHandler(void handler()); | 378 void set flushHandler(void handler()); |
| 379 |
| 380 /** |
| 381 * Sets the handler that gets called when errors occur when |
| 382 * operating on this file. |
| 383 */ |
| 294 void set errorHandler(void handler(String error)); | 384 void set errorHandler(void handler(String error)); |
| 295 } | 385 } |
| 296 | 386 |
| 297 | 387 |
| 298 class FileIOException implements Exception { | 388 class FileIOException implements Exception { |
| 299 const FileIOException([String this.message = ""]); | 389 const FileIOException([String this.message = ""]); |
| 300 String toString() => "FileIOException: $message"; | 390 String toString() => "FileIOException: $message"; |
| 301 final String message; | 391 final String message; |
| 302 } | 392 } |
| OLD | NEW |