|
||||||||||
| 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 Integers) to TLV lists (as
Lists). |
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
data| Method Detail |
protected final void copy(TlvChain chain)
chain - a TLV chain to copy
protected 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)
TlvChaintrue if this TLV chain contains any TLV's of the
given TLV type.
hasTlv in interface TlvChaintype - a TLV type
public Tlv[] getTlvs()
TlvChain
getTlvs in interface TlvChainpublic java.util.Iterator iterator()
TlvChain
iterator in interface TlvChainpublic int getTlvCount()
TlvChain
getTlvCount in interface TlvChainpublic Tlv getFirstTlv(int type)
TlvChainnull of TLV of the given type is present.
getFirstTlv in interface TlvChaintype - the type of TLV whose first match will be returned
null if none was foundpublic Tlv getLastTlv(int type)
TlvChainnull of TLV of the given type is present.
getLastTlv in interface TlvChaintype - the type of TLV whose last match will be returned
null if none was foundpublic Tlv[] getTlvs(int type)
TlvChainnull.
getTlvs in interface TlvChaintype - the type of TLV whose matching TLV's will be returned
public java.lang.String getString(int type)
TlvChainnull 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 TlvChaintype - 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)
TlvChainnull
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 TlvChaintype - 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 TlvChaintype - 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 TlvChaintype - 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 TlvChainpublic long getWritableLength()
Writablewrite. The value returned by this method must not
change after its first invocation.
getWritableLength in interface Writablewrite
public void write(java.io.OutputStream out)
throws java.io.IOException
WritablegetWritableLength.
write in interface Writableout - 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()
Integers) to TLV lists (as
Lists). 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 | |||||||||