Package org.red5.io.amf3
Class ByteArray
- java.lang.Object
-
- 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, Joachim Bauch (jojo@struktur.de)
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.mina.core.buffer.IoBufferdataInternal storage for array contents.protected IDataInputdataInputObject used to read from array.protected IDataOutputdataOutputObject used to write to array.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intbytesAvailable()Return number of bytes available for reading.voidcompress()Compress contents using zlib.booleanequals(Object obj)protected org.apache.mina.core.buffer.IoBuffergetData()Get internal data.ByteOrdergetEndian()Return the byteorder used when loading values.inthashCode()intlength()Return total number of bytes in array.intposition()Get the current position in the data.voidposition(int position)Set the current position in the data.protected voidprepareIO()Create internal objects used for reading and writing.booleanreadBoolean()Read boolean value.bytereadByte()Read signed single byte value.voidreadBytes(byte[] bytes)Read list of bytes.voidreadBytes(byte[] bytes, int offset)Read list of bytes to given offset.voidreadBytes(byte[] bytes, int offset, int length)Read given number of bytes to given offset.doublereadDouble()Read double-precision floating point value.floatreadFloat()Read single-precision floating point value.intreadInt()Read signed integer value.StringreadMultiByte(int length, String charSet)Read multibyte string.ObjectreadObject()Read arbitrary object.shortreadShort()Read signed short value.intreadUnsignedByte()Read unsigned single byte value.longreadUnsignedInt()Read unsigned integer value.intreadUnsignedShort()Read unsigned short value.StringreadUTF()Read UTF-8 encoded string.StringreadUTFBytes(int length)Read UTF-8 encoded string with given length.voidsetEndian(ByteOrder endian)Set the byteorder to use when loading values.StringtoString()Return string representation of the array's contents.voiduncompress()Decompress contents using zlib.voidwriteBoolean(boolean value)Write boolean value.voidwriteByte(byte value)Write signed byte value.voidwriteBytes(byte[] bytes)Write multiple bytes.voidwriteBytes(byte[] bytes, int offset)Write multiple bytes from given offset.voidwriteBytes(byte[] bytes, int offset, int length)Write given number of bytes from given offset.voidwriteDouble(double value)Write double-precision floating point value.voidwriteFloat(float value)Write single-precision floating point value.voidwriteInt(int value)Write signed integer value.voidwriteMultiByte(String value, String encoding)Write string in given character set.voidwriteObject(Object value)Write arbitrary object.voidwriteShort(short value)Write signed short value.voidwriteUnsignedInt(long value)Write unsigned integer value.voidwriteUTF(String value)Write UTF-8 encoded string.voidwriteUTFBytes(String value)Write UTF-8 encoded string as byte array.
-
-
-
Field Detail
-
data
protected org.apache.mina.core.buffer.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(org.apache.mina.core.buffer.IoBuffer buffer, int length)Internal constructor used to create ByteArray during deserialization.- Parameters:
buffer- io bufferlength- 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 org.apache.mina.core.buffer.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:
getEndianin interfaceIDataInput- Specified by:
getEndianin interfaceIDataOutput- Returns:
- the byteorder
-
readBoolean
public boolean readBoolean()
Read boolean value.- Specified by:
readBooleanin interfaceIDataInput- Returns:
- the value
-
readByte
public byte readByte()
Read signed single byte value.- Specified by:
readBytein interfaceIDataInput- Returns:
- the value
-
readBytes
public void readBytes(byte[] bytes)
Read list of bytes.- Specified by:
readBytesin interfaceIDataInput- Parameters:
bytes- destination for read bytes
-
readBytes
public void readBytes(byte[] bytes, int offset)Read list of bytes to given offset.- Specified by:
readBytesin interfaceIDataInput- Parameters:
bytes- destination for read bytesoffset- 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:
readBytesin interfaceIDataInput- Parameters:
bytes- destination for read bytesoffset- offset in destination to write tolength- number of bytes to read
-
readDouble
public double readDouble()
Read double-precision floating point value.- Specified by:
readDoublein interfaceIDataInput- Returns:
- the value
-
readFloat
public float readFloat()
Read single-precision floating point value.- Specified by:
readFloatin interfaceIDataInput- Returns:
- the value
-
readInt
public int readInt()
Read signed integer value.- Specified by:
readIntin interfaceIDataInput- Returns:
- the value
-
readMultiByte
public String readMultiByte(int length, String charSet)
Read multibyte string.- Specified by:
readMultiBytein interfaceIDataInput- Parameters:
length- length of string to readcharSet- character set of string to read- Returns:
- the string
-
readObject
public Object readObject()
Read arbitrary object.- Specified by:
readObjectin interfaceIDataInput- Returns:
- the object
-
readShort
public short readShort()
Read signed short value.- Specified by:
readShortin interfaceIDataInput- Returns:
- the value
-
readUTF
public String readUTF()
Read UTF-8 encoded string.- Specified by:
readUTFin interfaceIDataInput- Returns:
- the string
-
readUTFBytes
public String readUTFBytes(int length)
Read UTF-8 encoded string with given length.- Specified by:
readUTFBytesin interfaceIDataInput- Parameters:
length- the length of the string- Returns:
- the string
-
readUnsignedByte
public int readUnsignedByte()
Read unsigned single byte value.- Specified by:
readUnsignedBytein interfaceIDataInput- Returns:
- the value
-
readUnsignedInt
public long readUnsignedInt()
Read unsigned integer value.- Specified by:
readUnsignedIntin interfaceIDataInput- Returns:
- the value
-
readUnsignedShort
public int readUnsignedShort()
Read unsigned short value.- Specified by:
readUnsignedShortin interfaceIDataInput- Returns:
- the value
-
setEndian
public void setEndian(ByteOrder endian)
Set the byteorder to use when loading values.- Specified by:
setEndianin interfaceIDataInput- Specified by:
setEndianin interfaceIDataOutput- Parameters:
endian- the byteorder to use
-
writeBoolean
public void writeBoolean(boolean value)
Write boolean value.- Specified by:
writeBooleanin interfaceIDataOutput- Parameters:
value- the value
-
writeByte
public void writeByte(byte value)
Write signed byte value.- Specified by:
writeBytein interfaceIDataOutput- Parameters:
value- the value
-
writeBytes
public void writeBytes(byte[] bytes)
Write multiple bytes.- Specified by:
writeBytesin interfaceIDataOutput- Parameters:
bytes- the bytes
-
writeBytes
public void writeBytes(byte[] bytes, int offset)Write multiple bytes from given offset.- Specified by:
writeBytesin interfaceIDataOutput- Parameters:
bytes- the bytesoffset- 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:
writeBytesin interfaceIDataOutput- Parameters:
bytes- the bytesoffset- offset in bytes to start writing fromlength- number of bytes to write
-
writeDouble
public void writeDouble(double value)
Write double-precision floating point value.- Specified by:
writeDoublein interfaceIDataOutput- Parameters:
value- the value
-
writeFloat
public void writeFloat(float value)
Write single-precision floating point value.- Specified by:
writeFloatin interfaceIDataOutput- Parameters:
value- the value
-
writeInt
public void writeInt(int value)
Write signed integer value.- Specified by:
writeIntin interfaceIDataOutput- Parameters:
value- the value
-
writeMultiByte
public void writeMultiByte(String value, String encoding)
Write string in given character set.- Specified by:
writeMultiBytein interfaceIDataOutput- Parameters:
value- the stringencoding- the character set
-
writeObject
public void writeObject(Object value)
Write arbitrary object.- Specified by:
writeObjectin interfaceIDataOutput- Parameters:
value- the object
-
writeShort
public void writeShort(short value)
Write signed short value.- Specified by:
writeShortin interfaceIDataOutput- Parameters:
value- the value
-
writeUTF
public void writeUTF(String value)
Write UTF-8 encoded string.- Specified by:
writeUTFin interfaceIDataOutput- 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, soIDataInput.readUTFBytes(int)must be used to load it.- Specified by:
writeUTFBytesin interfaceIDataOutput- Parameters:
value- the string
-
writeUnsignedInt
public void writeUnsignedInt(long value)
Write unsigned integer value.- Specified by:
writeUnsignedIntin interfaceIDataOutput- Parameters:
value- the value
-
-