BinaryStream
Module | ejs.io |
Namespace | "ejs.io" |
Definition | class BinaryStream |
Specified | Ejs-11. |
Inheritance | BinaryStream ![]() |
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
Qualifiers | Property | Type | Description |
---|---|---|---|
public static const | BigEndian | Number | Big endian byte order. |
public static const | LittleEndian | Number | Little endian byte order. |
BinaryStream Methods
Qualifiers | Method |
---|---|
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
Return the number of bytes available to read.
- Returns
- A the number of available bytes.
Create a new BinaryStream.
- Parameters
stream: Stream Optional stream to stack upon.
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.
Determine if the system is using little endian byte ordering.
- Returns
- An endian encoding constant. Either LittleEndian or BigEndian.
Set the system encoding to little or big endian.
- Parameters
value: Number Set to true for little endian encoding or false for big endian.
Flush the stream and all stacked streams and underlying data source/sinks.
Read a boolean from the stream.
- Returns
- A boolean. Returns null on eof.
Throws
IOError: if an I/O error occurs.
Read a byte from the stream.
- Returns
- A byte. Returns -1 on eof.
Throws
IOError: if an I/O error occurs.
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.
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.
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.
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.
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.
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.
Write a byte to the array.
- Description
- Data is written to the current write $position pointer.
- Parameters
data: Number Data to write
Write a double to the array.
- Description
- Data is written to the current write $position pointer.
- Parameters
data: Number Data to write
Write a 32-bit integer to the array.
- Description
- Data is written to the current write $position pointer.
- Parameters
data: Number Data to write
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
Write a short to the array.
- Description
- Data is written to the current write $position pointer.
- Parameters
data: Number Data to write