Package de.cardcontact.tlv
Class ParseBuffer
- java.lang.Object
-
- de.cardcontact.tlv.ParseBuffer
-
public class ParseBuffer extends java.lang.Object
Object used to parse binary buffers- Author:
- Andreas Schwier (info@cardcontact.de)
-
-
Constructor Summary
Constructors Constructor Description ParseBuffer(byte[] newBuffer)
Create ParseBuffer to parse entire byte arrayParseBuffer(byte[] newBuffer, int newCursor, int newLength)
Create ParseBuffer using bytes at given range in byte array
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte
get()
Get next byte from parse buffer.ParseBuffer
get(byte[] dst, int offset, int length)
Bulk get from parse buffer Get specified number of bytes from bufferint
getDERLength()
Get DER coded length Values between 0 and 127 are encoded in one byte Values between 128 and 255 are encoded in two bytes Values between 256 and 65535 are encoded in three bytes Values between 65536 and 2^24 - 1 are encoded in four bytes Values between 2^24 and 2^32 - 1 are encoded in five byte For value >= 128 the first byte encoded the number of trailing bytes plus '80'int
getDGILength()
Get DGI coded length Values between 0 and 254 are encoded in one byte Values between 255 and 65535 are encoded in three bytes with the first byte set to 'FF'int
getLimit()
Returns the current upper limit for the parse bufferint
getTag()
Get variable length encoded tag as used in DER/BER encodingint
getUnsignedWord()
Return next two bytes as unsigned integerboolean
hasRemaining()
Return true if bytes are available to parsevoid
mark()
Mark current parser positionint
remaining()
Return number of remaining bytes in parse buffervoid
reset()
Reset current parser position to previously set markvoid
setLength(int newLength)
Set new length of parse region starting at current offset Throws IllegalArgumentException if the length exceed the underlying byte arrayvoid
setLimit(int limit)
Sets the upper limit for the parse buffer
-
-
-
Constructor Detail
-
ParseBuffer
public ParseBuffer(byte[] newBuffer, int newCursor, int newLength)
Create ParseBuffer using bytes at given range in byte array- Parameters:
newBuffer
- Binary arraynewCursor
- Offset in buffer to start atnewLength
- Length of region in buffer to parse
-
ParseBuffer
public ParseBuffer(byte[] newBuffer)
Create ParseBuffer to parse entire byte array- Parameters:
newBuffer
- Binary array
-
-
Method Detail
-
mark
public void mark()
Mark current parser position
-
reset
public void reset()
Reset current parser position to previously set mark
-
remaining
public int remaining()
Return number of remaining bytes in parse buffer- Returns:
- Number of bytes
-
getLimit
public int getLimit()
Returns the current upper limit for the parse buffer- Returns:
- the upper limit
-
setLimit
public void setLimit(int limit) throws TLVEncodingException
Sets the upper limit for the parse buffer- Parameters:
limit
-- Throws:
TLVEncodingException
-
setLength
public void setLength(int newLength) throws TLVEncodingException
Set new length of parse region starting at current offset Throws IllegalArgumentException if the length exceed the underlying byte array- Parameters:
newLength
- New length starting at current offset- Throws:
TLVEncodingException
-
hasRemaining
public boolean hasRemaining()
Return true if bytes are available to parse- Returns:
- true if more bytes are available
-
get
public byte get() throws TLVEncodingException
Get next byte from parse buffer. Advance current position by one.- Returns:
- Byte at current parse position
- Throws:
TLVEncodingException
- End of region reached
-
get
public ParseBuffer get(byte[] dst, int offset, int length) throws TLVEncodingException
Bulk get from parse buffer Get specified number of bytes from buffer- Parameters:
dst
- Receiving bufferoffset
- Offset in receiving bufferlength
- Number of bytes to get- Returns:
- This ParseBuffer object
- Throws:
TLVEncodingException
- Given length exceeds parse region
-
getUnsignedWord
public int getUnsignedWord() throws TLVEncodingException
Return next two bytes as unsigned integer- Returns:
- value of next two byte in MSB/LSB encoding
- Throws:
TLVEncodingException
-
getDGILength
public int getDGILength() throws TLVEncodingException
Get DGI coded length Values between 0 and 254 are encoded in one byte Values between 255 and 65535 are encoded in three bytes with the first byte set to 'FF'- Returns:
- Length
- Throws:
TLVEncodingException
- End of region reached during decoding
-
getDERLength
public int getDERLength() throws TLVEncodingException
Get DER coded length Values between 0 and 127 are encoded in one byte Values between 128 and 255 are encoded in two bytes Values between 256 and 65535 are encoded in three bytes Values between 65536 and 2^24 - 1 are encoded in four bytes Values between 2^24 and 2^32 - 1 are encoded in five byte For value >= 128 the first byte encoded the number of trailing bytes plus '80'- Returns:
- Length or -1 if variable length BER encoding
- Throws:
TLVEncodingException
- End of region reached during decoding
-
getTag
public int getTag() throws TLVEncodingException
Get variable length encoded tag as used in DER/BER encoding- Returns:
- tag value
- Throws:
TLVEncodingException
-
-