ByteArray

private class
system.ByteArray

Description

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

API overview

Constructor

ByteArray ()

Attributes

Public attributes

bytesAvailable: Number read-only

Get the number of bytes left until the end of the byte array

length: Number native

Return the length in bytes of this ByteArray

position: Number

Set the current position of the byte array

Functions

Public functions

clear (): Void native

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

compress (): Void native

Compress the ByteArray data with the zlib compression algorithm

readBoolean (): Boolean native

Reads a Boolean value from the byte stream

readByte (): Number native

Reads a signed byte from the byte stream

readBytes ( bytes: ByteArray , offset: Number = 0 , length: Number = 0 ): Number native

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

readDouble (): Number native

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

readFloat (): Number native

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

readInt (): Number native

Reads a signed 32-bit integer from the byte stream

readShort (): Number native

Reads a signed 16-bit integer from the byte stream

readString (): String native

Reads a UTF-8 string from the byte stream

readUTF (): String native

Reads a UTF-8 string from the byte stream

readUTFBytes ( length: Number ): String native

Reads a length amount of UTF-8 string bytes from the byte stream

readUnsignedByte (): Number native

Reads an unsigned byte from the byte stream

readUnsignedInt (): Number native

Reads an unsigned 32-bit integer from the byte stream

readUnsignedShort (): Number native

Reads an unsigned 16-bit integer from the byte stream

reserve ( bytes: Number ): Void native

Reserves the number of bytes specified

setPosition ( value: Number ): Void native

Moves the current position of the file pointer (in bytes) into the ByteArray object

uncompress ( uncompressedSize: Number = 0 , maxBuffer: Number = 262144 ): Void native

Uncompress zlib or gzip compressed data

writeBoolean ( value: Boolean ): Void native

Writes a Boolean value

writeByte ( value: Number ): Void native

Writes a byte to the byte stream

writeBytes ( bytes: ByteArray , offset: Number = 0 , length: Number = 0 ): Void native

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

writeDouble ( value: Number ): Void native

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

writeFloat ( value: Number ): Void native

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

writeInt ( value: Number ): Void native

Writes a 32-bit signed integer to the byte stream

writeShort ( value: Number ): Void native

Writes a 16-bit integer to the byte stream

writeString ( value: String ): Void native

Writes a UTF-8 string to the byte stream

writeUTF ( value: String ): Void native

Writes a UTF-8 string to the byte stream

writeUTFBytes ( value: String ): Void native

Writes a UTF-8 string to the byte stream

writeUnsignedByte ( value: Number ): Void native

Writes a byte to the byte stream

writeUnsignedInt ( value: Number ): Void native

Writes a 32-bit unsigned integer to the byte stream

writeUnsignedShort ( value: Number ): Void native

Writes a 16-bit integer to the byte stream

Constructor

ByteArray ()

Attributes

bytesAvailable: Number

read-only

Get the number of bytes left until the end of the byte array.

length: Number

native

Return the length in bytes of this ByteArray.

position: Number

Set the current position of the byte array.

Functions

clear (): Void

native

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



compress (): Void

native

Compress the ByteArray data with the zlib compression algorithm. The ByteArray gets resized to the compressed size of the data.



getFullTypeName (): String
Inherited from Object

native

Gets the fully qualified type name of the Object. The fully qualified type name includes the package of the type.


Returns

String fully qualified type name of the Object.

getType (): Type
Inherited from Object

native

Gets the Type that describes the Object.


Returns

Type The Type that describes the object.

getTypeName (): String
Inherited from Object

native

Gets the type name of the Object.


Returns

String type name of the Object.

readBoolean (): Boolean

native

Reads a Boolean value from the byte stream.

A single byte is read, returning true for non-zero values, false otherwise.


Returns

Boolean Returns true if the byte is nonzero, false otherwise.

readByte (): Number

native

Reads a signed byte from the byte stream.

The returned value is in the range -128 to 127.


Returns

Number An integer between -128 and 127.

readBytes ( bytes: ByteArray , offset: Number = 0 , length: Number = 0 ): Number

native

Reads the number of data bytes, specified by the length parameter, from the byte stream. The bytes are read into the ByteArray object specified by the bytes parameter, and the bytes are written into the destination ByteArray starting at the position specified by offset.

Parameters

bytes: ByteArray The ByteArray object to read data into.
offset: Number = 0 The offset (position) in bytes at which the read data should be written.
length: Number = 0 The number of bytes to read. The default value of 0 causes all available data to be read.


readDouble (): Number

native

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


Returns

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

readFloat (): Number

native

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


Returns

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

readInt (): Number

native

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

The returned value is in the range -2147483648 to 2147483647.


Returns

Number A 32-bit signed integer between -2147483648 and 2147483647.

readShort (): Number

native

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

The returned value is in the range -32768 to 32767.


Returns

Number A 16-bit signed integer between -32768 and 32767.

readString (): String

native

Reads a UTF-8 string from the byte stream. The string is assumed to be prefixed with an unsigned int indicating the length in bytes.


Returns

String UTF-8 encoded String.

readUTF (): String

native

Reads a UTF-8 string from the byte stream. The string is assumed to be prefixed with an unsigned short indicating the length in bytes.


Returns

String UTF-8 encoded String.

readUTFBytes ( length: Number ): String

native

Reads a length amount of UTF-8 string bytes from the byte stream.

Parameters

length: Number

Returns

String UTF-8 encoded String.

readUnsignedByte (): Number

native

Reads an unsigned byte from the byte stream.

The returned value is in the range 0 to 255.


Returns

Number A 32-bit unsigned integer between 0 and 255.

readUnsignedInt (): Number

native

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

The returned value is in the range 0 to 4294967295.


Returns

Number A 32-bit unsigned integer between 0 and 4294967295.

readUnsignedShort (): Number

native

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

The returned value is in the range 0 to 65535.


Returns

Number A 16-bit unsigned integer between 0 and 65535.

reserve ( bytes: Number ): Void

native

Reserves the number of bytes specified.

This does not set the ByteArray's size, it just reserves the desired capacity to avoid memory thrashing when writing to the ByteArray.

Parameters

bytes: Number


setPosition ( value: Number ): Void

native

Moves the current position of the file pointer (in bytes) into the ByteArray object.

This is the point at which the next call to a read method starts reading or a write method starts writing.

Parameters

value: Number


toString (): String
Inherited from Object

native

Returns a String that describes the Object. This can be overriden to provide extra details when printing objects using trace().


Returns

String String that described the Object.

uncompress ( uncompressedSize: Number = 0 , maxBuffer: Number = 262144 ): Void

native

Uncompress zlib or gzip compressed data. uncompressedSize is equivalent to initialSize due to legacy code. If not specified, initialSize will be used and ByteArray will be truncated to the actual size of the data. If the uncompressed data size doesn't fit in initialSize bytes, the buffer gets resized until it does.

Parameters

uncompressedSize: Number = 0
maxBuffer: Number = 262144


writeBoolean ( value: Boolean ): Void

native

Writes a Boolean value.

A single byte is written according to the value parameter, either 1 if true or 0 if false.

Parameters

value: Boolean 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: Number ): Void

native

Writes a byte to the byte stream.

The low 8 bits of the parameter are used. The high 24 bits are ignored.

Parameters

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


writeBytes ( bytes: ByteArray , offset: Number = 0 , length: Number = 0 ): Void

native

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

If the length parameter is omitted, the default length of 0 is used; the method writes the entire buffer starting at offset. If the offset parameter is also omitted, the entire buffer is written.

Parameters

bytes: ByteArray The ByteArray object.
offset: Number = 0 A zero-based index indicating the position into the array to begin writing.
length: Number = 0 An integer indicating how far into the buffer to write.


writeDouble ( value: Number ): Void

native

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

Parameters

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


writeFloat ( value: Number ): Void

native

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

Parameters

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


writeInt ( value: Number ): Void

native

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

Parameters

value: Number An integer to write to the byte stream.


writeShort ( value: Number ): Void

native

Writes a 16-bit integer to the byte stream.

Parameters

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


writeString ( value: String ): Void

native

Writes a UTF-8 string to the byte stream. The length of the UTF-8 string in bytes is written first, as a 32-bit integer, followed by the bytes representing the characters of the string

Parameters

value: String The string value to be written.


writeUTF ( value: String ): Void

native

Writes a UTF-8 string to the byte stream. The length of the UTF-8 string in bytes is written first, as a 16-bit integer, followed by the bytes representing the characters of the string

Parameters

value: String The string value to be written.


writeUTFBytes ( value: String ): Void

native

Writes a UTF-8 string to the byte stream. This function only writes the bytes representing the characters of the string.

Parameters

value: String The string value to be written.


writeUnsignedByte ( value: Number ): Void

native

Writes a byte to the byte stream.

Parameters

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


writeUnsignedInt ( value: Number ): Void

native

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

Parameters

value: Number An unsigned integer to write to the byte stream.


writeUnsignedShort ( value: Number ): Void

native

Writes a 16-bit integer to the byte stream.

Parameters

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


: