Package com.arcadedb.database
Class Binary
- java.lang.Object
-
- com.arcadedb.database.Binary
-
- All Implemented Interfaces:
BinaryStructure
,Comparable<Binary>
- Direct Known Subclasses:
TrackableBinary
public class Binary extends Object implements BinaryStructure, Comparable<Binary>
Binary data type. It is backed by Java Byte Buffers.- Author:
- Luca Garulli
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Binary.FetchCallback
-
Field Summary
Fields Modifier and Type Field Description protected int
allocationChunkSize
protected boolean
autoResizable
protected ByteBuffer
buffer
static int
BYTE_SERIALIZED_SIZE
protected byte[]
content
static int
DOUBLE_SERIALIZED_SIZE
protected Binary.FetchCallback
fetchCallback
static int
FLOAT_SERIALIZED_SIZE
static int
INT_SERIALIZED_SIZE
static int
LONG_SERIALIZED_SIZE
static int
SHORT_SERIALIZED_SIZE
protected int
size
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
append(Binary toCopy)
int
capacity()
protected void
checkForAllocation(int offset, int bytesToWrite)
Allocates enough space (max 1 page) and update the size according to the bytes to write.void
clear()
int
compareTo(Binary o)
Binary
copy()
boolean
equals(Object o)
Object
executeInLock(Callable<Object> callable)
void
fetch(Binary.FetchCallback callback)
void
fill(byte filler, int size)
void
flip()
int
getAllocationChunkSize()
byte
getByte()
byte
getByte(int index)
void
getByteArray(byte[] buffer)
void
getByteArray(int index, byte[] buffer)
void
getByteArray(int index, byte[] buffer, int offset, int length)
ByteBuffer
getByteBuffer()
byte[]
getBytes()
byte[]
getBytes(int index)
byte[]
getContent()
int
getContentSize()
int
getInt()
int
getInt(int index)
long
getLong()
long
getLong(int index)
long
getNumber()
long[]
getNumberAndSize(int index)
static int
getNumberSpace(long value)
short
getShort()
short
getShort(int index)
String
getString()
String
getString(int index)
long
getUnsignedNumber()
long[]
getUnsignedNumberAndSize()
short
getUnsignedShort()
int
getVarSize(long value)
int
hashCode()
void
move(int startPosition, int destPosition, int length)
int
position()
void
position(int index)
void
putBuffer(ByteBuffer value)
void
putByte(byte value)
void
putByte(int index, byte value)
void
putByteArray(byte[] value)
void
putByteArray(byte[] value, int length)
void
putByteArray(int index, byte[] value)
void
putByteArray(int index, byte[] value, int length)
int
putBytes(byte[] value)
int
putBytes(byte[] value, int size)
int
putBytes(int index, byte[] value)
void
putInt(int value)
void
putInt(int index, int value)
void
putLong(int index, long value)
void
putLong(long value)
int
putNumber(int index, long value)
int
putNumber(long value)
void
putShort(int index, short value)
void
putShort(short value)
int
putString(int index, String value)
int
putString(String value)
int
putUnsignedNumber(int index, long value)
int
putUnsignedNumber(long value)
int
readFromStream(InputStream is)
byte[]
remainingToByteArray()
void
rewind()
void
setAllocationChunkSize(int allocationChunkSize)
void
setAutoResizable(boolean autoResizable)
int
size()
void
size(int newSize)
Binary
slice()
Creates a copy of this object referring to the same underlying buffer.Binary
slice(int position)
Creates a copy of this object referring to the same underlying buffer, starting from a position.Binary
slice(int position, int length)
Creates a copy of this object referring to the same underlying buffer, starting from a position and with a custom length.byte[]
toByteArray()
String
toString()
-
-
-
Field Detail
-
BYTE_SERIALIZED_SIZE
public static final int BYTE_SERIALIZED_SIZE
- See Also:
- Constant Field Values
-
SHORT_SERIALIZED_SIZE
public static final int SHORT_SERIALIZED_SIZE
- See Also:
- Constant Field Values
-
INT_SERIALIZED_SIZE
public static final int INT_SERIALIZED_SIZE
- See Also:
- Constant Field Values
-
LONG_SERIALIZED_SIZE
public static final int LONG_SERIALIZED_SIZE
- See Also:
- Constant Field Values
-
FLOAT_SERIALIZED_SIZE
public static final int FLOAT_SERIALIZED_SIZE
- See Also:
- Constant Field Values
-
DOUBLE_SERIALIZED_SIZE
public static final int DOUBLE_SERIALIZED_SIZE
- See Also:
- Constant Field Values
-
autoResizable
protected boolean autoResizable
-
content
protected byte[] content
-
buffer
protected ByteBuffer buffer
-
size
protected int size
-
allocationChunkSize
protected int allocationChunkSize
-
fetchCallback
protected Binary.FetchCallback fetchCallback
-
-
Constructor Detail
-
Binary
public Binary()
-
Binary
public Binary(int initialSize)
-
Binary
public Binary(byte[] buffer)
-
Binary
public Binary(byte[] buffer, int contentSize)
-
Binary
public Binary(ByteBuffer buffer)
-
-
Method Detail
-
copy
public Binary copy()
-
clear
public void clear()
-
rewind
public void rewind()
-
setAutoResizable
public void setAutoResizable(boolean autoResizable)
-
getAllocationChunkSize
public int getAllocationChunkSize()
-
setAllocationChunkSize
public void setAllocationChunkSize(int allocationChunkSize)
-
append
public void append(Binary toCopy)
- Specified by:
append
in interfaceBinaryStructure
-
position
public int position()
- Specified by:
position
in interfaceBinaryStructure
-
position
public void position(int index)
- Specified by:
position
in interfaceBinaryStructure
-
putByte
public void putByte(int index, byte value)
- Specified by:
putByte
in interfaceBinaryStructure
-
putByte
public void putByte(byte value)
- Specified by:
putByte
in interfaceBinaryStructure
-
putNumber
public int putNumber(int index, long value)
- Specified by:
putNumber
in interfaceBinaryStructure
-
putNumber
public int putNumber(long value)
- Specified by:
putNumber
in interfaceBinaryStructure
-
putUnsignedNumber
public int putUnsignedNumber(int index, long value)
- Specified by:
putUnsignedNumber
in interfaceBinaryStructure
-
getVarSize
public int getVarSize(long value)
-
putUnsignedNumber
public int putUnsignedNumber(long value)
- Specified by:
putUnsignedNumber
in interfaceBinaryStructure
-
putShort
public void putShort(int index, short value)
- Specified by:
putShort
in interfaceBinaryStructure
-
putShort
public void putShort(short value)
- Specified by:
putShort
in interfaceBinaryStructure
-
putInt
public void putInt(int index, int value)
- Specified by:
putInt
in interfaceBinaryStructure
-
putInt
public void putInt(int value)
- Specified by:
putInt
in interfaceBinaryStructure
-
putLong
public void putLong(int index, long value)
- Specified by:
putLong
in interfaceBinaryStructure
-
putLong
public void putLong(long value)
- Specified by:
putLong
in interfaceBinaryStructure
-
putString
public int putString(int index, String value)
- Specified by:
putString
in interfaceBinaryStructure
-
putString
public int putString(String value)
- Specified by:
putString
in interfaceBinaryStructure
-
putBytes
public int putBytes(int index, byte[] value)
- Specified by:
putBytes
in interfaceBinaryStructure
-
putBytes
public int putBytes(byte[] value)
- Specified by:
putBytes
in interfaceBinaryStructure
-
putBytes
public int putBytes(byte[] value, int size)
- Specified by:
putBytes
in interfaceBinaryStructure
-
putByteArray
public void putByteArray(int index, byte[] value)
- Specified by:
putByteArray
in interfaceBinaryStructure
-
putByteArray
public void putByteArray(int index, byte[] value, int length)
- Specified by:
putByteArray
in interfaceBinaryStructure
-
putByteArray
public void putByteArray(byte[] value)
- Specified by:
putByteArray
in interfaceBinaryStructure
-
putBuffer
public void putBuffer(ByteBuffer value)
- Specified by:
putBuffer
in interfaceBinaryStructure
-
putByteArray
public void putByteArray(byte[] value, int length)
- Specified by:
putByteArray
in interfaceBinaryStructure
-
getByte
public byte getByte(int index)
- Specified by:
getByte
in interfaceBinaryStructure
-
getByte
public byte getByte()
- Specified by:
getByte
in interfaceBinaryStructure
-
getNumberAndSize
public long[] getNumberAndSize(int index)
- Specified by:
getNumberAndSize
in interfaceBinaryStructure
-
getNumber
public long getNumber()
- Specified by:
getNumber
in interfaceBinaryStructure
-
getUnsignedNumber
public long getUnsignedNumber()
- Specified by:
getUnsignedNumber
in interfaceBinaryStructure
-
getUnsignedNumberAndSize
public long[] getUnsignedNumberAndSize()
- Specified by:
getUnsignedNumberAndSize
in interfaceBinaryStructure
-
getShort
public short getShort(int index)
- Specified by:
getShort
in interfaceBinaryStructure
-
getShort
public short getShort()
- Specified by:
getShort
in interfaceBinaryStructure
-
getUnsignedShort
public short getUnsignedShort()
- Specified by:
getUnsignedShort
in interfaceBinaryStructure
-
getInt
public int getInt()
- Specified by:
getInt
in interfaceBinaryStructure
-
getInt
public int getInt(int index)
- Specified by:
getInt
in interfaceBinaryStructure
-
getLong
public long getLong()
- Specified by:
getLong
in interfaceBinaryStructure
-
getLong
public long getLong(int index)
- Specified by:
getLong
in interfaceBinaryStructure
-
getString
public String getString()
- Specified by:
getString
in interfaceBinaryStructure
-
getString
public String getString(int index)
- Specified by:
getString
in interfaceBinaryStructure
-
getByteArray
public void getByteArray(byte[] buffer)
- Specified by:
getByteArray
in interfaceBinaryStructure
-
getByteArray
public void getByteArray(int index, byte[] buffer)
- Specified by:
getByteArray
in interfaceBinaryStructure
-
getByteArray
public void getByteArray(int index, byte[] buffer, int offset, int length)
- Specified by:
getByteArray
in interfaceBinaryStructure
-
getBytes
public byte[] getBytes()
- Specified by:
getBytes
in interfaceBinaryStructure
-
getBytes
public byte[] getBytes(int index)
- Specified by:
getBytes
in interfaceBinaryStructure
-
toByteArray
public byte[] toByteArray()
- Specified by:
toByteArray
in interfaceBinaryStructure
-
remainingToByteArray
public byte[] remainingToByteArray()
- Specified by:
remainingToByteArray
in interfaceBinaryStructure
-
getByteBuffer
public ByteBuffer getByteBuffer()
- Specified by:
getByteBuffer
in interfaceBinaryStructure
-
flip
public void flip()
-
slice
public Binary slice()
Creates a copy of this object referring to the same underlying buffer.- Returns:
- the binary copy
-
slice
public Binary slice(int position)
Creates a copy of this object referring to the same underlying buffer, starting from a position.- Parameters:
position
- the starting position- Returns:
- the binary copy
-
slice
public Binary slice(int position, int length)
Creates a copy of this object referring to the same underlying buffer, starting from a position and with a custom length.- Parameters:
position
- the starting positionlength
- the length- Returns:
- the binary copy
-
size
public int size()
- Specified by:
size
in interfaceBinaryStructure
-
size
public void size(int newSize)
-
move
public void move(int startPosition, int destPosition, int length)
-
getContent
public byte[] getContent()
-
readFromStream
public int readFromStream(InputStream is) throws IOException
- Throws:
IOException
-
getContentSize
public int getContentSize()
-
getNumberSpace
public static int getNumberSpace(long value)
-
checkForAllocation
protected void checkForAllocation(int offset, int bytesToWrite)
Allocates enough space (max 1 page) and update the size according to the bytes to write.- Parameters:
offset
- the offsetbytesToWrite
- number of bytes to write
-
executeInLock
public Object executeInLock(Callable<Object> callable) throws Exception
- Throws:
Exception
-
capacity
public int capacity()
-
fill
public void fill(byte filler, int size)
-
fetch
public void fetch(Binary.FetchCallback callback)
-
compareTo
public int compareTo(Binary o)
- Specified by:
compareTo
in interfaceComparable<Binary>
-
-