|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectAbstractTlvChain
A base class for TLV chains, implementing basic functionality while leaving
extra features and data storage to subclasses.
Extending this class requires one to hold both a list of all contained
TLV's as well as a map from TLV type to TLV's in the chain with that type.
See getTlvList()
and getTlvMap()
for details.
Constructor Summary | |
protected |
AbstractTlvChain()
Creates a new TLV chain with a total size of -1 . |
protected |
AbstractTlvChain(int totalSize)
Creates a new TLV chain with the given total byte size, as read from an incoming stream. |
Method Summary | |
protected void |
addTlvImpl(Tlv tlv)
Adds a TLV to this chain. |
protected void |
copy(TlvChain chain)
Effectively makes this chain a copy of the given chain. |
protected java.util.List |
createSiblingList()
Creates a new List to serve as a value for the TLV map. |
Tlv |
getFirstTlv(int type)
Returns the first TLV in this chain with the given type, or null of TLV of the given type is present. |
Tlv |
getLastTlv(int type)
Returns the last TLV in this chain with the given type, or null of TLV of the given type is present. |
java.lang.String |
getString(int type)
Returns the ASCII string contained in the last TLV in this chain with the given type, or null if no TLV with the given type
is present in this chain. |
java.lang.String |
getString(int type,
java.lang.String charset)
Returns the string contained in the last TLV in this chain with the given type, decoded with the given charset, or null
if no TLV with the given type is present in this chain. |
int |
getTlvCount()
Returns the number of TLV's in this chain. |
protected abstract java.util.List |
getTlvList()
Returns a list of all of the TLV's in this chain. |
protected abstract java.util.Map |
getTlvMap()
Returns a map from TLV types (as Integer s) to TLV lists (as
List s). |
Tlv[] |
getTlvs()
Returns an array of all TLV's in this chain, in order. |
Tlv[] |
getTlvs(int type)
Returns an array containing all TLV's in this chain with the given TLV type, with original order preserved. |
int |
getTotalSize()
Returns the total size, in bytes, of this chain, as read from an incoming stream. |
long |
getUInt(int type)
Returns an unsigned four-byte integer read from the value of the last TLV of the given type in this chain, or -1 if
either no TLV of the given type is present in this chain or if the data
block for the TLV contains fewer than two bytes. |
int |
getUShort(int type)
Returns an unsigned two-byte integer read from the value of the last TLV of the given type in this chain, or -1 if
either no TLV of the given type is present in this chain or if the data
block for the TLV contains fewer than two bytes. |
long |
getWritableLength()
Returns the length of the data that was or will be written in a call to write . |
boolean |
hasTlv(int type)
Returns true if this TLV chain contains any TLV's of the
given TLV type. |
protected void |
initFromBlock(ByteBlock block,
int maxTlvs)
Copies the given number of TLV's from the given block of TLV's into this chain. |
java.util.Iterator |
iterator()
Returns an iterator over the TLV's in this TLV chain. |
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 |
protected AbstractTlvChain()
-1
.
protected AbstractTlvChain(int totalSize)
totalSize
- the total size of this object, in bytes, or
-1
if this object was not read from a block of binary
dataMethod Detail |
protected final void copy(TlvChain chain)
chain
- a TLV chain to copyprotected final void initFromBlock(ByteBlock block, int maxTlvs)
block
- a data block containing zero or more TLV'smaxTlvs
- the maximum number of TLV's to read, or -1
to
read all possible TLV's in the given blockprotected void addTlvImpl(Tlv tlv)
tlv
- a TLV to add to this chainpublic boolean hasTlv(int type)
TlvChain
true
if this TLV chain contains any TLV's of the
given TLV type.
hasTlv
in interface TlvChain
type
- a TLV type
public Tlv[] getTlvs()
TlvChain
getTlvs
in interface TlvChain
public java.util.Iterator iterator()
TlvChain
iterator
in interface TlvChain
public int getTlvCount()
TlvChain
getTlvCount
in interface TlvChain
public Tlv getFirstTlv(int type)
TlvChain
null
of TLV of the given type is present.
getFirstTlv
in interface TlvChain
type
- the type of TLV whose first match will be returned
null
if none was foundpublic Tlv getLastTlv(int type)
TlvChain
null
of TLV of the given type is present.
getLastTlv
in interface TlvChain
type
- the type of TLV whose last match will be returned
null
if none was foundpublic Tlv[] getTlvs(int type)
TlvChain
null
.
getTlvs
in interface TlvChain
type
- the type of TLV whose matching TLV's will be returned
public java.lang.String getString(int type)
TlvChain
null
if no TLV with the given type
is present in this chain. Equivalent to chain.hasTlv(type) ?
chain.getLastTlv(type).getDataAsString() : null
.
getString
in interface TlvChain
type
- the type of TLV whose ASCII string value will be returned
TlvChain.getLastTlv(int)
,
Tlv.getDataAsString()
public java.lang.String getString(int type, java.lang.String charset)
TlvChain
null
if no TLV with the given type is present in this chain. Note that if the
given charset is not found in this JVM, a valid charset will be derived
(like converting "unicode-2.0" to "UTF-16BE") or "US-ASCII" will be used.
getString
in interface TlvChain
type
- the type of TLV whose string value will be returnedcharset
- the charset with which the string will be decoded, or
null
to decode as US-ASCII
TlvChain.getLastTlv(int)
public int getUShort(int type)
TlvChain
-1
if
either no TLV of the given type is present in this chain or if the data
block for the TLV contains fewer than two bytes.
getUShort
in interface TlvChain
type
- the type of the TLV whose value will be returned
-1
if none is presentTlvChain.getLastTlv(int)
,
Tlv.getDataAsUShort()
public long getUInt(int type)
TlvChain
-1
if
either no TLV of the given type is present in this chain or if the data
block for the TLV contains fewer than two bytes.
getUInt
in interface TlvChain
type
- the type of the TLV whose value will be returned
-1
if none is presentTlvChain.getLastTlv(int)
,
Tlv.getDataAsUInt()
public int getTotalSize()
TlvChain
-1
if this chain was not read from a stream.
getTotalSize
in interface TlvChain
public 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 occursprotected abstract java.util.List getTlvList()
protected abstract java.util.Map getTlvMap()
Integer
s) to TLV lists (as
List
s). The list should contain all TLV's of the given TLV
type that exist in this TLV chain, in the same order as they appear in
the full list.
protected java.util.List createSiblingList()
List
to serve as a value for the TLV map. The default implementation returns a
LinkedList
.
public java.lang.String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |