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.String
dump(int indent)
Return dump of primitive TLV object using a given left indentationboolean
equals(java.lang.Object testtlv)
Test for equalityTreeNode
getChildAt(int index)
Return child at index - No childs for PrimitiveTLVint
getChildCount()
Return number of childs, of object is constructedjava.util.Date
getDate()
Return value as dateint
getIndex(TreeNode child)
Return index of child - No childs for PrimitiveTLVint
getLength()
Return length of value fieldTreeNode
getParent()
Return parent - This we don't knowbyte[]
getValue()
Return the valueint
hashCode()
boolean
isLeaf()
Return trueprotected int
toByteArray(byte[] buffer, int offset)
Store primitive object to binary bufferjava.lang.String
toString()
Return Tag of TLV object as stringprotected int
valueToByteArray(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 TLVEncodingException
Create 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 TLVEncodingException
Create 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 TLVEncodingException
Create 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.UnsupportedOperationException
TLVEncodingException
-
-
Method Detail
-
valueToByteArray
protected int valueToByteArray(byte[] buffer, int offset)
Store value in binary buffer- Specified by:
valueToByteArray
in 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:
toByteArray
in 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.UnsupportedEncodingException
Return value as date- Returns:
- Date
- Throws:
java.io.UnsupportedEncodingException
-
equals
public boolean equals(java.lang.Object testtlv)
Test for equality- Overrides:
equals
in classjava.lang.Object
- Parameters:
testtlv
- Object to test for- Returns:
- True if values are equal
-
hashCode
public int hashCode()
- Overrides:
hashCode
in 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)
-
-