The ByteArray object provides methods and properties to optimize reading, writing, and working with binary data.

Note: The ByteArray object is for advanced developers who need to access data on the byte level.


In-memory data is a packed array (the most compact representation for the data type) of bytes. It also can be read and written to as an in-memory file.


Inherited from Bytes.


Can be created with method new:

Lib.Media.Utils.ByteArray.new(size)

Creates a ByteArray instance representing a packed array of bytes, so that you can use the methods and properties in this object to optimize your data storage and stream.

size - ByteArray size


Also can be created from static method fromBytes:

fromBytes(bytes)

Creates a ByteArray instance from library system Bytes object.

bytes - Bytes object.


Created ByteArray object has properties:

bytesAvailable

[read-only] The number of bytes of data available for reading from the current position in the byte array to the end of the array.

endian

Changes or reads the byte order for the data; either Endian.BIG_ENDIAN or Endian.LITTLE_ENDIAN.

length

The length of the ByteArray object, in bytes.

position

Moves, or returns the current position, in bytes, of the file pointer into the ByteArray object.


methods:

clear()

Clears the contents of the byte array and resets the length and position properties to 0.


compress(algorithm)

Compresses the byte array.

algorithm - (default = nil) - The compression algorithm to use when compressing. Valid values are defined as constants in the CompressionAlgorithm object. The default is to use zlib format. Calling compress(CompressionAlgorithm.DEFLATE) has the same effect as calling the deflate() method. 

deflate()

Compresses the byte array using the deflate compression algorithm.


inflate()

Decompresses the byte array using the deflate compression algorithm.


readBoolean()

Reads a Boolean value from the byte stream.


readByte()

Reads a signed byte from the byte stream.


readBytes(bytes, offset, length)

Reads the number of data bytes, specified by the length parameter, from the byte stream.

bytes - The ByteArray object to read data into.

offset - (default = 0) - The offset (position) in bytes at which the read data should be written.

length - (default = 0) - The number of bytes to read. The default value of 0 causes all available data to be read.

readDouble()

Reads an IEEE 754 double-precision (64-bit) floating-point number from the byte stream.


readFloat()

Reads an IEEE 754 single-precision (32-bit) floating-point number from the byte stream.


readInt()

Reads a signed 32-bit integer from the byte stream.


readMultiByte(length, charSet)

Reads a multibyte string of specified length from the byte stream using the specified character set.

length - The number of bytes from the byte stream to read.

charSet - The string denoting the character set to use to interpret the bytes. Possible character set strings include "shift-jis", "cn-gb", "iso-8859-1", and others. For a complete list, see Supported Character Sets. (not implemented)

readShort()

Reads a signed 16-bit integer from the byte stream.


readUnsignedByte()

Reads an unsigned byte from the byte stream.


readUnsignedInt()

Reads an unsigned 32-bit integer from the byte stream.


readUnsignedShort()

Reads an unsigned 16-bit integer from the byte stream.


readUTF()

Reads a UTF-8 string from the byte stream.


readUTFBytes(length)

Reads a sequence of UTF-8 bytes specified by the length parameter from the byte stream and returns a string.

length - An unsigned short indicating the length of the UTF-8 bytes.

toString()

Converts the byte array to a string.


uncompress(algorithm)

Decompresses the byte array.

algorithm - (default = nil) - The compression algorithm to use when decompressing. This must be the same compression algorithm used to compress the data. Valid values are defined as constants in the CompressionAlgorithm object. The default is to use zlib format.

writeBoolean(value)

Writes a Boolean value.

value - A Boolean value determining which byte is written. If the parameter is true, the method writes a 1; if false, the method writes a 0.

writeByte(value)

Writes a byte to the byte stream.

value - A 32-bit integer. The low 8 bits are written to the byte stream.

writeBytes(bytes, offset, length)

Writes a sequence of length bytes from the specified byte array, bytes, starting offset(zero-based index) bytes into the byte stream.

bytes - The ByteArray object.

offset - (default = 0) - A zero-based index indicating the position into the array to begin writing.

length - (default = 0) - An unsigned integer indicating how far into the buffer to write.

writeDouble(value)

Writes an IEEE 754 double-precision (64-bit) floating-point number to the byte stream.

value - A double-precision (64-bit) floating-point number.

writeFloat(value)

Writes an IEEE 754 single-precision (32-bit) floating-point number to the byte stream.

value - A single-precision (32-bit) floating-point number.

writeInt(value)

Writes a 32-bit signed integer to the byte stream.

value - An integer to write to the byte stream.

writeMultiByte(value, charSet)

Writes a multibyte string to the byte stream using the specified character set.

(not supported)


writeShort(value)

Writes a 16-bit integer to the byte stream.

value - 32-bit integer, whose low 16 bits are written to the byte stream.

writeUnsignedInt(value)

Writes a 32-bit unsigned integer to the byte stream.

value - An unsigned integer to write to the byte stream.

writeUTF(value)

Writes a UTF-8 string to the byte stream.

value - The string value to be written.

writeUTFBytes(value)

Writes a UTF-8 string to the byte stream.

value - The string value to be written.

asString()

The same as readUTFBytes()



Created with the Personal Edition of HelpNDoc: Free EBook and documentation generator