BinaryStream

Moduleejs.io
Namespace"ejs.io"
Definition class BinaryStream
SpecifiedEjs-11.
InheritanceBinaryStream inherit Object

BinaryStreams encode and decode various objects onto streams.

A BinaryStream may be stacked atop an underlying stream provider such as File, Http or Socket. The underlying stream must be in sync mode.


Properties

QualifiersPropertyTypeDescription
public static const BigEndianNumberBig endian byte order.
public static const LittleEndianNumberLittle endian byte order.

BinaryStream Methods

QualifiersMethod
public available(): Number
 Return the number of bytes available to read.
BinaryStream(stream: Stream)
 Create a new BinaryStream.
public close(graceful: Boolean): Void
 Close the input stream and free up all associated resources.
public get endian(): Number
 Determine if the system is using little endian byte ordering.
public set endian(value: Number): Void
 Set the system encoding to little or big endian.
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 data from the stream.
public readBoolean(): Boolean
 Read a boolean from the stream.
public readByte(): Number
 Read a byte from the stream.
public readByteArray(count: Number): ByteArray
 Read data from the stream into a byte array.
public readDate(): Date
 Read a date from the stream.
public readDouble(): Date
 Read a double from the stream.
public readInteger(): Number
 Read a 32-bit integer from the stream.
public readLong(): Number
 Read a 64-bit long from the stream.
public readString(count: Number): String
 Read a UTF-8 string from the stream.
public readXML(): XML
 Read an XML document from the stream.
public skip(n: Number): Void
public write(items: Array): Number
 Write data to the stream.
public writeByte(data: Number): Void
 Write a byte to the array.
public writeDouble(data: Number): Void
 Write a double to the array.
public writeInteger(data: Number): Void
 Write a 32-bit integer to the array.
public writeLong(data: Number): Void
 Write a 64 bit long integer to the array.
public writeShort(data: Number): Void
 Write a short to the array.

Method Detail

public available(): Number

Return the number of bytes available to read.

Returns
A the number of available bytes.

BinaryStream(stream: Stream)

Create a new BinaryStream.

Parameters
stream: Stream Optional stream to stack upon.

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.

get public endian(): Number

Determine if the system is using little endian byte ordering.

Returns
An endian encoding constant. Either LittleEndian or BigEndian.

set public endian(value: Number): Void

Set the system encoding to little or big endian.

Parameters
value: Number Set to true for little endian encoding or false for big endian.

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 data from the stream.

Parameters
buffer: ByteArray Destination byte array for the read data.
offset: Number Offset in the byte array to place the data.
count: Number Number of bytes to read.
Returns
A count of the bytes actually read. Returns zero on eof.

Throws

IOError: if an I/O error occurs.


public readBoolean(): Boolean

Read a boolean from the stream.

Returns
A boolean. Returns null on eof.

Throws

IOError: if an I/O error occurs.


public readByte(): Number

Read a byte from the stream.

Returns
A byte. Returns -1 on eof.

Throws

IOError: if an I/O error occurs.


public readByteArray(count: Number): ByteArray

Read data from the stream into a byte array.

Returns
A new byte array with the available data. Returns an empty byte array on eof.

Throws

IOError: if an I/O error occurs.


public readDate(): Date

Read a date from the stream.

Returns
A date.

Throws

IOError: if an I/O error occurs.


public readDouble(): Date

Read a double from the stream.

Description
The data will be decoded according to the encoding property.
Returns
A double.

Throws

IOError: if an I/O error occurs.


public readInteger(): Number

Read a 32-bit integer from the stream.

Description
The data will be decoded according to the encoding property.
Returns
An 32-bitinteger.

Throws

IOError: if an I/O error occurs.


public readLong(): Number

Read a 64-bit long from the stream.

Description
The data will be decoded according to the encoding property.
Returns
A 64-bit long number.

Throws

IOError: if an I/O error occurs.


public readString(count: Number): String

Read a UTF-8 string from the stream.

Parameters
count: Number of bytes to read. Returns the entire stream contents if count is -1.
Returns
A string.

Throws

IOError: if an I/O error occurs.


public readXML(): XML

Read an XML document from the stream.

Description
This assumes the XML document will be the only data until EOF.
Returns
An XML document.

Throws

IOError: if an I/O error occurs.


public skip(n: Number): Void

public write(items: Array): Number

Write data to the stream.

Description
Write intelligently encodes various.
Parameters
Returns
The total number of elements that were written.

Throws

IOError: if there is an I/O error.


public writeByte(data: Number): Void

Write a byte to the array.

Description
Data is written to the current write $position pointer.
Parameters
data: Number Data to write

public writeDouble(data: Number): Void

Write a double to the array.

Description
Data is written to the current write $position pointer.
Parameters
data: Number Data to write

public writeInteger(data: Number): Void

Write a 32-bit integer to the array.

Description
Data is written to the current write $position pointer.
Parameters
data: Number Data to write

public writeLong(data: Number): Void

Write a 64 bit long integer to the array.

Description
Data is written to the current write $position pointer.
Parameters
data: Number Data to write

public writeShort(data: Number): Void

Write a short to the array.

Description
Data is written to the current write $position pointer.
Parameters
data: Number Data to write