Package org.scijava.io
Interface ByteBank
-
- All Known Implementing Classes:
ByteArrayByteBank,ByteBufferByteBank
public interface ByteBankAByteBankis a self-growing buffer over arbitrary bytes.- Author:
- Gabriel Einsdorf, Curtis Rueden
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidappendBytes(byte[] bytes, int length)Appends the given bytes to the bufferdefault voidappendBytes(byte[] bytes, int offset, int length)Appends the given bytes to the bufferdefault voidbasicRangeCheck(long start, long end)Ensures that the requested range satisfies basic sanity criteria.default voidcheckReadPos(long start, long end)Check if we can read from the specified rangedefault voidcheckWritePos(long start, long end)Check if we can write to the specified rangevoidclear()Clears the bufferbytegetByte(long pos)default intgetBytes(long startPos, byte[] bytes)intgetBytes(long startPos, byte[] bytes, int offset, int length)longgetMaxBufferSize()default booleanisReadOnly()voidsetByte(long pos, byte b)Sets the byte at the given positionvoidsetBytes(long startPos, byte[] bytes, int offset, int length)Sets the bytes starting form the given position to the values form the provided array.longsize()default byte[]toByteArray()Copies this entire buffer into a newly allocated byte array.default byte[]toByteArray(long offset, int len)Copies part of this buffer into a newly allocated byte array.
-
-
-
Method Detail
-
getByte
byte getByte(long pos)
- Parameters:
pos- the position to read from- Returns:
- the byte at the given position
-
getBytes
default int getBytes(long startPos, byte[] bytes)- Parameters:
startPos- the position in the buffer to start reading frombytes- the byte array to read into- Returns:
- the number of bytes read
-
getBytes
int getBytes(long startPos, byte[] bytes, int offset, int length)- Parameters:
startPos- the position in the buffer to start reading frombytes- the byte array to read intooffset- the offset in the bytes arraylength- the number of elements to read into the bytes array- Returns:
- number of bytes read
-
toByteArray
default byte[] toByteArray(long offset, int len)Copies part of this buffer into a newly allocated byte array.- Parameters:
offset- the initial position in the bufferlen- the number of bytes to copy- Returns:
- The newly allocated byte array containing the data.
-
toByteArray
default byte[] toByteArray()
Copies this entire buffer into a newly allocated byte array.- Returns:
- The newly allocated byte array containing the data.
-
setBytes
void setBytes(long startPos, byte[] bytes, int offset, int length)Sets the bytes starting form the given position to the values form the provided array.- Parameters:
startPos- the position in the buffer to start writing frombytes- the byte array to writeoffset- the offset in the bytes arraylength- the number of bytes to read
-
appendBytes
default void appendBytes(byte[] bytes, int length)Appends the given bytes to the buffer- Parameters:
bytes- the array containing the bytes to append to the bufferlength- the number of elements to append from the bytes array
-
appendBytes
default void appendBytes(byte[] bytes, int offset, int length)Appends the given bytes to the buffer- Parameters:
bytes- the array containing the bytes to append to the bufferoffset- the offset in the bytes arraylength- the number of elements to append from the bytes array
-
checkReadPos
default void checkReadPos(long start, long end)Check if we can read from the specified range- Parameters:
start- the start position of the rangeend- the end position of the range
-
checkWritePos
default void checkWritePos(long start, long end)Check if we can write to the specified range- Parameters:
start- the start position of the rangeend- the end position of the range- Throws:
IndexOutOfBoundsException- if
-
basicRangeCheck
default void basicRangeCheck(long start, long end)Ensures that the requested range satisfies basic sanity criteria.- Parameters:
start- the start of the rangeend- the end of the range
-
clear
void clear()
Clears the buffer
-
size
long size()
- Returns:
- the offset which follows the last byte stored in this ByteBank
-
setByte
void setByte(long pos, byte b)Sets the byte at the given position- Parameters:
pos- the positionb- the value to set
-
getMaxBufferSize
long getMaxBufferSize()
- Returns:
- the maximal size of the buffer
-
isReadOnly
default boolean isReadOnly()
- Returns:
- True iff the buffer is read-only.
-
-