Chromium Code Reviews| 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 final READ = const FileMode(0); | 10 static final READ = const FileMode(0); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 * By default mode is FileMode.READ. | 89 * By default mode is FileMode.READ. |
| 90 */ | 90 */ |
| 91 void open([FileMode mode]); | 91 void open([FileMode mode]); |
| 92 | 92 |
| 93 /** | 93 /** |
| 94 * Synchronously open the file for random access operations. The | 94 * Synchronously open the file for random access operations. The |
| 95 * result is a RandomAccessFile on which random access operations | 95 * result is a RandomAccessFile on which random access operations |
| 96 * can be performed. Opened RandomAccessFiles must be closed using | 96 * can be performed. Opened RandomAccessFiles must be closed using |
| 97 * the [close] method. | 97 * the [close] method. |
| 98 * | 98 * |
| 99 * Files can be opened in three modes: | 99 * See [open] for information on the [:mode:] argument. |
| 100 * | |
| 101 * FileMode.READ: open the file for reading. If the file does not | |
| 102 * exist the [errorHandler] is called. | |
| 103 * | |
| 104 * FileMode.WRITE: open the file for both reading and writing and | |
| 105 * truncate the file to length zero. If the file does not exist the | |
| 106 * file is created. | |
| 107 * | |
| 108 * FileMode.APPEND: same as FileMode.WRITE except that the file is | |
| 109 * not truncated and the position is set to the end of the file. | |
| 110 * | |
| 111 * By default mode is FileMode.READ. | |
| 112 */ | 100 */ |
| 113 RandomAccessFile openSync([FileMode mode]); | 101 RandomAccessFile openSync([FileMode mode]); |
| 114 | 102 |
| 115 /** | 103 /** |
| 116 * Get the canonical full path corresponding to the file name. The | 104 * Get the canonical full path corresponding to the file name. The |
| 117 * [fullPathHandler] is called with the result when the fullPath | 105 * [fullPathHandler] is called with the result when the fullPath |
| 118 * operation completes. | 106 * operation completes. |
| 119 */ | 107 */ |
| 120 void fullPath(); | 108 void fullPath(); |
| 121 | 109 |
| 122 /** | 110 /** |
| 123 * Synchronously get the canonical full path corresponding to the file name. | 111 * Synchronously get the canonical full path corresponding to the file name. |
| 124 */ | 112 */ |
| 125 String fullPathSync(); | 113 String fullPathSync(); |
| 126 | 114 |
| 127 /** | 115 /** |
| 128 * Create a new independent input stream for the file. The file | 116 * Create a new independent input stream for the file. The file |
| 129 * input stream must be closed when no longer used to free up | 117 * input stream must be closed when no longer used to free up system |
| 130 * system resources. | 118 * resources. The [inputStreamHandler] is called with the result |
| 119 * when the openInputStream operation completes. | |
| 131 */ | 120 */ |
| 132 InputStream openInputStream(); | 121 InputStream openInputStream(); |
| 133 | 122 |
| 134 /** | 123 /** |
| 124 * Synchronously create a new independent input stream for the | |
| 125 * file. The file input stream must be closed when no longer used to | |
| 126 * free up system resources. | |
| 127 * | |
| 128 * Even though this call to open the input stream is synchronous | |
| 129 * then the input stream itself will be asynchronous as is the case | |
|
Mads Ager (google)
2012/02/22 13:20:20
is synchronous then the ... will be ..
=>
is synch
Søren Gjesse
2012/02/22 14:03:18
Done.
| |
| 130 * for all input streams. | |
| 131 */ | |
| 132 InputStream openInputStreamSync(); | |
| 133 | |
| 134 /** | |
| 135 * Creates a new independent output stream for the file. The file | 135 * Creates a new independent output stream for the file. The file |
| 136 * 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 |
| 137 * system resources. | 137 * system resources. |
| 138 * | 138 * |
| 139 * An output stream can be opened in two modes: | 139 * An output stream can be opened in two modes: |
| 140 * | 140 * |
| 141 * FileMode.WRITE: create the stream and truncate the underlying | 141 * FileMode.WRITE: create the stream and truncate the underlying |
| 142 * file to length zero. | 142 * file to length zero. |
| 143 * | 143 * |
| 144 * FileMode.APPEND: create the stream and set the position to the end of | 144 * FileMode.APPEND: create the stream and set the position to the end of |
| 145 * the underlying file. | 145 * the underlying file. |
| 146 * | 146 * |
| 147 * By default the mode is FileMode.WRITE. | 147 * By default the mode is FileMode.WRITE. |
| 148 */ | 148 */ |
| 149 OutputStream openOutputStream([FileMode mode]); | 149 OutputStream openOutputStream([FileMode mode]); |
| 150 | 150 |
| 151 /** | 151 /** |
| 152 * Synchronously creates a new independent output stream for the | |
| 153 * file. The file output stream must be closed when no longer used | |
| 154 * to free up system resources. | |
| 155 * | |
| 156 * See [openOutputStream] for information on the [:mode:] argument. | |
| 157 * | |
| 158 * Even though this call to open the output stream is synchronous | |
| 159 * then the output stream itself will be asynchronous as is the case | |
|
Mads Ager (google)
2012/02/22 13:20:20
Ditto.
Søren Gjesse
2012/02/22 14:03:18
Done.
| |
| 160 * for all output streams. | |
| 161 */ | |
| 162 OutputStream openOutputStreamSync([FileMode mode]); | |
| 163 | |
| 164 /** | |
| 152 * Get the name of the file. | 165 * Get the name of the file. |
| 153 */ | 166 */ |
| 154 String get name(); | 167 String get name(); |
| 155 | 168 |
| 156 /** | 169 /** |
| 157 * Sets the handler that gets called when an [exists] operation | 170 * Sets the handler that gets called when an [exists] operation |
| 158 * completes. | 171 * completes. |
| 159 */ | 172 */ |
| 160 void set existsHandler(void handler(bool exists)); | 173 void set existsHandler(void handler(bool exists)); |
| 161 | 174 |
| 162 /** | 175 /** |
| 163 * Sets the handler that gets called when a [create] operation | 176 * Sets the handler that gets called when a [create] operation |
| 164 * completes. | 177 * completes. |
| 165 */ | 178 */ |
| 166 void set createHandler(void handler()); | 179 void set createHandler(void handler()); |
| 167 | 180 |
| 168 /** | 181 /** |
| 169 * Sets the handler that gets called when a [delete] operation | 182 * Sets the handler that gets called when a [delete] operation |
| 170 * completes. | 183 * completes. |
| 171 */ | 184 */ |
| 172 void set deleteHandler(void handler()); | 185 void set deleteHandler(void handler()); |
| 173 | 186 |
| 174 /** | 187 /** |
| 175 * Sets the handler that gets called when an [open] operation | 188 * Sets the handler that gets called when an [open] operation |
| 176 * completes. | 189 * completes. |
| 177 */ | 190 */ |
| 178 void set openHandler(void handler(RandomAccessFile openedFile)); | 191 void set openHandler(void handler(RandomAccessFile openedFile)); |
| 179 | 192 |
| 180 /** | 193 /** |
| 194 * Sets the handler that gets called when an [openInputStream] | |
| 195 * operation completes. | |
| 196 */ | |
| 197 void set inputStreamHandler(void handler(InputStream stream)); | |
| 198 | |
| 199 /** | |
| 200 * Sets the handler that gets called when an [openOutputStream] | |
| 201 * operation completes. | |
| 202 */ | |
| 203 void set outputStreamHandler(void handler(OutputStream stream)); | |
| 204 | |
| 205 /** | |
| 181 * Sets the handler that gets called when a [fullPath] operation | 206 * Sets the handler that gets called when a [fullPath] operation |
| 182 * completes. | 207 * completes. |
| 183 */ | 208 */ |
| 184 void set fullPathHandler(void handler(String path)); | 209 void set fullPathHandler(void handler(String path)); |
| 185 | 210 |
| 186 /** | 211 /** |
| 187 * Sets the handler that gets called when errors occur during | 212 * Sets the handler that gets called when errors occur during |
| 188 * operations on this file. | 213 * operations on this file. |
| 189 */ | 214 */ |
| 190 void set errorHandler(void handler(String error)); | 215 void set errorHandler(void handler(String error)); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 */ | 418 */ |
| 394 void set errorHandler(void handler(String error)); | 419 void set errorHandler(void handler(String error)); |
| 395 } | 420 } |
| 396 | 421 |
| 397 | 422 |
| 398 class FileIOException implements Exception { | 423 class FileIOException implements Exception { |
| 399 const FileIOException([String this.message = ""]); | 424 const FileIOException([String this.message = ""]); |
| 400 String toString() => "FileIOException: $message"; | 425 String toString() => "FileIOException: $message"; |
| 401 final String message; | 426 final String message; |
| 402 } | 427 } |
| OLD | NEW |