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

Side by Side Diff: runtime/bin/input_stream.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/http_impl.dart ('k') | runtime/bin/list_stream.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 * Basic input stream which supplies binary data. 6 * Basic input stream which supplies binary data.
7 * 7 *
8 * Input streams are used to read data sequentially from some data 8 * Input streams are used to read data sequentially from some data
9 * source. All input streams are non-blocking. They each have a number 9 * source. All input streams are non-blocking. They each have a number
10 * of read calls which will always return without any IO related 10 * of read calls which will always return without any IO related
(...skipping 13 matching lines...) Expand all
24 * 24 *
25 * If for some reason the data from an input stream cannot be handled 25 * If for some reason the data from an input stream cannot be handled
26 * by the application immediately setting the data handler to `null` 26 * by the application immediately setting the data handler to `null`
27 * will avoid further callbacks until it is set to a function 27 * will avoid further callbacks until it is set to a function
28 * again. While the data handler is not active system flow control 28 * again. While the data handler is not active system flow control
29 * will be used to avoid buffering more data than needed. 29 * will be used to avoid buffering more data than needed.
30 * 30 *
31 * Always set up appropriate handlers when using input streams. 31 * Always set up appropriate handlers when using input streams.
32 * 32 *
33 */ 33 */
34 interface InputStream { 34 abstract class InputStream {
35 /** 35 /**
36 * Reads data from the stream. Returns a system allocated buffer 36 * Reads data from the stream. Returns a system allocated buffer
37 * with up to [len] bytes. If no value is passed for [len] all 37 * with up to [len] bytes. If no value is passed for [len] all
38 * available data will be returned. If no data is available null will 38 * available data will be returned. If no data is available null will
39 * be returned. 39 * be returned.
40 */ 40 */
41 List<int> read([int len]); 41 List<int> read([int len]);
42 42
43 /** 43 /**
44 * Reads up to [len] bytes into buffer [buffer] starting at offset 44 * Reads up to [len] bytes into buffer [buffer] starting at offset
45 * [offset]. Returns the number of bytes actually read which might 45 * [offset]. Returns the number of bytes actually read which might
46 * be zero. If [offset] is not specified 0 is used. If [len] is not 46 * be zero. If [offset] is not specified 0 is used. If [len] is not
47 * specified the length of [buffer] is used. 47 * specified the length of [buffer] is used.
48 */ 48 */
49 int readInto(List<int> buffer, [int offset, int len]); 49 int readInto(List<int> buffer, [int offset, int len]);
50 50
51 /** 51 /**
52 * Returns the number of bytes available for immediate reading. 52 * Returns the number of bytes available for immediate reading.
53 */ 53 */
54 int available(); 54 int available();
55 55
56 /** 56 /**
57 * Pipe the content of this input stream directly to the output 57 * Pipe the content of this input stream directly to the output
58 * stream [output]. The default behavior is to close the output when 58 * stream [output]. The default behavior is to close the output when
59 * all the data from the input stream have been written. Specifying 59 * all the data from the input stream have been written. Specifying
60 * `false` for the optional argument [close] keeps the output 60 * `false` for the optional argument [close] keeps the output
61 * stream open after writing all data from the input stream. The 61 * stream open after writing all data from the input stream.
62 * default value for [close] is `true`.
63 */ 62 */
64 void pipe(OutputStream output, [bool close]); 63 void pipe(OutputStream output, [bool close = true]);
65 64
66 /** 65 /**
67 * Close the underlying communication channel to avoid getting any 66 * Close the underlying communication channel to avoid getting any
68 * more data. In normal situations, where all data is read from the 67 * more data. In normal situations, where all data is read from the
69 * stream until the close handler is called, calling [close] is not 68 * stream until the close handler is called, calling [close] is not
70 * required. When [close] is used the close handler will still be 69 * required. When [close] is used the close handler will still be
71 * called. 70 * called.
72 */ 71 */
73 void close(); 72 void close();
74 73
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 const Encoding._internal(String this.name); 106 const Encoding._internal(String this.name);
108 final String name; 107 final String name;
109 } 108 }
110 109
111 110
112 /** 111 /**
113 * A string input stream wraps a basic input stream and supplies 112 * A string input stream wraps a basic input stream and supplies
114 * string data. This data can be read either as string chunks or as 113 * string data. This data can be read either as string chunks or as
115 * lines separated by line termination character sequences. 114 * lines separated by line termination character sequences.
116 */ 115 */
117 interface StringInputStream default _StringInputStream { 116 abstract class StringInputStream {
118 /** 117 /**
119 * Decodes a binary input stream into characters using the specified 118 * Decodes a binary input stream into characters using the specified
120 * encoding. The default encoding is UTF-8 - `Encoding.UTF_8`. 119 * encoding.
121 */ 120 */
122 StringInputStream(InputStream input, [Encoding encoding]); 121 factory StringInputStream(InputStream input,
122 [Encoding encoding = Encoding.UTF_8]) {
123 return new _StringInputStream(input, encoding);
124 }
123 125
124 /** 126 /**
125 * Reads up to [len] characters from the stream. if [len] is not 127 * Reads up to [len] characters from the stream. if [len] is not
126 * specified reads as many characters as is available from the 128 * specified reads as many characters as is available from the
127 * stream. If no data is available null will be returned. 129 * stream. If no data is available null will be returned.
128 */ 130 */
129 String read([int len]); 131 String read([int len]);
130 132
131 /** 133 /**
132 * Reads the next line from the stream. The line ending characters 134 * Reads the next line from the stream. The line ending characters
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 * communication channel gets into some kind of error situation. 183 * communication channel gets into some kind of error situation.
182 */ 184 */
183 void set onError(void callback(e)); 185 void set onError(void callback(e));
184 } 186 }
185 187
186 188
187 /** 189 /**
188 * A chunked input stream wraps a basic input stream and supplies 190 * A chunked input stream wraps a basic input stream and supplies
189 * binary data in configurable chunk sizes. 191 * binary data in configurable chunk sizes.
190 */ 192 */
191 interface ChunkedInputStream default _ChunkedInputStream { 193 abstract class ChunkedInputStream {
192 /** 194 /**
193 * Adds buffering to an input stream and provide the ability to read 195 * Adds buffering to an input stream and provide the ability to read
194 * the data in known size chunks. 196 * the data in known size chunks.
195 */ 197 */
196 ChunkedInputStream(InputStream input, [int chunkSize]); 198 factory ChunkedInputStream(InputStream input, [int chunkSize = 0]) {
199 return new _ChunkedInputStream(input, chunkSize);
200 }
197 201
198 /** 202 /**
199 * Reads [chunkSize] bytes from the stream. If [chunkSize] bytes are 203 * Reads [chunkSize] bytes from the stream. If [chunkSize] bytes are
200 * not currently available null is returned. When the stream is 204 * not currently available null is returned. When the stream is
201 * closed the last call can return with less than [chunkSize] bytes. 205 * closed the last call can return with less than [chunkSize] bytes.
202 */ 206 */
203 List<int> read(); 207 List<int> read();
204 208
205 /** 209 /**
206 * Returns whether the stream has been closed. There might still be 210 * Returns whether the stream has been closed. There might still be
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 void set onError(void callback(e)); 242 void set onError(void callback(e));
239 } 243 }
240 244
241 245
242 class StreamException implements Exception { 246 class StreamException implements Exception {
243 const StreamException([String this.message = ""]); 247 const StreamException([String this.message = ""]);
244 const StreamException.streamClosed() : message = "Stream closed"; 248 const StreamException.streamClosed() : message = "Stream closed";
245 String toString() => "StreamException: $message"; 249 String toString() => "StreamException: $message";
246 final String message; 250 final String message;
247 } 251 }
OLDNEW
« no previous file with comments | « runtime/bin/http_impl.dart ('k') | runtime/bin/list_stream.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698