Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 * An input stream is used to read data sequentially from a data source. |
| 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 | |
| 9 * on a given input. | |
| 10 */ | 7 */ |
| 11 interface InputStream { | 8 interface InputStream { |
| 12 /** | 9 /** |
| 13 * Reads data from the stream. Returns a system allocated buffer | 10 * Reads data from the stream. If no encoding is set fir the stream |
|
Mads Ager (google)
2011/11/30 10:44:07
fir -> for
| |
| 14 * with up to [len] bytes. If no value is passed for [len] all | 11 * it returns a system allocated buffer with up to [len] bytes. If |
| 15 * available data will be returned. If no data is available null will | 12 * encoding is set it returns a [String] with up to [len] |
| 16 * be returned. | 13 * characters. If no value is passed for [len] all available data |
| 14 * will be returned. If no data is available null will be returned. | |
| 17 */ | 15 */ |
| 18 List<int> read([int len]); | 16 Object read([int len]); |
| 17 | |
| 18 /** | |
| 19 * Reads a line of characters from the stream. If a full line is not | |
| 20 * available the return value is null. If no encoding is set for the | |
| 21 * stream an exception is thrown. | |
| 22 */ | |
| 23 String readLine(); | |
| 19 | 24 |
| 20 /** | 25 /** |
| 21 * Reads up to [len] bytes into buffer [buffer] starting at offset | 26 * Reads up to [len] bytes into buffer [buffer] starting at offset |
| 22 * [offset]. Returns the number of bytes actually read which might | 27 * [offset]. Returns the number of bytes actually read which might |
| 23 * be zero. If [offset] is not specified 0 is used. If [len] is not | 28 * be zero. If [offset] is not specified 0 is used. If [len] is not |
| 24 * specified the length of [buffer] is used. | 29 * specified the length of [buffer] is used. If an encoding is set |
| 30 * for the stream an exception is thrown. | |
| 25 */ | 31 */ |
| 26 int readInto(List<int> buffer, [int offset, int len]); | 32 int readInto(List<int> buffer, [int offset, int len]); |
| 27 | 33 |
| 28 /** | 34 /** |
| 35 * Reads data from the stream until the pattern [pattern] is | |
| 36 * encountered. | |
| 37 */ | |
| 38 Object readUntil(Object pattern); | |
|
Mads Ager (google)
2011/11/30 10:44:07
Should pattern have type Pattern?
| |
| 39 | |
| 40 /** | |
| 41 * Pipe the data from this input stream directly to the | |
| 42 * [destination] [OutputStream]. After the input stream has been | |
| 43 * connected to an output stream data cannot be read from it | |
| 44 * anymore. When there is no more data in the input stream [close] | |
| 45 * will be called on the connected output stream. | |
| 46 */ | |
| 47 void pipe(OutputStream destination); | |
| 48 | |
| 49 /** | |
| 29 * Returns the number of bytes available for immediate reading. | 50 * Returns the number of bytes available for immediate reading. |
|
Mads Ager (google)
2011/11/30 10:44:07
Hmm, bytes or characters depending on the encoding
| |
| 30 */ | 51 */ |
| 31 int available(); | 52 int available(); |
| 32 | 53 |
| 33 /** | 54 /** |
| 55 * Sets the encoding used by the stream for turning bytes into | |
| 56 * characters. If encoding is set then calling the [read] method | |
| 57 * will return a [String] instead of a [List] of bytes. Currently | |
| 58 * the encodings "UTF-8", "ISO-8859-1" and "ASCII" are supported. | |
|
Mads Ager (google)
2011/11/30 10:44:07
Maybe there should always be an encoding? A defaul
| |
| 59 */ | |
| 60 void set encoding(String encoding); | |
| 61 String get encoding(); | |
| 62 | |
| 63 /** | |
| 64 * Sets the minimum number of bytes required to trigger a the | |
|
Mads Ager (google)
2011/11/30 10:44:07
Again, is this bytes or characters depending on th
| |
| 65 * [dataHandler] ... | |
| 66 */ | |
| 67 void set chunkSize(int chunkSize); | |
| 68 int get chunkSize(); | |
| 69 | |
| 70 /** | |
| 71 * Sets the data pattern to expect before triggering the | |
| 72 * [dataHandler] ... | |
| 73 */ | |
| 74 void set dataPattern(Object pattern); | |
| 75 get dataPattern(); | |
| 76 | |
| 77 /** | |
| 34 * Returns whether the stream is closed. There will be no more data | 78 * Returns whether the stream is closed. There will be no more data |
| 35 * to read. | 79 * to read. |
| 36 */ | 80 */ |
| 37 bool get closed(); | 81 bool get closed(); |
| 38 | 82 |
| 39 /** | 83 /** |
| 40 * Sets the handler that gets called when data is available. | 84 * Sets the handler that gets called when data is available. |
| 41 */ | 85 */ |
| 42 void set dataHandler(void callback()); | 86 void set dataHandler(void callback()); |
| 43 | |
| 44 /** | |
| 45 * Sets the handler that gets called when there will be no more data | |
| 46 * available in the stream. | |
| 47 */ | |
| 48 void set closeHandler(void callback()); | |
| 49 | |
| 50 /** | |
| 51 * Sets the handler that gets called when the underlying | |
| 52 * communication channel gets into some kind of error situation. | |
| 53 */ | |
| 54 void set errorHandler(void callback()); | |
| 55 } | |
| 56 | |
| 57 | |
| 58 interface StringInputStream factory _StringInputStream { | |
| 59 /** | |
| 60 * Decodes a binary input stream into characters using the specified | |
| 61 * encoding. | |
| 62 */ | |
| 63 StringInputStream(InputStream input, [String encoding]); | |
| 64 | |
| 65 /** | |
| 66 * Reads as many characters as is available from the stream. If no data is | |
| 67 * available null will be returned. | |
| 68 */ | |
| 69 String read(); | |
| 70 | |
| 71 /** | |
| 72 * Reads the next line from the stream. The line ending characters | |
| 73 * will not be part og the returned string. If a full line is not | |
| 74 * available null will be returned. | |
| 75 */ | |
| 76 String readLine(); | |
| 77 | |
| 78 /** | |
| 79 * Returns whether the stream has been closed. There might still be | |
| 80 * more data to read. | |
| 81 */ | |
| 82 bool get closed(); | |
| 83 | |
| 84 /** | |
| 85 * Returns the encoding used to decode the binary data into characters. | |
| 86 */ | |
| 87 String get encoding(); | |
| 88 | |
| 89 /** | |
| 90 * Sets the handler that gets called when data is available. | |
| 91 */ | |
| 92 void set dataHandler(void callback()); | |
| 93 | 87 |
| 94 /** | 88 /** |
| 95 * Sets the handler that gets called when there will be no more data | 89 * Sets the handler that gets called when there will be no more data |
| 96 * available in the stream. | 90 * available in the stream. |
| 97 */ | 91 */ |
| 98 void set closeHandler(void callback()); | 92 void set closeHandler(void callback()); |
| 99 | 93 |
| 100 /** | 94 /** |
| 101 * Sets the handler that gets called when the underlying | 95 * Sets the handler that gets called when the underlying |
| 102 * communication channel gets into some kind of error situation. | 96 * communication channel gets into some kind of error situation. |
| 103 */ | 97 */ |
| 104 void set errorHandler(void callback()); | 98 void set errorHandler(void callback()); |
| 105 } | 99 } |
| 106 | 100 |
| 107 | 101 |
| 108 class StreamException implements Exception { | 102 class StreamException implements Exception { |
| 109 const StreamException([String this.message = ""]); | 103 const StreamException([String this.message = ""]); |
| 110 String toString() => "StreamException: $message"; | 104 String toString() => "StreamException: $message"; |
| 111 final String message; | 105 final String message; |
| 112 } | 106 } |
| OLD | NEW |