Dart API Referencedart:ioInputStream

InputStream Interface

Basic input stream which supplies binary data.

Input streams are used to read data sequentially from some data source. All input streams are non-blocking. They each have a number of read calls which will always return without any IO related blocking. If the requested data is not available a read call will return null. All input streams have one or more handlers which will trigger when data is available.

The following example shows a data handler in an ordinary input stream which will be called when some data is available and a call to read will not return null.

[: InputStream input = ... input.onData = () {

 var data = input.read();
 ...

}; :]

If for some reason the data from an input stream cannot be handled by the application immediately setting the data handler to null will avoid further callbacks until it is set to a function again. While the data handler is not active system flow control will be used to avoid buffering more data than needed.

Always set up appropriate handlers when using input streams.

Subinterfaces

ListInputStream, SocketInputStream

Methods

Code int available() #

Returns the number of bytes available for immediate reading.

int available();

Code void close() #

Close the underlying communication channel to avoid getting any more data. In normal situations, where all data is read from the stream until the close handler is called, calling close is not required. When close is used the close handler will still be called.

void close();

Code bool get closed() #

Returns whether the stream is closed. There will be no more data to read.

bool get closed();

Code void set onClosed(void callback()) #

Sets the handler that gets called when there will be no more data available in the stream.

void set onClosed(void callback());

Code void set onData(void callback()) #

Sets the handler that gets called when data is available.

void set onData(void callback());

Code void set onError(void callback(e)) #

Sets the handler that gets called when the underlying communication channel gets into some kind of error situation.

void set onError(void callback(e));

Code void pipe(OutputStream output, [bool close]) #

Pipe the content of this input stream directly to the output stream output. The default behavior is to close the output when all the data from the input stream have been written. Specifying false for the optional argument close keeps the output stream open after writing all data from the input stream. The default value for close is true.

void pipe(OutputStream output, [bool close]);

Code List<int> read([int len]) #

Reads data from the stream. Returns a system allocated buffer with up to len bytes. If no value is passed for len all available data will be returned. If no data is available null will be returned.

List<int> read([int len]);

Code int readInto(List<int> buffer, [int offset, int len]) #

Reads up to len bytes into buffer buffer starting at offset offset. Returns the number of bytes actually read which might be zero. If offset is not specified 0 is used. If len is not specified the length of buffer is used.

int readInto(List<int> buffer, [int offset, int len]);