Package com.neovisionaries.ws.client
Class ByteArray
java.lang.Object
com.neovisionaries.ws.client.ByteArray
Expandable byte array with byte-basis and bit-basis operations.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
void
clearBit
(int bitIndex) private void
expandBuffer
(int newBufferSize) Expand the size of the internal buffer.byte
get
(int index) Get a byte at the index.boolean
getBit
(int bitIndex) int
getBits
(int bitIndex, int nBits) int
getHuffmanBits
(int bitIndex, int nBits) int
length()
The length of the data.void
put
(byte[] source) Add data at the current position.void
put
(byte[] source, int index, int length) Add data at the current position.void
put
(int data) Add a byte at the current position.void
Add data at the current position.boolean
readBit
(int[] bitIndex) int
readBits
(int[] bitIndex, int nBits) void
setBit
(int bitIndex, boolean bit) void
shrink
(int size) byte[]
toBytes()
Convert to a byte array (byte[]
).byte[]
toBytes
(int beginIndex) byte[]
toBytes
(int beginIndex, int endIndex)
-
Field Details
-
ADDITIONAL_BUFFER_SIZE
private static final int ADDITIONAL_BUFFER_SIZE- See Also:
-
mBuffer
-
mLength
private int mLength
-
-
Constructor Details
-
ByteArray
public ByteArray(int capacity) Constructor with initial capacity.- Parameters:
capacity
- Initial capacity for the internal buffer.
-
ByteArray
public ByteArray(byte[] data) Constructor with initial data. The length of the data is used as the initial capacity of the internal buffer.- Parameters:
data
- Initial data.
-
-
Method Details
-
length
public int length()The length of the data. -
get
Get a byte at the index.- Throws:
IndexOutOfBoundsException
-
expandBuffer
private void expandBuffer(int newBufferSize) Expand the size of the internal buffer. -
put
public void put(int data) Add a byte at the current position. -
put
public void put(byte[] source) Add data at the current position.- Parameters:
source
- Source data.
-
put
public void put(byte[] source, int index, int length) Add data at the current position.- Parameters:
source
- Source data.index
- The index in the source data. Data from the index is copied.length
- The length of data to copy.
-
put
Add data at the current position.- Parameters:
source
- Source data.index
- The index in the source data. Data from the index is copied.length
- The length of data to copy.
-
toBytes
public byte[] toBytes()Convert to a byte array (byte[]
). -
toBytes
public byte[] toBytes(int beginIndex) -
toBytes
public byte[] toBytes(int beginIndex, int endIndex) -
clear
public void clear() -
shrink
public void shrink(int size) -
getBit
public boolean getBit(int bitIndex) -
getBits
public int getBits(int bitIndex, int nBits) -
getHuffmanBits
public int getHuffmanBits(int bitIndex, int nBits) -
readBit
public boolean readBit(int[] bitIndex) -
readBits
public int readBits(int[] bitIndex, int nBits) -
setBit
public void setBit(int bitIndex, boolean bit) -
clearBit
public void clearBit(int bitIndex)
-