Package | flash.utils |
Interface | public interface IDataOutput |
Implementors | ByteArray, FileStream, Socket |
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 |
All IDataInput and IDataOutput operations are "bigEndian" by default (the most significant byte in the sequence is stored at the lowest or first storage address), and are nonblocking.
Sign extension matters only when you read data, not when you write it. Therefore, you do not need separate
write methods to work with IDataInput.readUnsignedByte()
and
IDataInput.readUnsignedShort()
. In other words:
- Use
IDataOutput.writeByte()
withIDataInput.readUnsignedByte()
andIDataInput.readByte()
. - Use
IDataOutput.writeShort()
withIDataInput.readUnsignedShort()
andIDataInput.readShort()
.
Related API Elements
Property | Defined By | ||
---|---|---|---|
endian : String
The byte order for the data, either the BIG_ENDIAN or LITTLE_ENDIAN
constant from the Endian class. | IDataOutput | ||
objectEncoding : uint
Used to determine whether the AMF3 or AMF0 format is used when writing or reading binary data using the
writeObject() method. | IDataOutput |
Method | Defined By | ||
---|---|---|---|
Writes a Boolean value. | IDataOutput | ||
Writes a byte. | IDataOutput | ||
Writes a sequence of bytes from the
specified byte array, bytes,
starting at the byte specified by offset
(using a zero-based index)
with a length specified by length,
into the file stream, byte stream, or byte array. | IDataOutput | ||
Writes an IEEE 754 double-precision (64-bit) floating point number. | IDataOutput | ||
Writes an IEEE 754 single-precision (32-bit) floating point number. | IDataOutput | ||
Writes a 32-bit signed integer. | IDataOutput | ||
Writes a multibyte string to the file stream, byte stream, or byte array, using the specified character set. | IDataOutput | ||
Writes an object to the file stream, byte stream, or byte array, in AMF serialized
format. | IDataOutput | ||
Writes a 16-bit integer. | IDataOutput | ||
Writes a 32-bit unsigned integer. | IDataOutput | ||
Writes a UTF-8 string to the file stream, byte stream, or byte array. | IDataOutput | ||
Writes a UTF-8 string. | IDataOutput |
endian | property |
endian:String
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 |
The byte order for the data, either the BIG_ENDIAN
or LITTLE_ENDIAN
constant from the Endian class.
Implementation
public function get endian():String
public function set endian(value:String):void
Related API Elements
objectEncoding | property |
objectEncoding:uint
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 |
Used to determine whether the AMF3 or AMF0 format is used when writing or reading binary data using the
writeObject()
method. The value is a constant from the ObjectEncoding class.
Implementation
public function get objectEncoding():uint
public function set objectEncoding(value:uint):void
Related API Elements
writeBoolean | () | method |
public function writeBoolean(value:Boolean):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 |
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 ,
1 is written; if false , 0 is written.
|
writeByte | () | method |
writeBytes | () | method |
public function writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 |
Writes a sequence of bytes from the
specified byte array, bytes
,
starting at the byte specified by offset
(using a zero-based index)
with a length specified by length
,
into the file stream, byte stream, or byte array.
If the length
parameter is omitted, the default
length of 0 is used and the entire buffer starting at
offset
is written.
If the offset
parameter is also omitted, the entire buffer is
written.
If the offset
or length
parameter
is out of range, they are clamped to the beginning and end
of the bytes
array.
Parameters
bytes:ByteArray — The byte array to write.
| |
offset:uint (default = 0 ) — A zero-based index specifying the position into the array to begin writing.
| |
length:uint (default = 0 ) — An unsigned integer specifying how far into the buffer to write.
|
writeDouble | () | method |
writeFloat | () | method |
writeInt | () | method |
writeMultiByte | () | method |
public function writeMultiByte(value:String, charSet:String):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 |
Writes a multibyte string to the file stream, byte stream, or byte array, 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 |
writeShort | () | method |
writeUnsignedInt | () | method |
writeUTF | () | method |
public function writeUTF(value:String):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 |
Writes a UTF-8 string to the file stream, byte stream, or byte array. 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.
|
Throws
RangeError — If the length is larger than
65535.
|
writeUTFBytes | () | method |
DataOutputExample
to write a boolean
and the double-precision floating-point representation of pi to a byte array. This is accomplished
using the following steps:
- Declare a new ByteArray object instance
byteArr
. - Write the byte-equivalent value of the Boolean
false
and the double-precision floating-point equivalent of the mathematical value of pi. - Read back the boolean and double-precision floating-point number.
Notice how a code segment is added at the end to check for end of file errors to ensure that the byte stream is not read past its end.
package { import flash.display.Sprite; import flash.utils.ByteArray; import flash.errors.EOFError; public class DataOutputExample extends Sprite { public function DataOutputExample() { var byteArr:ByteArray = new ByteArray(); byteArr.writeBoolean(false); byteArr.writeDouble(Math.PI); byteArr.position = 0; try { trace(byteArr.readBoolean()); // false } catch(e:EOFError) { trace(e); // EOFError: Error #2030: End of file was encountered. } try { trace(byteArr.readDouble()); // 3.141592653589793 } catch(e:EOFError) { trace(e); // EOFError: Error #2030: End of file was encountered. } try { trace(byteArr.readDouble()); } catch(e:EOFError) { trace(e); // EOFError: Error #2030: End of file was encountered. } } } }
Thu Dec 6 2018, 01:12 PM -08:00