Package de.cardcontact.tlv
Class ByteBuffer
- java.lang.Object
-
- de.cardcontact.tlv.ByteBuffer
-
public class ByteBuffer extends java.lang.Object
Implements a mutable byte buffer similar to StringBuffer.- Author:
- Andreas Schwier (info@cardcontact.de)
-
-
Constructor Summary
Constructors Constructor Description ByteBuffer()
Create empty ByteBuffer with initial capacity of 16 bytesByteBuffer(byte[] bytes)
Create ByteBuffer which contains a exact copy of the byte array passed as parameterByteBuffer(int length)
Create empty ByteBuffer with initial capacity as defined by parameter length
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ByteBuffer
append(byte _byte)
Append single byteByteBuffer
append(byte[] bytes)
Append byte arrayByteBuffer
append(ByteBuffer bb)
Append ByteBufferByteBuffer
clear(int offset, int count)
Clear buffer in specified range and move trailing data behind offset + countByteBuffer
copy(int offset, byte[] source)
Copy source into buffer at offsetstatic int
find(byte[] source, byte[] search, int offset)
Search byte arrays for matching search string and return zero based offset.int
find(byte[] search, int offset)
Search ByteBuffer for matching search string and return zero based offset.static int
find(byte[] source, int length, byte[] search, int offset)
Search byte arrays for matching search string and return zero based offset.byte
getByteAt(int offset)
Return byte at zero based offsetbyte[]
getBytes()
Return ByteBuffer as byte arraysbyte[]
getBytes(int offset, int count)
Return part of ByteBuffer as byte arraysByteBuffer
insert(int offset, byte _byte)
Insert byte at offsetByteBuffer
insert(int offset, byte[] bytes)
Insert contents of byte array at offsetByteBuffer
insert(int offset, byte[] bytes, int length)
Insert bytes at offsetByteBuffer
insert(int offset, ByteBuffer bb)
Insert contents of ByteBuffer at offsetint
length()
Return length of ByteBufferjava.lang.String
toString()
Return hexadecimal string for content of ByteBuffer
-
-
-
Constructor Detail
-
ByteBuffer
public ByteBuffer()
Create empty ByteBuffer with initial capacity of 16 bytes
-
ByteBuffer
public ByteBuffer(int length)
Create empty ByteBuffer with initial capacity as defined by parameter length- Parameters:
length
- Initial capacity of ByteBuffer
-
ByteBuffer
public ByteBuffer(byte[] bytes)
Create ByteBuffer which contains a exact copy of the byte array passed as parameter- Parameters:
bytes
- Byte array to create ByteBuffer from
-
-
Method Detail
-
append
public ByteBuffer append(byte _byte)
Append single byte- Parameters:
_byte
-- Returns:
- this
-
append
public ByteBuffer append(byte[] bytes)
Append byte array- Parameters:
bytes
-- Returns:
- this
-
append
public ByteBuffer append(ByteBuffer bb)
Append ByteBuffer- Parameters:
bb
-- Returns:
- this
-
insert
public ByteBuffer insert(int offset, byte[] bytes, int length) throws java.lang.IndexOutOfBoundsException
Insert bytes at offset- Parameters:
offset
-bytes
-length
-- Returns:
- Throws:
java.lang.IndexOutOfBoundsException
-
insert
public ByteBuffer insert(int offset, byte _byte) throws java.lang.IndexOutOfBoundsException
Insert byte at offset- Parameters:
offset
- Position at which to insert the bytes_byte
- Byte to insert- Returns:
- this
- Throws:
java.lang.IndexOutOfBoundsException
- If offset is not in range
-
insert
public ByteBuffer insert(int offset, byte[] bytes) throws java.lang.IndexOutOfBoundsException
Insert contents of byte array at offset- Parameters:
offset
- Position at which to insert the bytesbytes
- Byte array to insert- Returns:
- this
- Throws:
java.lang.IndexOutOfBoundsException
- If offset is not in range
-
insert
public ByteBuffer insert(int offset, ByteBuffer bb) throws java.lang.IndexOutOfBoundsException
Insert contents of ByteBuffer at offset- Parameters:
offset
- Position at which to insert the ByteBufferbb
- ByteBuffer to insert- Returns:
- this
- Throws:
java.lang.IndexOutOfBoundsException
- If offset is not in range
-
length
public int length()
Return length of ByteBuffer- Returns:
- Length of ByteBuffer
-
getByteAt
public byte getByteAt(int offset) throws java.lang.IndexOutOfBoundsException
Return byte at zero based offset- Parameters:
offset
-- Returns:
- byte at offset
- Throws:
java.lang.IndexOutOfBoundsException
-
clear
public ByteBuffer clear(int offset, int count) throws java.lang.IndexOutOfBoundsException
Clear buffer in specified range and move trailing data behind offset + count- Parameters:
offset
-count
-- Returns:
- this
- Throws:
java.lang.IndexOutOfBoundsException
-
copy
public ByteBuffer copy(int offset, byte[] source)
Copy source into buffer at offset- Parameters:
offset
-source
-- Returns:
- this
-
find
public static int find(byte[] source, int length, byte[] search, int offset)
Search byte arrays for matching search string and return zero based offset. Start search at given offset. An empty search string is always found.- Parameters:
source
- Byte array to search inlength
- Range in source to search insearch
- Byte array to search foroffset
- Offset to start at- Returns:
- Zero based offset of match or -1
-
find
public static int find(byte[] source, byte[] search, int offset)
Search byte arrays for matching search string and return zero based offset. Start search at given offset. An empty search string is always found.- Parameters:
source
- Byte array to search insearch
- Byte array to search foroffset
- Offset to start at- Returns:
- Zero based offset of match or -1
-
find
public int find(byte[] search, int offset)
Search ByteBuffer for matching search string and return zero based offset. Start search at given offset. An empty search string is always found.- Parameters:
search
- Byte array to search foroffset
- Offset to start at- Returns:
- Zero based offset of match or -1
-
getBytes
public byte[] getBytes()
Return ByteBuffer as byte arrays- Returns:
- Array of bytes
-
getBytes
public byte[] getBytes(int offset, int count)
Return part of ByteBuffer as byte arrays- Parameters:
offset
- Zero based offset in buffercount
- Number of bytes to extract- Returns:
- Array of bytes
-
toString
public java.lang.String toString()
Return hexadecimal string for content of ByteBuffer- Overrides:
toString
in classjava.lang.Object
- Returns:
- Hexadecimal string
-
-