Package org.apache.ignite.internal.jdbc2
Class JdbcBinaryBuffer
- java.lang.Object
-
- org.apache.ignite.internal.jdbc2.JdbcBinaryBuffer
-
public class JdbcBinaryBuffer extends Object
Buffer storing the binary data.Buffer can start working in read-only mode if created wrapping the existing byte array which can not be modified. Any write operation switches it lazily to the read-write mode. This allows to prevent the unnecessary data copying.
Data may be read via the InputStream API and modified via the OutputStream one. Changes done via OutputStream are visible via the InputStream even if InputStream is created before changes done.
InputStream and OutputStream created remain valid even if the underlying data storage changed from read-only to read-write.
Note however that implementation is not thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description static intMIN_CAPMinimum buffer capacity.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]bytes()Get copy of the buffer data as byte array.protected static intcapacity(int cap, int reqCap)Calculate new capacity.static JdbcBinaryBuffercreateReadOnly(byte[] arr, int off, int len)Create buffer which wraps the existing byte array and start working in the read-only mode.static JdbcBinaryBuffercreateReadWrite()Create empty buffer which starts working in the read-write mode.static JdbcBinaryBuffercreateReadWrite(byte[] arr)Create buffer which takes ownerhip of and wraps data in the existing byte array and starts working in the read-write mode.InputStreaminputStream()Provide InputStream through which the data can be read starting from the begining.JdbcBinaryBuffershallowCopy()Create shallow read-only copy of this buffer.
-
-
-
Field Detail
-
MIN_CAP
public static final int MIN_CAP
Minimum buffer capacity.- See Also:
- Constant Field Values
-
-
Method Detail
-
createReadOnly
public static JdbcBinaryBuffer createReadOnly(byte[] arr, int off, int len)
Create buffer which wraps the existing byte array and start working in the read-only mode.- Parameters:
arr- The byte array to be wrapped.off- The offset to the first byte to be wrapped.len- The length in bytes of the data to be wrapped.
-
createReadWrite
public static JdbcBinaryBuffer createReadWrite(byte[] arr)
Create buffer which takes ownerhip of and wraps data in the existing byte array and starts working in the read-write mode.- Parameters:
arr- The byte array to be wrapped.
-
createReadWrite
public static JdbcBinaryBuffer createReadWrite()
Create empty buffer which starts working in the read-write mode.
-
shallowCopy
public JdbcBinaryBuffer shallowCopy()
Create shallow read-only copy of this buffer.
-
inputStream
public InputStream inputStream()
Provide InputStream through which the data can be read starting from the begining.Stream is not limited meaning that it would return any new data written to the buffer after stream creation.
- Returns:
- InputStream instance.
-
bytes
public byte[] bytes()
Get copy of the buffer data as byte array.- Returns:
- Byte array containing buffer data.
-
capacity
protected static int capacity(int cap, int reqCap)Calculate new capacity.- Parameters:
cap- Current capacity.reqCap- Required new capacity.- Returns:
- New capacity.
-
-