public class ByteFifoBuffer extends Object
Modifier and Type | Field and Description |
---|---|
private byte[] |
array
Backing byte array
|
private int |
buffered
Stored bytes count
|
private int |
read_pos
Current read position
|
private int |
write_pos
Current write position
|
Constructor and Description |
---|
ByteFifoBuffer(int len)
Creates buffer of specified size
|
Modifier and Type | Method and Description |
---|---|
private void |
assertWriteLimit(int newWrPos)
Checks if new write position is correct
|
void |
consumeReadData(int count)
Aligns current read position by count
|
void |
consumeWriteBuffer(int count)
Advances current buffer's write position by count bytes
|
int |
getBuffered() |
int |
getWriteRemaining() |
int |
length() |
int |
read(byte[] out_buffer,
int count)
Reads count bytes into out_buffer.
|
int |
read(byte[] out_buffer,
int buff_offset,
int count)
Read with buffer offset
|
private int |
readLimit(int desiredReadCount)
Limits desiredReadCount to count that is actually available
|
int |
readOffset(byte[] dst_buff,
int dst_buff_offset,
int count,
int offset)
Reads count bytes from buffer without storing new read position
|
private static void |
readOp(byte[] outBuffer,
int dst_buff_offset,
int count,
byte[] srcBuffer,
int read_pos,
int buff_len)
Utility method used for read operations
|
void |
resetReadPosition() |
void |
resetWritePosition() |
boolean |
setCapacity(int new_size)
Sets new buffer's capacity
|
int |
write(byte[] buffer,
int count)
Writes count of bytes from the buffer
|
int |
write(byte[] data,
int offset,
int count)
Writes data into the buffer.
|
private int |
writeLimit(int desiredWriteCount)
Limits desiredWriteCount to what's actually available
|
int |
writeOffset(byte[] data,
int count,
int nOffset)
Writes count bytes from data to the buffer without
affecting buffer's write position
|
private static void |
writeOp(byte[] inBuffer,
int inOffset,
int count,
byte[] outBuffer,
int write_pos,
int buff_len)
Utility method for write operations
|
private byte[] array
private int write_pos
private int buffered
private int read_pos
public ByteFifoBuffer(int len)
len
- buffer's sizepublic int length()
public int read(byte[] out_buffer, int count)
out_buffer
- read count bytes into this buffercount
- number of bytes to read into the out_bufferpublic int read(byte[] out_buffer, int buff_offset, int count)
out_buffer
- read count bytes into this bufferbuff_offset
- offset where to start writing into out_buffercount
- bytes to readprivate int readLimit(int desiredReadCount)
desiredReadCount
- desired amount of bytes to readprivate static void readOp(byte[] outBuffer, int dst_buff_offset, int count, byte[] srcBuffer, int read_pos, int buff_len)
outBuffer
- dst_buff_offset
- count
- srcBuffer
- read_pos
- buff_len
- public int getWriteRemaining()
public int getBuffered()
public int write(byte[] buffer, int count)
buffer
- data to write into the buffercount
- number of bytes to read from the bufferpublic int write(byte[] data, int offset, int count)
data
- source dataoffset
- source buffer's offsetcount
- number of bytes to read from the bufferprivate static void writeOp(byte[] inBuffer, int inOffset, int count, byte[] outBuffer, int write_pos, int buff_len)
inBuffer
- inOffset
- count
- outBuffer
- write_pos
- buff_len
- private int writeLimit(int desiredWriteCount)
desiredWriteCount
- private void assertWriteLimit(int newWrPos) throws IllegalArgumentException
newWrPos
- new write positionIllegalArgumentException
public void consumeWriteBuffer(int count) throws IllegalArgumentException, BufferOverflowException
count
- number of bytes to move forwardIllegalArgumentException
BufferOverflowException
public boolean setCapacity(int new_size)
new_size
- number of bytespublic void consumeReadData(int count) throws IllegalArgumentException, BufferUnderflowException
count
- number of bytes to move the read positionBufferUnderflowException
- if new position exceeds buffered data
countIllegalArgumentException
public int readOffset(byte[] dst_buff, int dst_buff_offset, int count, int offset)
dst_buff
- buffer to write the read data todst_buff_offset
- offset of destination buffercount
- bytes to readoffset
- from current read positionpublic int writeOffset(byte[] data, int count, int nOffset) throws BufferOverflowException
data
- the data to write to the buffercount
- number of bytes to read from datanOffset
- from buffer's write positionBufferOverflowException
public void resetReadPosition()
public void resetWritePosition()
Copyright © 2018. All rights reserved.