Stream

Moduleejs
Namespaceintrinsic
Definition class Stream
SpecifiedEjs-11.
InheritanceStream

Stream objects represent bi-directional streams of data that pass data elements between an endpoint known as a source or sink and a consumer / producer.

In between, intermediate streams may be used as filters. Example endpoints are the File, Socket, String and Http classes. The TextStream is an example of a filter stream. The data elements passed by streams may be any series of objects including: bytes, lines of text, integers or objects. Streams may buffer the incoming data or not. Streams may offer sync and/or async modes of operation.


Properties

QualifiersPropertyTypeDescription
No properties defined

Stream Methods

QualifiersMethod
public available(): Number
 Return the number of bytes available to read.
public close(graceful: Boolean): Void
 Close the input stream and free up all associated resources.
public flush(): Void
 Flush the stream and all stacked streams and underlying data source/sinks.
public read(buffer: ByteArray, offset: Number, count: Number): Number
 Read a block of data from the stream.
public skip(n: Number): Void
public write(data: Array): Number
 Write data to the stream.

Method Detail

public available(): Number

Return the number of bytes available to read.

Returns
A the number of available bytes.

public close(graceful: Boolean): Void

Close the input stream and free up all associated resources.

Parameters
graceful: Boolean if true, then close the socket gracefully after writing all pending data. [default: false]

public flush(): Void

Flush the stream and all stacked streams and underlying data source/sinks.


public read(buffer: ByteArray, offset: Number, count: Number): Number

Read a block of data from the stream.

Description
Read the required number of bytes from the stream into the supplied byte array at the given offset.
Parameters
count: Number Number of elements to read.
Returns
A count of the bytes actually read.

Throws

IOError: if an I/O error occurs.


public skip(n: Number): Void

public write(data: Array): Number

Write data to the stream.

Description
If in sync mode, the write call blocks until the underlying stream or endpoint absorbes all the data. If in async-mode, the call accepts whatever data can be accepted immediately and returns a count of the elements that have been written.
Parameters
data: Array Data to write.
Returns
The total number of elements that were written.

Throws

IOError: if there is an I/O error.