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

Side by Side Diff: sdk/lib/io/input_stream.dart

Issue 12316036: Merge IO v2 branch to bleeding edge (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to r18818 Created 7 years, 10 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 | « sdk/lib/io/http_session.dart ('k') | sdk/lib/io/io.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 part of dart.io; 5 part of dart.io;
6 6
7 /** 7 /**
8 * Basic input stream which supplies binary data. 8 * Basic input stream which supplies binary data.
9 * 9 *
10 * Input streams are used to read data sequentially from some data 10 * Input streams are used to read data sequentially from some data
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 /** 108 /**
109 * SYSTEM encoding is the current code page on Windows and UTF-8 on 109 * SYSTEM encoding is the current code page on Windows and UTF-8 on
110 * Linux and Mac. 110 * Linux and Mac.
111 */ 111 */
112 static const Encoding SYSTEM = const Encoding._internal("SYSTEM"); 112 static const Encoding SYSTEM = const Encoding._internal("SYSTEM");
113 const Encoding._internal(String this.name); 113 const Encoding._internal(String this.name);
114 final String name; 114 final String name;
115 } 115 }
116 116
117 117
118 /**
119 * A string input stream wraps a basic input stream and supplies
120 * string data. This data can be read either as string chunks or as
121 * lines separated by line termination character sequences.
122 */
123 abstract class StringInputStream {
124 /**
125 * Decodes a binary input stream into characters using the specified
126 * encoding.
127 */
128 factory StringInputStream(InputStream input,
129 [Encoding encoding = Encoding.UTF_8]) {
130 return new _StringInputStream(input, encoding);
131 }
132
133 /**
134 * Reads up to [len] characters from the stream. if [len] is not
135 * specified reads as many characters as is available from the
136 * stream. If no data is available null will be returned.
137 */
138 String read([int len]);
139
140 /**
141 * Reads the next line from the stream. The line ending characters
142 * will not be part of the returned string. If a full line is not
143 * available null will be returned.
144 */
145 String readLine();
146
147 /**
148 * Returns the number of characters available for immediate
149 * reading. Note that this includes all characters that will be in
150 * the String returned from [read] this includes line breaking
151 * characters. If [readLine] is used for reading one can observe
152 * less characters being returned as the line breaking characters
153 * are discarded.
154 */
155 int available();
156
157 /**
158 * Returns whether the stream has been closed. There might still be
159 * more data to read.
160 */
161 bool get closed;
162
163 /**
164 * Returns the encoding used to decode the binary data into characters.
165 */
166 Encoding get encoding;
167
168 /**
169 * Sets the handler that gets called when data is available. The two
170 * handlers [onData] and [onLine] are mutually exclusive
171 * and setting one will remove the other.
172 */
173 void set onData(void callback());
174
175 /**
176 * Sets the handler that gets called when a line is available. The
177 * two handlers [onData] and [onLine] are mutually
178 * exclusive and setting one will remove the other.
179 */
180 void set onLine(void callback());
181
182 /**
183 * Sets the handler that gets called when there will be no more data
184 * available in the stream.
185 */
186 void set onClosed(void callback());
187
188 /**
189 * Sets the handler that gets called when the underlying
190 * communication channel gets into some kind of error situation.
191 */
192 void set onError(void callback(e));
193 }
194
195
196 /**
197 * A chunked input stream wraps a basic input stream and supplies
198 * binary data in configurable chunk sizes.
199 */
200 abstract class ChunkedInputStream {
201 /**
202 * Adds buffering to an input stream and provide the ability to read
203 * the data in known size chunks.
204 */
205 factory ChunkedInputStream(InputStream input, [int chunkSize = 0]) {
206 return new _ChunkedInputStream(input, chunkSize);
207 }
208
209 /**
210 * Reads [chunkSize] bytes from the stream. If [chunkSize] bytes are
211 * not currently available null is returned. When the stream is
212 * closed the last call can return with less than [chunkSize] bytes.
213 */
214 List<int> read();
215
216 /**
217 * Returns whether the stream has been closed. There might still be
218 * more data to read.
219 */
220 bool get closed;
221
222 /**
223 * Returns the chunk size used by this stream.
224 */
225 int get chunkSize;
226
227 /**
228 * Sets the chunk size used by this stream.
229 */
230 void set chunkSize(int chunkSize);
231
232 /**
233 * Sets the handler that gets called when at least [chunkSize] bytes
234 * of data is available or the underlying stream has been closed and
235 * there is still unread data.
236 */
237 void set onData(void callback());
238
239 /**
240 * Sets the handler that gets called when there will be no more data
241 * available in the stream.
242 */
243 void set onClosed(void callback());
244
245 /**
246 * Sets the handler that gets called when the underlying
247 * communication channel gets into some kind of error situation.
248 */
249 void set onError(void callback(e));
250 }
251
252
253 class StreamException implements Exception { 118 class StreamException implements Exception {
254 const StreamException([String this.message = ""]); 119 const StreamException([String this.message = ""]);
255 const StreamException.streamClosed() : message = "Stream closed"; 120 const StreamException.streamClosed() : message = "Stream closed";
256 String toString() => "StreamException: $message"; 121 String toString() => "StreamException: $message";
257 final String message; 122 final String message;
258 } 123 }
OLDNEW
« no previous file with comments | « sdk/lib/io/http_session.dart ('k') | sdk/lib/io/io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698