org.red5.io.amf3
Class ByteArray

java.lang.Object
  extended by org.red5.io.amf3.ByteArray
All Implemented Interfaces:
IDataInput, IDataOutput

public class ByteArray
extends Object
implements IDataInput, IDataOutput

Red5 version of the Flex ByteArray class.

Author:
The Red5 Project ([email protected]), Joachim Bauch ([email protected])

Field Summary
protected  IoBuffer data
          Internal storage for array contents.
protected  IDataInput dataInput
          Object used to read from array.
protected  IDataOutput dataOutput
          Object used to write to array.
 
Constructor Summary
  ByteArray()
          Public constructor.
protected ByteArray(IoBuffer buffer, int length)
          Internal constructor used to create ByteArray during deserialization.
 
Method Summary
 int bytesAvailable()
          Return number of bytes available for reading.
 void compress()
          Compress contents using zlib.
 boolean equals(Object obj)
           
protected  IoBuffer getData()
          Get internal data.
 ByteOrder getEndian()
          Return the byteorder used when loading values.
 int hashCode()
           
 int length()
          Return total number of bytes in array.
 int position()
          Get the current position in the data.
 void position(int position)
          Set the current position in the data.
protected  void prepareIO()
          Create internal objects used for reading and writing.
 boolean readBoolean()
          Read boolean value.
 byte readByte()
          Read signed single byte value.
 void readBytes(byte[] bytes)
          Read list of bytes.
 void readBytes(byte[] bytes, int offset)
          Read list of bytes to given offset.
 void readBytes(byte[] bytes, int offset, int length)
          Read given number of bytes to given offset.
 double readDouble()
          Read double-precision floating point value.
 float readFloat()
          Read single-precision floating point value.
 int readInt()
          Read signed integer value.
 String readMultiByte(int length, String charSet)
          Read multibyte string.
 Object readObject()
          Read arbitrary object.
 short readShort()
          Read signed short value.
 int readUnsignedByte()
          Read unsigned single byte value.
 long readUnsignedInt()
          Read unsigned integer value.
 int readUnsignedShort()
          Read unsigned short value.
 String readUTF()
          Read UTF-8 encoded string.
 String readUTFBytes(int length)
          Read UTF-8 encoded string with given length.
 void setEndian(ByteOrder endian)
          Set the byteorder to use when loading values.
 String toString()
          Return string representation of the array's contents.
 void uncompress()
          Decompress contents using zlib.
 void writeBoolean(boolean value)
          Write boolean value.
 void writeByte(byte value)
          Write signed byte value.
 void writeBytes(byte[] bytes)
          Write multiple bytes.
 void writeBytes(byte[] bytes, int offset)
          Write multiple bytes from given offset.
 void writeBytes(byte[] bytes, int offset, int length)
          Write given number of bytes from given offset.
 void writeDouble(double value)
          Write double-precision floating point value.
 void writeFloat(float value)
          Write single-precision floating point value.
 void writeInt(int value)
          Write signed integer value.
 void writeMultiByte(String value, String encoding)
          Write string in given character set.
 void writeObject(Object value)
          Write arbitrary object.
 void writeShort(short value)
          Write signed short value.
 void writeUnsignedInt(long value)
          Write unsigned integer value.
 void writeUTF(String value)
          Write UTF-8 encoded string.
 void writeUTFBytes(String value)
          Write UTF-8 encoded string as byte array.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

data

protected IoBuffer data
Internal storage for array contents.


dataInput

protected IDataInput dataInput
Object used to read from array.


dataOutput

protected IDataOutput dataOutput
Object used to write to array.

Constructor Detail

ByteArray

protected ByteArray(IoBuffer buffer,
                    int length)
Internal constructor used to create ByteArray during deserialization.

Parameters:
buffer -
length -

ByteArray

public ByteArray()
Public constructor. Creates new empty ByteArray.

Method Detail

prepareIO

protected void prepareIO()
Create internal objects used for reading and writing.


getData

protected IoBuffer getData()
Get internal data.

Returns:
byte buffer

position

public int position()
Get the current position in the data.

Returns:
current position

position

public void position(int position)
Set the current position in the data.

Parameters:
position - position to set

bytesAvailable

public int bytesAvailable()
Return number of bytes available for reading.

Returns:
bytes available

length

public int length()
Return total number of bytes in array.

Returns:
number of bytes in array

compress

public void compress()
Compress contents using zlib.


uncompress

public void uncompress()
Decompress contents using zlib.


getEndian

public ByteOrder getEndian()
Return the byteorder used when loading values.

Specified by:
getEndian in interface IDataInput
Specified by:
getEndian in interface IDataOutput
Returns:
the byteorder

readBoolean

public boolean readBoolean()
Read boolean value.

Specified by:
readBoolean in interface IDataInput
Returns:
the value

readByte

public byte readByte()
Read signed single byte value.

Specified by:
readByte in interface IDataInput
Returns:
the value

readBytes

public void readBytes(byte[] bytes)
Read list of bytes.

Specified by:
readBytes in interface IDataInput
Parameters:
bytes - destination for read bytes

readBytes

public void readBytes(byte[] bytes,
                      int offset)
Read list of bytes to given offset.

Specified by:
readBytes in interface IDataInput
Parameters:
bytes - destination for read bytes
offset - offset in destination to write to

readBytes

public void readBytes(byte[] bytes,
                      int offset,
                      int length)
Read given number of bytes to given offset.

Specified by:
readBytes in interface IDataInput
Parameters:
bytes - destination for read bytes
offset - offset in destination to write to
length - number of bytes to read

readDouble

public double readDouble()
Read double-precision floating point value.

Specified by:
readDouble in interface IDataInput
Returns:
the value

readFloat

public float readFloat()
Read single-precision floating point value.

Specified by:
readFloat in interface IDataInput
Returns:
the value

readInt

public int readInt()
Read signed integer value.

Specified by:
readInt in interface IDataInput
Returns:
the value

readMultiByte

public String readMultiByte(int length,
                            String charSet)
Read multibyte string.

Specified by:
readMultiByte in interface IDataInput
Parameters:
length - length of string to read
charSet - character set of string to read
Returns:
the string

readObject

public Object readObject()
Read arbitrary object.

Specified by:
readObject in interface IDataInput
Returns:
the object

readShort

public short readShort()
Read signed short value.

Specified by:
readShort in interface IDataInput
Returns:
the value

readUTF

public String readUTF()
Read UTF-8 encoded string.

Specified by:
readUTF in interface IDataInput
Returns:
the string

readUTFBytes

public String readUTFBytes(int length)
Read UTF-8 encoded string with given length.

Specified by:
readUTFBytes in interface IDataInput
Parameters:
length - the length of the string
Returns:
the string

readUnsignedByte

public int readUnsignedByte()
Read unsigned single byte value.

Specified by:
readUnsignedByte in interface IDataInput
Returns:
the value

readUnsignedInt

public long readUnsignedInt()
Read unsigned integer value.

Specified by:
readUnsignedInt in interface IDataInput
Returns:
the value

readUnsignedShort

public int readUnsignedShort()
Read unsigned short value.

Specified by:
readUnsignedShort in interface IDataInput
Returns:
the value

setEndian

public void setEndian(ByteOrder endian)
Set the byteorder to use when loading values.

Specified by:
setEndian in interface IDataInput
Specified by:
setEndian in interface IDataOutput
Parameters:
endian - the byteorder to use

writeBoolean

public void writeBoolean(boolean value)
Write boolean value.

Specified by:
writeBoolean in interface IDataOutput
Parameters:
value - the value

writeByte

public void writeByte(byte value)
Write signed byte value.

Specified by:
writeByte in interface IDataOutput
Parameters:
value - the value

writeBytes

public void writeBytes(byte[] bytes)
Write multiple bytes.

Specified by:
writeBytes in interface IDataOutput
Parameters:
bytes - the bytes

writeBytes

public void writeBytes(byte[] bytes,
                       int offset)
Write multiple bytes from given offset.

Specified by:
writeBytes in interface IDataOutput
Parameters:
bytes - the bytes
offset - offset in bytes to start writing from

writeBytes

public void writeBytes(byte[] bytes,
                       int offset,
                       int length)
Write given number of bytes from given offset.

Specified by:
writeBytes in interface IDataOutput
Parameters:
bytes - the bytes
offset - offset in bytes to start writing from
length - number of bytes to write

writeDouble

public void writeDouble(double value)
Write double-precision floating point value.

Specified by:
writeDouble in interface IDataOutput
Parameters:
value - the value

writeFloat

public void writeFloat(float value)
Write single-precision floating point value.

Specified by:
writeFloat in interface IDataOutput
Parameters:
value - the value

writeInt

public void writeInt(int value)
Write signed integer value.

Specified by:
writeInt in interface IDataOutput
Parameters:
value - the value

writeMultiByte

public void writeMultiByte(String value,
                           String encoding)
Write string in given character set.

Specified by:
writeMultiByte in interface IDataOutput
Parameters:
value - the string
encoding - the character set

writeObject

public void writeObject(Object value)
Write arbitrary object.

Specified by:
writeObject in interface IDataOutput
Parameters:
value - the object

writeShort

public void writeShort(short value)
Write signed short value.

Specified by:
writeShort in interface IDataOutput
Parameters:
value - the value

writeUTF

public void writeUTF(String value)
Write UTF-8 encoded string.

Specified by:
writeUTF in interface IDataOutput
Parameters:
value - the string

writeUTFBytes

public void writeUTFBytes(String value)
Write UTF-8 encoded string as byte array. This string is stored without informations about its length, so IDataInput.readUTFBytes(int) must be used to load it.

Specified by:
writeUTFBytes in interface IDataOutput
Parameters:
value - the string

writeUnsignedInt

public void writeUnsignedInt(long value)
Write unsigned integer value.

Specified by:
writeUnsignedInt in interface IDataOutput
Parameters:
value - the value

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Return string representation of the array's contents.

Overrides:
toString in class Object
Returns:
string representation of array's contents.


Copyright © 2006-2012 The Red5 Project