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

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

Issue 8318009: Update the streams interfaces (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from ager@ Created 9 years, 1 month 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/file_impl.dart ('k') | runtime/bin/process_impl.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 * Input is read from a given input stream. Such an input stream can 6 * Input is read from a given input stream. Such an input stream can
7 * be an endpoint, e.g., a socket or a file, or another input stream. 7 * be an endpoint, e.g., a socket or a file, or another input stream.
8 * Multiple input streams can be chained together to operate collaboratively 8 * Multiple input streams can be chained together to operate collaboratively
9 * on a given input. 9 * on a given input.
10 */ 10 */
11 interface InputStream { 11 interface InputStream {
12 /** 12 /**
13 * Reads [len] bytes into [buffer] buffer starting at [offset] offset. 13 * Reads data from the stream. Returns a system allocated buffer
14 * [callback] callback is invoked on completion unless it is null. 14 * with up to [len] bytes. If no value is passed for [len] all
15 * available data will be returned. If no data is available null will
16 * be returned.
15 */ 17 */
16 bool read(List<int> buffer, int offset, int len, void callback()); 18 List<int> read([int len]);
17 19
18 /** 20 /**
19 * Reads data from the stream into a buffer until a given [pattern] occurs and 21 * Reads up to [len] bytes into buffer [buffer] starting at offset
20 * hands that buffer over as an input to the registered [callback]. 22 * [offset]. Returns the number of bytes actually read which might
21 * The callback is not invoked if a read error occurs. 23 * be zero. If [offset] is not specified 0 is used. If [len] is not
24 * specified the length of [buffer] is used.
22 */ 25 */
23 void readUntil(List<int> pattern, void callback(List<int> buffer)); 26 int readInto(List<int> buffer, [int offset, int len]);
27
28 /**
29 * Returns the number of bytes available for immediate reading.
30 */
31 int available();
32
33 /**
34 * Returns whether the stream has been closed. There might still be
35 * more data to read.
36 */
37 bool closed();
38
39 /**
40 * Sets the data which handler gets called when data is available.
41 */
42 void set dataHandler(void callback());
43
44 /**
45 * The close handler gets called when the underlying communication
46 * channel is closed and no more data will become available. Not all
47 * types of communication channels will emit close events.
48 */
49 void set closeHandler(void callback());
50
51 /**
52 * The error handler gets called when the underlying communication
53 * channel gets into some kind of error situation.
54 */
55 void set errorHandler(void callback());
24 } 56 }
57
58
59 interface StringInputStream factory _StringInputStream {
60 /**
61 * Decodes a binary input stream into characters using the specified
62 * encoding.
63 */
64 StringInputStream(InputStream input, [String encoding]);
65
66 /**
67 * Reads as many characters as is available from the stream. If no data is
68 * available null will be returned.
69 */
70 String read();
71
72 /**
73 * Reads the next line from the stream. The line ending characters
74 * will not be part og the returned string. If a full line is not
75 * available null will be returned.
76 */
77 String readLine();
78
79 /**
80 * Returns whether the stream has been closed. There might still be
81 * more data to read.
82 */
83 bool get closed();
84
85 /**
86 * Returns the encoding used to decode the binary data into characters.
87 */
88 String get encoding();
89
90 /**
91 * The data handler gets called when data is available.
92 */
93 void set dataHandler(void callback());
94
95 /**
96 * The close handler gets called when the underlying communication
97 * channel is closed and no more data will become available. Not all
98 * types of communication channels will emit close events.
99 */
100 void set closeHandler(void callback());
101
102 /**
103 * The error handler gets called when the underlying communication
104 * channel gets into some kind of error situation.
105 */
106 void set errorHandler(void callback());
107 }
108
109
110 class StreamException implements Exception {
111 const StreamException([String this.message = ""]);
112 String toString() => "StreamException: $message";
113 final String message;
114 }
OLDNEW
« no previous file with comments | « runtime/bin/file_impl.dart ('k') | runtime/bin/process_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698