net.kano.joscar.tlv
Class TlvTools

java.lang.Object
  extended byTlvTools

public final class TlvTools
extends java.lang.Object

Provides a set of utilites for working with TLV chains.


Method Summary
static ImmutableTlvChain createChain(Tlv[] tlvs, int offset, int len)
          Creates a new immutable TLV chain with the given number of TLV's starting from the given offset of the given TLV array.
static MutableTlvChain createMutableChain()
          Returns a new empty mutable TLV chain.
static ImmutableTlvChain getImmutableCopy(TlvChain other)
          Returns a copy of the given TLV chain that cannot be modified.
static MutableTlvChain getMutableCopy(TlvChain other)
          Returns a copy of the given TLV chain that can be modified.
static boolean isCompleteTlvChain(ByteBlock block)
          Returns whether the given block might be a valid, complete TLV chain.
static ImmutableTlvChain readChain(ByteBlock block)
          Reads a TLV chain from the given block of TLV's.
static ImmutableTlvChain readChain(ByteBlock block, int maxTlvs)
          Reads a TLV chain from the given block of TLV's, stopping after reading the number of TLV's specified by maxTlvs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

readChain

public static ImmutableTlvChain readChain(ByteBlock block)
Reads a TLV chain from the given block of TLV's. Calling this method is equivalent to calling readChain(block, -1). The total number of bytes read can be read by calling the getTotalSize method of the returned TlvChain.

Parameters:
block - the data block containing zero or more TLV's
Returns:
a TLV chain object containing TLV's read from the given block of data

readChain

public static ImmutableTlvChain readChain(ByteBlock block,
                                          int maxTlvs)
Reads a TLV chain from the given block of TLV's, stopping after reading the number of TLV's specified by maxTlvs. If maxTlvs is -1, all possible TLV's are read. The total number of bytes read can be read by calling the getTotalSize method of the returned TlvChain.

Parameters:
block - block the data block containing zero or more TLV's
maxTlvs - the maximum number of TLV's to read, or -1 to read all possible TLV's in the given block
Returns:
an immutable TLV chain object containing TLV's read from the given block of data

createChain

public static ImmutableTlvChain createChain(Tlv[] tlvs,
                                            int offset,
                                            int len)
Creates a new immutable TLV chain with the given number of TLV's starting from the given offset of the given TLV array. Note that no element of tlvs can be null.

Parameters:
tlvs - the list of (non-null) TLV's
offset - the index of the first TLV that this chain should contain
len - the number of TLV's to include in this chain
Returns:
a TLV chain containing the given number of TLV's starting at the given index of the given array of TLV's

createMutableChain

public static MutableTlvChain createMutableChain()
Returns a new empty mutable TLV chain.

Returns:
a new empty mutable TLV chain

getMutableCopy

public static MutableTlvChain getMutableCopy(TlvChain other)
Returns a copy of the given TLV chain that can be modified. (Modifications to the returned chain will not be reflected in the original chain.)

Parameters:
other - the TLV chain to copy
Returns:
a mutable TLV chain containing the same TLV's as the given chain

getImmutableCopy

public static ImmutableTlvChain getImmutableCopy(TlvChain other)
Returns a copy of the given TLV chain that cannot be modified. (Modifications to the original chain will not be reflected in the returned chain.)

Parameters:
other - the TLV chain to copy
Returns:
an immutable TLV chain containing the same TLV's as the given chain

isCompleteTlvChain

public static boolean isCompleteTlvChain(ByteBlock block)
Returns whether the given block might be a valid, complete TLV chain. A complete TLV chain contains no data after the chain.

Parameters:
block - a block of data that might contain a complete TLV chain
Returns:
whether or not the given block represents a complete TLV chain