Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: runtime/bin/file.dart

Issue 10938010: Switch from interfaces to abstract classes in dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Add test binaries. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/directory.dart ('k') | runtime/bin/http.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 * Files can be opened in three modes: 118 * Files can be opened in three modes:
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 *
129 * The default value for [mode] is [:FileMode.READ:].
130 */ 128 */
131 Future<RandomAccessFile> open([FileMode mode]); 129 Future<RandomAccessFile> open([FileMode mode = FileMode.READ]);
132 130
133 /** 131 /**
134 * Synchronously open the file for random access operations. The 132 * Synchronously open the file for random access operations. The
135 * result is a RandomAccessFile on which random access operations 133 * result is a RandomAccessFile on which random access operations
136 * can be performed. Opened RandomAccessFiles must be closed using 134 * can be performed. Opened RandomAccessFiles must be closed using
137 * the [close] method. 135 * the [close] method.
138 * 136 *
139 * The default value for [mode] is [:FileMode.READ:].
140 *
141 * See [open] for information on the [mode] argument. 137 * See [open] for information on the [mode] argument.
142 */ 138 */
143 RandomAccessFile openSync([FileMode mode]); 139 RandomAccessFile openSync([FileMode mode = FileMode.READ]);
144 140
145 /** 141 /**
146 * Get the canonical full path corresponding to the file name. 142 * Get the canonical full path corresponding to the file name.
147 * Returns a [:Future<String>:] that completes with the path. 143 * Returns a [:Future<String>:] that completes with the path.
148 */ 144 */
149 Future<String> fullPath(); 145 Future<String> fullPath();
150 146
151 /** 147 /**
152 * Synchronously get the canonical full path corresponding to the file name. 148 * Synchronously get the canonical full path corresponding to the file name.
153 */ 149 */
(...skipping 11 matching lines...) Expand all
165 * output stream must be closed when no longer used to free up 161 * output stream must be closed when no longer used to free up
166 * system resources. 162 * system resources.
167 * 163 *
168 * An output stream can be opened in two modes: 164 * An output stream can be opened in two modes:
169 * 165 *
170 * FileMode.WRITE: create the stream and truncate the underlying 166 * FileMode.WRITE: create the stream and truncate the underlying
171 * file to length zero. 167 * file to length zero.
172 * 168 *
173 * FileMode.APPEND: create the stream and set the position to the end of 169 * FileMode.APPEND: create the stream and set the position to the end of
174 * the underlying file. 170 * the underlying file.
175 *
176 * By default the mode is FileMode.WRITE.
177 */ 171 */
178 OutputStream openOutputStream([FileMode mode]); 172 OutputStream openOutputStream([FileMode mode = FileMode.WRITE]);
179 173
180 /** 174 /**
181 * Read the entire file contents as a list of bytes. Returns a 175 * Read the entire file contents as a list of bytes. Returns a
182 * [:Future<List<int>>:] that completes with the list of bytes that 176 * [:Future<List<int>>:] that completes with the list of bytes that
183 * is the contents of the file. 177 * is the contents of the file.
184 */ 178 */
185 Future<List<int>> readAsBytes(); 179 Future<List<int>> readAsBytes();
186 180
187 /** 181 /**
188 * Synchronously read the entire file contents as a list of bytes. 182 * Synchronously read the entire file contents as a list of bytes.
189 */ 183 */
190 List<int> readAsBytesSync(); 184 List<int> readAsBytesSync();
191 185
192 /** 186 /**
193 * Read the entire file contents as text using the given 187 * Read the entire file contents as text using the given
194 * [encoding]. The default encoding is [:Encoding.UTF_8:]. 188 * [encoding].
195 * 189 *
196 * Returns a [:Future<String>:] that completes with the string once 190 * Returns a [:Future<String>:] that completes with the string once
197 * the file contents has been read. 191 * the file contents has been read.
198 */ 192 */
199 Future<String> readAsText([Encoding encoding]); 193 Future<String> readAsText([Encoding encoding = Encoding.UTF_8]);
200 194
201 /** 195 /**
202 * Synchronously read the entire file contents as text using the 196 * Synchronously read the entire file contents as text using the
203 * given [encoding]. The default encoding is [:Encoding.UTF_8:]. 197 * given [encoding].
204 */ 198 */
205 String readAsTextSync([Encoding encoding]); 199 String readAsTextSync([Encoding encoding = Encoding.UTF_8]);
206 200
207 /** 201 /**
208 * Read the entire file contents as lines of text using the give 202 * Read the entire file contents as lines of text using the give
209 * [encoding]. The default encoding is [:Encoding.UTF_8:]. 203 * [encoding].
210 * 204 *
211 * Returns a [:Future<List<String>>:] that completes with the lines 205 * Returns a [:Future<List<String>>:] that completes with the lines
212 * once the file contents has been read. 206 * once the file contents has been read.
213 */ 207 */
214 Future<List<String>> readAsLines([Encoding encoding]); 208 Future<List<String>> readAsLines([Encoding encoding = Encoding.UTF_8]);
215 209
216 /** 210 /**
217 * Synchronously read the entire file contents as lines of text 211 * Synchronously read the entire file contents as lines of text
218 * using the given [encoding] The default encoding is 212 * using the given [encoding].
219 * [:Encoding.UTF_8:].
220 */ 213 */
221 List<String> readAsLinesSync([Encoding encoding]); 214 List<String> readAsLinesSync([Encoding encoding = Encoding.UTF_8]);
222 215
223 /** 216 /**
224 * Get the name of the file. 217 * Get the name of the file.
225 */ 218 */
226 String get name; 219 String get name;
227 } 220 }
228 221
229 222
230 /** 223 /**
231 * [RandomAccessFile] provides random access to the data in a 224 * [RandomAccessFile] provides random access to the data in a
232 * file. [RandomAccessFile] objects are obtained by calling the 225 * file. [RandomAccessFile] objects are obtained by calling the
233 * [:open:] method on a [File] object. 226 * [:open:] method on a [File] object.
234 */ 227 */
235 interface RandomAccessFile { 228 abstract class RandomAccessFile {
236 /** 229 /**
237 * Close the file. Returns a [:Future<RandomAccessFile>:] that 230 * Close the file. Returns a [:Future<RandomAccessFile>:] that
238 * completes with this RandomAccessFile when it has been closed. 231 * completes with this RandomAccessFile when it has been closed.
239 */ 232 */
240 Future<RandomAccessFile> close(); 233 Future<RandomAccessFile> close();
241 234
242 /** 235 /**
243 * Synchronously close the file. 236 * Synchronously close the file.
244 */ 237 */
245 void closeSync(); 238 void closeSync();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 */ 281 */
289 Future<RandomAccessFile> writeList(List<int> buffer, int offset, int bytes); 282 Future<RandomAccessFile> writeList(List<int> buffer, int offset, int bytes);
290 283
291 /** 284 /**
292 * Synchronously write a List<int> to the file. Returns the number 285 * Synchronously write a List<int> to the file. Returns the number
293 * of bytes successfully written. 286 * of bytes successfully written.
294 */ 287 */
295 int writeListSync(List<int> buffer, int offset, int bytes); 288 int writeListSync(List<int> buffer, int offset, int bytes);
296 289
297 /** 290 /**
298 * Write a string to the file using the given [encoding]. The 291 * Write a string to the file using the given [encoding]. Returns a
299 * default encoding is UTF-8 - [:Encoding.UTF_8:]. Returns a
300 * [:Future<RandomAccessFile>:] that completes with this 292 * [:Future<RandomAccessFile>:] that completes with this
301 * RandomAccessFile when the write completes. 293 * RandomAccessFile when the write completes.
302 */ 294 */
303 Future<RandomAccessFile> writeString(String string, [Encoding encoding]); 295 Future<RandomAccessFile> writeString(String string,
296 [Encoding encoding = Encoding.UTF_8]);
304 297
305 /** 298 /**
306 * Synchronously write a single string to the file using the given 299 * Synchronously write a single string to the file using the given
307 * [encoding]. Returns the number of characters successfully 300 * [encoding]. Returns the number of characters successfully
308 * written. The default encoding is UTF-8 - [:Encoding.UTF_8:]. 301 * written.
309 */ 302 */
310 int writeStringSync(String string, [Encoding encoding]); 303 int writeStringSync(String string,
304 [Encoding encoding = Encoding.UTF_8]);
311 305
312 /** 306 /**
313 * Get the current byte position in the file. Returns a 307 * Get the current byte position in the file. Returns a
314 * [:Future<int>:] that completes with the position. 308 * [:Future<int>:] that completes with the position.
315 */ 309 */
316 Future<int> position(); 310 Future<int> position();
317 311
318 /** 312 /**
319 * Synchronously get the current byte position in the file. 313 * Synchronously get the current byte position in the file.
320 */ 314 */
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 sb.add(" ($osError)"); 380 sb.add(" ($osError)");
387 } 381 }
388 } else if (osError != null) { 382 } else if (osError != null) {
389 sb.add(": osError"); 383 sb.add(": osError");
390 } 384 }
391 return sb.toString(); 385 return sb.toString();
392 } 386 }
393 final String message; 387 final String message;
394 final OSError osError; 388 final OSError osError;
395 } 389 }
OLDNEW
« no previous file with comments | « runtime/bin/directory.dart ('k') | runtime/bin/http.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698