Package de.cardcontact.tlv
Class PrimitiveTLV
- java.lang.Object
-
- de.cardcontact.tlv.TLV
-
- de.cardcontact.tlv.PrimitiveTLV
-
- All Implemented Interfaces:
TreeNode
- Direct Known Subclasses:
CertificateDate,GeneralizedTime,IntegerTLV,ObjectIdentifier,OctetString,PrintableString,PublicKeyReference,SignatureTLV,UTF8String
public class PrimitiveTLV extends TLV
Base class for all primitive TLV objects- Author:
- Andreas Schwier (info@cardcontact.de)
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]value-
Fields inherited from class de.cardcontact.tlv.TLV
alternateLengthFormat, name, tag
-
-
Constructor Summary
Constructors Constructor Description PrimitiveTLV(byte[] buffer)Create a primitive TLV object or structure from binaryPrimitiveTLV(byte[] buffer, int offset)Create a primitive TLV object from binary data in buffer at given offsetPrimitiveTLV(int newTagValue, byte[] newvalue)Create a primitive TLV object with tag given as integer valuePrimitiveTLV(ParseBuffer pb)Create a primitive TLV object from binary in parse bufferPrimitiveTLV(Tag newtag, byte[] newvalue)Create a primitive TLV object with tag and valuePrimitiveTLV(TLV tlv)Copy constructor Initialize with existing PrimitiveTLV object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringdump(int indent)Return dump of primitive TLV object using a given left indentationbooleanequals(java.lang.Object testtlv)Test for equalityTreeNodegetChildAt(int index)Return child at index - No childs for PrimitiveTLVintgetChildCount()Return number of childs, of object is constructedjava.util.DategetDate()Return value as dateintgetIndex(TreeNode child)Return index of child - No childs for PrimitiveTLVintgetLength()Return length of value fieldTreeNodegetParent()Return parent - This we don't knowbyte[]getValue()Return the valueinthashCode()booleanisLeaf()Return trueprotected inttoByteArray(byte[] buffer, int offset)Store primitive object to binary bufferjava.lang.StringtoString()Return Tag of TLV object as stringprotected intvalueToByteArray(byte[] buffer, int offset)Store value in binary buffer-
Methods inherited from class de.cardcontact.tlv.TLV
dump, dumpSingleLine, factory, factory, factory, getBytes, getLengthFieldAsByteArray, getLengthFieldSize, getLengthFieldSizeHelper, getName, getSize, getTag, lengthFromByteArray, lengthToByteArray, setName, setTag, useAlternateLengthEncoding
-
-
-
-
Constructor Detail
-
PrimitiveTLV
public PrimitiveTLV(Tag newtag, byte[] newvalue)
Create a primitive TLV object with tag and value- Parameters:
newtag- Tag as objectnewvalue- Byte array containing value
-
PrimitiveTLV
public PrimitiveTLV(int newTagValue, byte[] newvalue) throws TLVEncodingExceptionCreate a primitive TLV object with tag given as integer value- Parameters:
newTagValue- Tag as integer valuenewvalue- Byte array containing value- Throws:
TLVEncodingException
-
PrimitiveTLV
public PrimitiveTLV(byte[] buffer, int offset) throws TLVEncodingExceptionCreate a primitive TLV object from binary data in buffer at given offset- Parameters:
buffer- Buffer containing TLV objectoffset- Offset in buffer- Throws:
TLVEncodingException
-
PrimitiveTLV
public PrimitiveTLV(byte[] buffer) throws TLVEncodingExceptionCreate a primitive TLV object or structure from binary- Parameters:
buffer- Binary data containing TLV structure- Throws:
TLVEncodingException
-
PrimitiveTLV
public PrimitiveTLV(ParseBuffer pb) throws TLVEncodingException
Create a primitive TLV object from binary in parse buffer- Parameters:
pb- Binary data containing TLV structure- Throws:
TLVEncodingException
-
PrimitiveTLV
public PrimitiveTLV(TLV tlv) throws TLVEncodingException
Copy constructor Initialize with existing PrimitiveTLV object. Does not perform a deep copy. The tag and value are reassigned. Caution: If applied to a TLV object embedded in a complex structure remember to update the reference to this object in the parent node.- Parameters:
tlv- PrimitiveTLV- Throws:
java.lang.UnsupportedOperationExceptionTLVEncodingException
-
-
Method Detail
-
valueToByteArray
protected int valueToByteArray(byte[] buffer, int offset)Store value in binary buffer- Specified by:
valueToByteArrayin classTLV- Parameters:
buffer- Byte array that received the binary dataoffset- Offset in byte array- Returns:
- New offset behind the stored object
-
toByteArray
protected int toByteArray(byte[] buffer, int offset)Store primitive object to binary buffer- Specified by:
toByteArrayin classTLV- Parameters:
buffer- Byte array that received the binary dataoffset- Offset in byte array- Returns:
- New offset behind the stored object
-
getLength
public int getLength()
Return length of value field
-
getValue
public byte[] getValue()
Return the value
-
getDate
public java.util.Date getDate() throws java.io.UnsupportedEncodingExceptionReturn value as date- Returns:
- Date
- Throws:
java.io.UnsupportedEncodingException
-
equals
public boolean equals(java.lang.Object testtlv)
Test for equality- Overrides:
equalsin classjava.lang.Object- Parameters:
testtlv- Object to test for- Returns:
- True if values are equal
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
dump
public java.lang.String dump(int indent)
Return dump of primitive TLV object using a given left indentation
-
toString
public java.lang.String toString()
Return Tag of TLV object as string
-
getChildCount
public int getChildCount()
Return number of childs, of object is constructed- Returns:
- Number of childs
- See Also:
TreeNode.getChildCount()
-
isLeaf
public boolean isLeaf()
Return true- Returns:
- Node is leaf node
- See Also:
TreeNode.isLeaf()
-
getParent
public TreeNode getParent()
Return parent - This we don't know- Returns:
- Parent or null if root or unknown
- See Also:
TreeNode.getParent()
-
getChildAt
public TreeNode getChildAt(int index)
Return child at index - No childs for PrimitiveTLV- Returns:
- Child node
- See Also:
TreeNode.getChildAt(int)
-
getIndex
public int getIndex(TreeNode child)
Return index of child - No childs for PrimitiveTLV- Parameters:
child- to look for- Returns:
- Child index or -1
- See Also:
TreeNode.getIndex(de.cardcontact.tlv.TreeNode)
-
-