|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectTlv
Represents a "Type-Length-Value" block, a very popular data structure in the OSCAR protocol. Fun trivia: as of this writing, this class is referenced 267 times throughout joscar. A TLV simply contains a two-byte unsigned "type" and a "value" whose binary length is less than 65536 bytes. This class is immutable.
Constructor Summary | |
Tlv(ByteBlock tlvBytes)
Creates a new TLV from the beginning of the given data block. |
|
Tlv(int type)
Creates a TLV of the given type with no data block. |
|
Tlv(int type,
Writable data)
Creates a TLV of the given type with the given data block. |
Method Summary | |
ByteBlock |
getData()
Returns this TLV's data block. |
java.lang.String |
getDataAsString()
Returns this TLV's data block decoded into an US-ASCII string. |
long |
getDataAsUInt()
Returns an unsigned integer read from the first four bytes of this TLV's data block, or -1 if fewer than four bytes exist in the
block. |
int |
getDataAsUShort()
Returns an unsigned integer read from the first two bytes of this TLV's data block, or -1 if fewer than two bytes exist in the
block. |
LiveWritable |
getDataWriter()
Returns the object that will be used to write the TLV data to a stream. |
static Tlv |
getStringInstance(int type,
java.lang.String string)
Returns a new TLV of the given type containing the given string encoded to bytes with the US-ASCII encoder. |
int |
getTotalSize()
Returns the total size of this object, as read from an input stream. |
int |
getType()
Returns this TLV's type. |
static Tlv |
getUIntInstance(int type,
long number)
Returns a new TLV of the given type containing the given value as a four-byte unsigned integer as its data block. |
static Tlv |
getUShortInstance(int type,
int number)
Returns a new TLV of the given type containing the given value as a two-byte unsigned integer as its data block. |
long |
getWritableLength()
Returns the length of the data that was or will be written in a call to write . |
static boolean |
isValidTLV(ByteBlock tlvBytes)
Returns true if there is a valid TLV at the beginning of the
given data block. |
java.lang.String |
toString()
|
void |
write(java.io.OutputStream out)
Writes a representation of this object to the given stream. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Tlv(int type)
new Tlv(type, ByteBlock.EMPTY_BLOCK)
.
type
- the type of this TLVpublic Tlv(int type, Writable data)
type
- the type of this TLVdata
- this TLV's data blockpublic Tlv(ByteBlock tlvBytes) throws java.lang.IllegalArgumentException
getTotalSize
.
tlvBytes
- a block of data containing a TLV at the beginning
java.lang.IllegalArgumentException
- if the beginning of the given byte block
does not contain a valid TLV at the beginningMethod Detail |
public static Tlv getStringInstance(int type, java.lang.String string)
type
- the type of the TLV to be returnedstring
- the ASCII string to use as the TLV's data
public static Tlv getUShortInstance(int type, int number)
type
- the type of the TLV to be returnednumber
- the value of the TLV, to be encoded as a two-byte unsigned
integer
public static Tlv getUIntInstance(int type, long number)
type
- the type of the TLV to be returnednumber
- the value of the TLV, to be encoded as a four-byte unsigned
integer
public static boolean isValidTLV(ByteBlock tlvBytes)
true
if there is a valid TLV at the beginning of the
given data block. This only checks for the length of the block, and in no
way performs validation on its contents.
tlvBytes
- the bytes supposedly containing a TLV at the beginning
public final int getType()
0
to BinaryTools.USHORT_MAX
.
public final ByteBlock getData()
Writable
that is not a
ByteBlock
, a byte block is generated from that
Writable
, which may be a computationally expensive
operation.
public final LiveWritable getDataWriter()
ByteBlock
.
write(java.io.OutputStream)
public final java.lang.String getDataAsString()
BinaryTools.getAsciiString(net.kano.joscar.ByteBlock)
public final int getDataAsUShort()
-1
if fewer than two bytes exist in the
block.
-1
if none existsBinaryTools.getUShort(ByteBlock, int)
public final long getDataAsUInt()
-1
if fewer than four bytes exist in the
block.
-1
if none existsBinaryTools.getUInt(ByteBlock, int)
public final int getTotalSize()
-1
if this TLV was not read from a stream but instead
constructed manually.
-1
if
this object wasn't read from an incoming streampublic long getWritableLength()
Writable
write
. The value returned by this method must not
change after its first invocation.
getWritableLength
in interface Writable
write
public void write(java.io.OutputStream out) throws java.io.IOException
Writable
getWritableLength
.
write
in interface Writable
out
- the stream to which to write
java.io.IOException
- if an I/O error occurspublic java.lang.String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |