Package org.apache.calcite.avatica.util
Class UnsynchronizedBuffer
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.calcite.avatica.util.UnsynchronizedBuffer
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class UnsynchronizedBuffer extends java.io.OutputStreamA utility class for reading and writing bytes to byte buffers without synchronization. A reduced variant taken from Apache Accumulo. This class is not thread-safe by design. It is up to the caller to guarantee mutual exclusion as necessary.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) byte[]data(package private) intinitialCapacityprivate static intLARGE_BUFFER_SIZE(package private) intoffset
-
Constructor Summary
Constructors Constructor Description UnsynchronizedBuffer()Creates a new writer.UnsynchronizedBuffer(int initialCapacity)Creates a new writer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetOffset()longgetSize()static intnextArraySize(int i)Determines what next array size should be by rounding up to next power of two.private voidreserve(int l)voidreset()Resets the internal pointer into the buffer.byte[]toArray()Gets (a copy of) the contents of this writer's buffer.voidwrite(byte[] bytes, int off, int length)Adds bytes to this writer's buffer.voidwrite(int b)
-
-
-
Field Detail
-
LARGE_BUFFER_SIZE
private static final int LARGE_BUFFER_SIZE
- See Also:
- Constant Field Values
-
initialCapacity
final int initialCapacity
-
offset
int offset
-
data
byte[] data
-
-
Method Detail
-
reserve
private void reserve(int l)
-
write
public void write(byte[] bytes, int off, int length)Adds bytes to this writer's buffer.- Overrides:
writein classjava.io.OutputStream- Parameters:
bytes- byte arrayoff- offset into array to start copying byteslength- number of bytes to add- Throws:
java.lang.IndexOutOfBoundsException- if off or length are invalid
-
write
public void write(int b) throws java.io.IOException- Specified by:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
toArray
public byte[] toArray()
Gets (a copy of) the contents of this writer's buffer.- Returns:
- byte buffer contents
-
reset
public void reset()
Resets the internal pointer into the buffer.
-
getOffset
public int getOffset()
- Returns:
- The current offset into the backing array.
-
getSize
public long getSize()
- Returns:
- The current length of the backing array.
-
nextArraySize
public static int nextArraySize(int i)
Determines what next array size should be by rounding up to next power of two.- Parameters:
i- current array size- Returns:
- next array size
- Throws:
java.lang.IllegalArgumentException- if i is negative
-
-