BinaryStream

Moduleejs.io
Definition class BinaryStream
InheritanceBinaryStream inherit Object
Specifiedejscript-1.1
StabilityEvolving.

BinaryStreams encode and decode various objects onto streams.

A BinaryStream may be stacked atop an underlying stream provider such as ByteArray, File or Http.


Properties

QualifiersPropertyTypeDescription
public static const BigEndianNumberBig endian byte order.
public static const LittleEndianNumberLittle endian byte order.
public get availableNumberThe number of bytes available to read.
public get setendianNumberCurrent byte ordering. Set to either LittleEndian or BigEndian.

BinaryStream Methods

QualifiersMethod
BinaryStream(stream: Stream)
 Create a new BinaryStream.
public close(graceful: Boolean = true): Void
 Close the input stream and free up all associated resources.
public flush(graceful: Boolean = true): Void
 Flush the stream and all stacked streams and underlying data source/sinks.
public read(buffer: ByteArray, offset: Number = 0 , count: Number = -1): 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 readDate(): Date
 Read a date from the stream.
public readDouble()
 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.The data will be decoded according to the encoding property.
public readString(count: Number = -1): String
 Read a UTF-8 string from the stream.
public readXML(): XML
 Read an XML document from the stream.
public write(data: 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 BinaryStream(stream: Stream)

Create a new BinaryStream.

Parameters
stream: Stream Stream to stack upon.

public close(graceful: Boolean = true): 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: true]

public flush(graceful: Boolean = true): Void

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

Parameters
graceful: Boolean If true, then write all pending data. [default: true]

public read(buffer: ByteArray, offset: Number = 0 , count: Number = -1): 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. If the offset is -1, then data is appended to the buffer write position which is then updated. [default: 0 ]
count: Number Number of bytes to read. If -1, read as much as the buffer will hold up. [default: -1]
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 readDate(): Date

Read a date from the stream.

Returns
A date.
Throws
IOError: if an I/O error occurs.

public readDouble()

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.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 = -1): 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. [default: -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 write(data: Array): Number

Write data to the stream.

Description
Write intelligently encodes various.
Parameters
data: Array Data to write. The ByteStream class intelligently encodes various data types according to the current setting of the Local variables: tab-width: 4 c-basic-offset: 4 End: vim: sw=4 ts=4 expandtab.
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.