| window.runtime property | window.runtime.flash.utils.ByteArray |
| Runtime Versions: | 1.0 |
Note: The ByteArray class 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, but an instance of the ByteArray
class can be manipulated with the standard [] (array access) operators.
It also can be read and written to as an in-memory file, using
methods similar to those in the URLStream and Socket classes.
In addition, zlib compression and decompression are supported, as well as Action Message Format (AMF) object serialization.
Possible uses of the ByteArray class include the following:
See also
| Property | Defined By | ||
|---|---|---|---|
| bytesAvailable : uint [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. | ByteArray | ||
| defaultObjectEncoding : uint [static]
Denotes the default object encoding for the ByteArray class to use for a new ByteArray instance. | ByteArray | ||
| endian : String
Changes or reads the byte order for the data; either Endian.BIG_ENDIAN or
Endian.LITTLE_ENDIAN. | ByteArray | ||
| length : uint
The length of the ByteArray object, in bytes. | ByteArray | ||
| objectEncoding : uint
Used to determine whether the ActionScript 3.0, ActionScript 2.0, or ActionScript 1.0 format should be
used when writing to, or reading from, a ByteArray instance. | ByteArray | ||
| position : uint
Moves, or returns the current position, in bytes, of the file
pointer into the ByteArray object. | ByteArray | ||
| Method | Defined By | ||
|---|---|---|---|
Creates a ByteArray instance representing a packed array of bytes, so that you can use the methods and properties in this class to optimize your data storage and stream. | ByteArray | ||
clear():void
Clears the contents of the byte array and resets the length
and position properties to 0. | ByteArray | ||
Compresses the byte array. | ByteArray | ||
deflate():void
Compresses the byte array using the deflate compression algorithm. | ByteArray | ||
inflate():void
Decompresses the byte array using the deflate compression algorithm. | ByteArray | ||
Reads a Boolean value from the byte stream. | ByteArray | ||
Reads a signed byte from the byte stream. | ByteArray | ||
Reads the number of data bytes, specified by the length parameter, from the byte stream. | ByteArray | ||
Reads an IEEE 754 double-precision (64-bit) floating-point number from the byte stream. | ByteArray | ||
Reads an IEEE 754 single-precision (32-bit) floating-point number from the byte stream. | ByteArray | ||
Reads a signed 32-bit integer from the byte stream. | ByteArray | ||
Reads a multibyte string of specified length from the byte stream using the
specified character set. | ByteArray | ||
readObject():*
Reads an object from the byte array, encoded in AMF
serialized format. | ByteArray | ||
Reads a signed 16-bit integer from the byte stream. | ByteArray | ||
Reads an unsigned byte from the byte stream. | ByteArray | ||
Reads an unsigned 32-bit integer from the byte stream. | ByteArray | ||
Reads an unsigned 16-bit integer from the byte stream. | ByteArray | ||
Reads a UTF-8 string from the byte stream. | ByteArray | ||
Reads a sequence of UTF-8 bytes specified by the length
parameter from the byte stream and returns a string. | ByteArray | ||
Converts the byte array to a string. | ByteArray | ||
uncompress(algorithm:String):void
Decompresses the byte array. | ByteArray | ||
writeBoolean(value:Boolean):void
Writes a Boolean value. | ByteArray | ||
Writes a byte to the byte stream. | ByteArray | ||
Writes a sequence of length bytes from the
specified byte array, bytes,
starting offset (zero-based index) bytes
into the byte stream. | ByteArray | ||
writeDouble(value:Number):void
Writes an IEEE 754 double-precision (64-bit) floating-point number to the byte stream. | ByteArray | ||
writeFloat(value:Number):void
Writes an IEEE 754 single-precision (32-bit) floating-point number to the byte stream. | ByteArray | ||
Writes a 32-bit signed integer to the byte stream. | ByteArray | ||
Writes a multibyte string to the byte stream using the specified character set. | ByteArray | ||
writeObject(object:*):void
Writes an object into the byte array in AMF
serialized format. | ByteArray | ||
writeShort(value:int):void
Writes a 16-bit integer to the byte stream. | ByteArray | ||
writeUnsignedInt(value:uint):void
Writes a 32-bit unsigned integer to the byte stream. | ByteArray | ||
Writes a UTF-8 string to the byte stream. | ByteArray | ||
writeUTFBytes(value:String):void
Writes a UTF-8 string to the byte stream. | ByteArray | ||
| bytesAvailable | property |
bytesAvailable:uint [read-only] | Runtime Versions: | 1.0 |
The number of bytes of data available for reading from the current position in the byte array to the end of the array.
Use the bytesAvailable property in conjunction
with the read methods each time you access a ByteArray object
to ensure that you are reading valid data.
| defaultObjectEncoding | property |
defaultObjectEncoding:uint| Runtime Versions: | 1.0 |
Denotes the default object encoding for the ByteArray class to use for a new ByteArray instance.
When you create a new ByteArray instance, the encoding on that instance starts
with the value of defaultObjectEncoding.
The defaultObjectEncoding property is initialized to ObjectEncoding.AMF3.
When an object is written to or read from binary data, the objectEncoding value
is used to determine whether the ActionScript 3.0, ActionScript2.0, or ActionScript 1.0 format should be used. The value is a
constant from the ObjectEncoding class.
See also
| endian | property |
endian:String| Runtime Versions: | 1.0 |
Changes or reads the byte order for the data; either Endian.BIG_ENDIAN or
Endian.LITTLE_ENDIAN.
See also
| length | property |
length:uint| Runtime Versions: | 1.0 |
The length of the ByteArray object, in bytes.
If the length is set to a value that is larger than the current length, the the right side of the byte array is filled with zeros.
If the length is set to a value that is smaller than the current length, the byte array is truncated.
| objectEncoding | property |
objectEncoding:uint| Runtime Versions: | 1.0 |
Used to determine whether the ActionScript 3.0, ActionScript 2.0, or ActionScript 1.0 format should be used when writing to, or reading from, a ByteArray instance. The value is a constant from the ObjectEncoding class.
See also
| position | property |
position:uint| Runtime Versions: | 1.0 |
Moves, or returns the current position, in bytes, of the file pointer 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.
| ByteArray | () | Constructor |
function ByteArray()| Runtime Versions: | 1.0 |
Creates a ByteArray instance representing a packed array of bytes, so that you can use the methods and properties in this class to optimize your data storage and stream.
| clear | () | method |
function clear():void| Runtime Versions: | 1.5 |
Clears the contents of the byte array and resets the length
and position properties to 0. Calling this method explicitly
frees up the memory used by the ByteArray instance.
| compress | () | method |
function compress(algorithm:String):void
Compresses the byte array. The entire byte array is compressed. For content
running in Adobe AIR, you can specify a compression algorithm by passing a
value (defined in the CompressionAlgorithm class) as the algorithm
parameter.
After the call, the length property of the ByteArray is set to the new length.
The position property is set to the end of the byte array.
The zlib compressed data format is described at http://www.ietf.org/rfc/rfc1950.txt.
The deflate compression algorithm is described at http://www.ietf.org/rfc/rfc1951.txt.
The deflate compression algorithm is used in several compression formats, such as zlib, gzip, some zip implementations, and others. When data is compressed using one of those compression formats, in addition to storing the compressed version of the original data, the compression format data (for example, the .zip file) includes metadata information. Some examples of the types of metadata included in various file formats are file name, file modification date/time, original file size, optional comments, checksum data, and more.
For example, when a ByteArray is compressed using the zlib algorithm,
the resulting ByteArray is structured in a specific format. Certain bytes contain
metadata about the compressed data, while other bytes contain the actual compressed
version of the original ByteArray data. As defined by the zlib compressed data
format specification, those bytes (that is, the portion containing
the compressed version of the original data) are compressed using the deflate
algorithm. Consequently those bytes are identical to the result of calling
compress(CompressionAlgorithm.DEFLATE)
on the original ByteArray. However, the result from
compress(CompressionAlgorithm.ZLIB) includes
the extra metadata, while the compress(air.CompressionAlgorithm.DEFLATE)
result includes only the compressed version of the original ByteArray data and nothing else.
In order to use the deflate format to compress a ByteArray instance's
data in a specific format such as gzip or zip, you cannot simply call
compress(air.CompressionAlgorithm.DEFLATE).
You must create a ByteArray structured
according to the compression format's specification, including the appropriate
metadata as well as the compressed data obtained using the deflate format.
Likewise, in order to decode data compressed in a format such
as gzip or zip, you can't simply call uncompress(air.CompressionAlgorithm.DEFLATE)
on that data. First, you must separate the metadata from the compressed data, and you can
then use the deflate format to decompress the compressed data.
Parameters
algorithm:String (default = NaN) — The compression algorithm to use when compressing. Valid values are defined as
constants in the CompressionAlgorithm class. The default is to use zlib format.
Calling compress(air.CompressionAlgorithm.DEFLATE)
has the same effect as calling the deflate() method.
|
See also
| deflate | () | method |
function deflate():void| Runtime Versions: | 1.5 |
Compresses the byte array using the deflate compression algorithm. The entire byte array is compressed.
After the call, the length property of the ByteArray is set to the new length.
The position property is set to the end of the byte array.
The deflate compression algorithm is described at http://www.ietf.org/rfc/rfc1951.txt.
In order to use the deflate format to compress a ByteArray instance's
data in a specific format such as gzip or zip, you cannot simply call
deflate(). You must create a ByteArray structured
according to the compression format's specification, including the appropriate
metadata as well as the compressed data obtained using the deflate format.
Likewise, in order to decode data compressed in a format such
as gzip or zip, you can't simply call inflate()
on that data. First, you must separate the metadata from the compressed data, and you can
then use the deflate format to decompress the compressed data.
See also
| inflate | () | method |
function inflate():void| Runtime Versions: | 1.0 |
Decompresses the byte array using the deflate compression algorithm. The byte array must have been compressed using the same algorithm.
After the call, the length property of the ByteArray is set to the new length.
The position property is set to 0.
The deflate compression algorithm is described at http://www.ietf.org/rfc/rfc1951.txt.
In order to decode data compressed in a format that uses the deflate compression algorithm,
such as data in gzip or zip format, it will not work to simply call inflate() on
a ByteArray containing the compression formation data. First, you must separate the metadata that is
included as part of the compressed data format from the actual compressed data. For more
information, see the compress() method description.
IOError — The data is not valid compressed data; it was not compressed with the
same compression algorithm used to compress.
|
See also
| readBoolean | () | method |
function readBoolean():Boolean| Runtime Versions: | 1.0 |
Reads a Boolean value from the byte stream. A single byte is read,
and true is returned if the byte is nonzero,
false otherwise.
Boolean — Returns true if the byte is nonzero, false otherwise.
|
EOFError — There is not sufficient data available
to read.
|
| readByte | () | method |
function readByte():int| Runtime Versions: | 1.0 |
Reads a signed byte from the byte stream.
The returned value is in the range -128 to 127.
Returnsint — An integer between -128 and 127.
|
EOFError — There is not sufficient data available
to read.
|
| readBytes | () | method |
function readBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void| Runtime Versions: | 1.0 |
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:uint (default = 0) — The offset (position) in bytes at which the read data should be written.
| |
length:uint (default = 0) — The number of bytes to read. The default value of 0 causes all available data to be read.
|
EOFError — There is not sufficient data available
to read.
|
| readDouble | () | method |
function readDouble():Number| Runtime Versions: | 1.0 |
Reads an IEEE 754 double-precision (64-bit) floating-point number from the byte stream.
ReturnsNumber — A double-precision (64-bit) floating-point number.
|
EOFError — There is not sufficient data available
to read.
|
| readFloat | () | method |
function readFloat():Number| Runtime Versions: | 1.0 |
Reads an IEEE 754 single-precision (32-bit) floating-point number from the byte stream.
ReturnsNumber — A single-precision (32-bit) floating-point number.
|
EOFError — There is not sufficient data available
to read.
|
| readInt | () | method |
function readInt():int| Runtime Versions: | 1.0 |
Reads a signed 32-bit integer from the byte stream.
The returned value is in the range -2147483648 to 2147483647.
Returnsint — A 32-bit signed integer between -2147483648 and 2147483647.
|
EOFError — There is not sufficient data available
to read.
|
| readMultiByte | () | method |
function readMultiByte(length:uint, charSet:String):String| Runtime Versions: | 1.0 |
Reads a multibyte string of specified length from the byte stream using the specified character set.
Parameters
length:uint — The number of bytes from the byte stream to read.
| |
charSet:String — 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.
Note: If the value for the |
String — UTF-8 encoded string.
|
EOFError — There is not sufficient data available
to read.
|
| readObject | () | method |
function readObject():*| Runtime Versions: | 1.0 |
Reads an object from the byte array, encoded in AMF serialized format.
Returns* — The deserialized object.
|
EOFError — There is not sufficient data available
to read.
|
| readShort | () | method |
function readShort():int| Runtime Versions: | 1.0 |
Reads a signed 16-bit integer from the byte stream.
The returned value is in the range -32768 to 32767.
Returnsint — A 16-bit signed integer between -32768 and 32767.
|
EOFError — There is not sufficient data available
to read.
|
| readUnsignedByte | () | method |
function readUnsignedByte():uint| Runtime Versions: | 1.0 |
Reads an unsigned byte from the byte stream.
The returned value is in the range 0 to 255.
Returnsuint — A 32-bit unsigned integer between 0 and 255.
|
EOFError — There is not sufficient data available
to read.
|
| readUnsignedInt | () | method |
function readUnsignedInt():uint| Runtime Versions: | 1.0 |
Reads an unsigned 32-bit integer from the byte stream.
The returned value is in the range 0 to 4294967295.
Returnsuint — A 32-bit unsigned integer between 0 and 4294967295.
|
EOFError — There is not sufficient data available
to read.
|
| readUnsignedShort | () | method |
function readUnsignedShort():uint| Runtime Versions: | 1.0 |
Reads an unsigned 16-bit integer from the byte stream.
The returned value is in the range 0 to 65535.
Returnsuint — A 16-bit unsigned integer between 0 and 65535.
|
EOFError — There is not sufficient data available
to read.
|
| readUTF | () | method |
function readUTF():String| Runtime Versions: | 1.0 |
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.
ReturnsString — UTF-8 encoded string.
|
EOFError — There is not sufficient data available
to read.
|
| readUTFBytes | () | method |
function readUTFBytes(length:uint):String| Runtime Versions: | 1.0 |
Reads a sequence of UTF-8 bytes specified by the length
parameter from the byte stream and returns a string.
Parameters
length:uint — An unsigned short indicating the length of the UTF-8 bytes.
|
String — A string composed of the UTF-8 bytes of the specified length.
|
EOFError — There is not sufficient data available
to read.
|
| toString | () | method |
function toString():String| Runtime Versions: | 1.0 |
Converts the byte array to a string.
If the data in the array begins with a Unicode byte order mark, the application will honor that mark
when converting to a string. If System.useCodePage is set to true, the
application will treat the data in the array as being in the current system code page when converting.
String — The string representation of the byte array.
|
| uncompress | () | method |
function uncompress(algorithm:String):void| Runtime Versions: | 1.0 |
Decompresses the byte array. For content running in Adobe AIR, you can specify
a compression algorithm by passing a value (defined in the CompressionAlgorithm class)
as the algorithm parameter. The byte array must have been compressed
using the same algorithm.
After the call, the length property of the ByteArray is set to the new length.
The position property is set to 0.
The zlib compressed data format is described at http://www.ietf.org/rfc/rfc1950.txt.
The deflate compression algorithm is described at http://www.ietf.org/rfc/rfc1951.txt.
In order to decode data compressed in a format that uses the deflate compression algorithm,
such as data in gzip or zip format, it will not work to call
uncompress(CompressionAlgorithm.DEFLATE) on
a ByteArray containing the compression formation data. First, you must separate the metadata that is
included as part of the compressed data format from the actual compressed data. For more
information, see the compress() method description.
Parameters
algorithm:String (default = NaN) — 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 class. The default is to use zlib format. This parameter
is only recognized for content running in Adobe AIR.
|
IOError — The data is not valid compressed data; it was not compressed with the
same compression algorithm used to compress.
|
See also
| writeBoolean | () | method |
function writeBoolean(value:Boolean):void| Runtime Versions: | 1.0 |
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 | () | method |
function writeByte(value:int):void| Runtime Versions: | 1.0 |
Writes a byte to the byte stream.
The low 8 bits of the parameter are used. The high 24 bits are ignored.
Parameters
value:int — A 32-bit integer. The low 8 bits are written to the byte stream.
|
| writeBytes | () | method |
function writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void| Runtime Versions: | 1.0 |
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.
If offset or length
is out of range, they are clamped to the beginning and end
of the bytes array.
Parameters
bytes:ByteArray — The ByteArray object.
| |
offset:uint (default = 0) — A zero-based index indicating the position into the array to begin writing.
| |
length:uint (default = 0) — An unsigned integer indicating how far into the buffer to write.
|
| writeDouble | () | method |
function writeDouble(value:Number):void| Runtime Versions: | 1.0 |
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 | () | method |
function writeFloat(value:Number):void| Runtime Versions: | 1.0 |
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 | () | method |
function writeInt(value:int):void| Runtime Versions: | 1.0 |
Writes a 32-bit signed integer to the byte stream.
Parameters
value:int — An integer to write to the byte stream.
|
| writeMultiByte | () | method |
function writeMultiByte(value:String, charSet:String):void| Runtime Versions: | 1.0 |
Writes a multibyte string to the byte stream using the specified character set.
Parameters
value:String — The string value to be written.
| |
charSet:String — The string denoting the character set to use. Possible character set strings
include "shift-jis", "cn-gb", "iso-8859-1", and others.
For a complete list, see Supported Character Sets.
|
| writeObject | () | method |
function writeObject(object:*):void| Runtime Versions: | 1.0 |
Writes an object into the byte array in AMF serialized format.
Parameters
object:* — The object to serialize.
|
| writeShort | () | method |
function writeShort(value:int):void| Runtime Versions: | 1.0 |
Writes a 16-bit integer to the byte stream. The low 16 bits of the parameter are used. The high 16 bits are ignored.
Parameters
value:int — 32-bit integer, whose low 16 bits are written to the byte stream.
|
| writeUnsignedInt | () | method |
function writeUnsignedInt(value:uint):void| Runtime Versions: | 1.0 |
Writes a 32-bit unsigned integer to the byte stream.
Parameters
value:uint — An unsigned integer to write to the byte stream.
|
| writeUTF | () | method |
function writeUTF(value:String):void| Runtime Versions: | 1.0 |
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.
|
— If the length is larger than
65535.
|
| writeUTFBytes | () | method |
function writeUTFBytes(value:String):void| Runtime Versions: | 1.0 |
Writes a UTF-8 string to the byte stream. Similar to the writeUTF() method,
but writeUTFBytes() does not prefix the string with a 16-bit length word.
Parameters
value:String — The string value to be written.
|