Class TinkerByteBuffer
java.lang.Object
org.apache.tinkerpop.gremlin.tinkergraph.structure.storage.TinkerByteBuffer
- All Implemented Interfaces:
Buffer
A self-contained, heap
byte[]-backed implementation of the gremlin-core Buffer abstraction, used to
drive GraphBinaryWriter/GraphBinaryReader without depending on gremlin-util's Netty-backed buffer.
All multi-byte values are big-endian, matching the wire order the Netty implementation uses. The backing array grows
as needed on write. This class is not thread-safe; a buffer is used by a single thread for a single
serialize/deserialize.-
Constructor Summary
ConstructorsConstructorDescriptionTinkerByteBuffer(byte[] data) Wraps an existing array for reading.TinkerByteBuffer(int initialCapacity) -
Method Summary
Modifier and TypeMethodDescriptionintcapacity()Returns the number of bytes (octets) this buffer can contain.getBytes(int index, byte[] dst) Transfers this buffer's data to the specified destination starting at the specified absoluteindex.booleanisDirect()Returnstrueif and only if this buffer is backed by an NIO direct buffer.Marks the current writer index in this buffer.Exposes this buffer's readable bytes as a NIOByteBuffer.nioBuffer(int index, int length) Exposes this buffer's sub-region as an NIOByteBuffer.intReturns the maximum number of NIOByteBuffers that consist this buffer.Exposes this buffer's readable bytes as NIO ByteBuffer's instances.nioBuffers(int index, int length) Exposes this buffer's readable bytes as NIO ByteBuffer's instances.intReturns the number of readable bytes.booleanGets a boolean and advances the reader index.bytereadByte()Gets a byte and advances the reader index.readBytes(byte[] destination) Transfers this buffer's data to the specified destination starting at the current reader index and advances the reader index.readBytes(byte[] destination, int dstIndex, int length) Transfers this buffer's data to the specified destination starting at the current reader index and advances the reader index.readBytes(OutputStream out, int length) Transfers this buffer's data to the specified stream starting at the current reader index and advances the index.readBytes(ByteBuffer dst) Transfers this buffer's data to the specified destination starting at the current reader index until the destination's position reaches its limit, and advances the reader index.doubleGets a 64-bit floating point number and advances the reader index.intReturns the reader index of this buffer.readerIndex(int readerIndex) Sets the reader index of this buffer.floatGets a 32-bit floating point number and advances the reader index.intreadInt()Gets a 32-bit integer at the current index and advances the reader index.longreadLong()Gets a 64-bit integer and advances the reader index.shortGets a 16-bit short integer and advances the reader index.intReturns the reference count of this object.booleanrelease()Decreases the reference count by1and deallocates this object if the reference count reaches at0.Repositions the current writer index to the marked index in this buffer.retain()Increases the reference count by1.byte[]Returns a copy of the readable-region bytes (from reader index to writer index).byte[]Returns a copy of all written bytes (index 0 to writer index).writeBoolean(boolean value) Sets the specified boolean at the current writer index and advances the index.writeByte(int value) Sets the specified byte at the current writer index and advances the index.writeBytes(byte[] src) Transfers the specified source array's data to this buffer starting at the current writer index and advances the index.writeBytes(byte[] src, int srcIndex, int length) Transfers the specified source array's data to this buffer starting at the current writer index and advances the index.writeBytes(ByteBuffer src) Transfers the specified source byte data to this buffer starting at the current writer index and advances the index.writeDouble(double value) Sets the specified 64-bit floating point number at the current writer index and advances the index.writeFloat(float value) Sets the specified 32-bit floating point number at the current writer index and advances the index.writeInt(int value) Sets the specified 32-bit integer at the current writer index and advances the index.writeLong(long value) Sets the specified 64-bit long integer at the current writer index and advances the index.intReturns the writer index of this buffer.writerIndex(int writerIndex) Sets the writer index of this buffer.writeShort(int value) Sets the specified 16-bit short integer at the current writer index and advances the index.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.tinkerpop.gremlin.structure.io.Buffer
hasKnownRemainingLength
-
Constructor Details
-
TinkerByteBuffer
public TinkerByteBuffer() -
TinkerByteBuffer
public TinkerByteBuffer(int initialCapacity) -
TinkerByteBuffer
public TinkerByteBuffer(byte[] data) Wraps an existing array for reading. The writer index is positioned at the end of the supplied data.
-
-
Method Details
-
toReadableArray
public byte[] toReadableArray()Returns a copy of the readable-region bytes (from reader index to writer index). Does not change indexes. -
toWrittenArray
public byte[] toWrittenArray()Returns a copy of all written bytes (index 0 to writer index). Does not change indexes. -
readableBytes
public int readableBytes()Description copied from interface:BufferReturns the number of readable bytes.- Specified by:
readableBytesin interfaceBuffer
-
readerIndex
public int readerIndex()Description copied from interface:BufferReturns the reader index of this buffer.- Specified by:
readerIndexin interfaceBuffer
-
readerIndex
Description copied from interface:BufferSets the reader index of this buffer.- Specified by:
readerIndexin interfaceBuffer
-
writerIndex
public int writerIndex()Description copied from interface:BufferReturns the writer index of this buffer.- Specified by:
writerIndexin interfaceBuffer
-
writerIndex
Description copied from interface:BufferSets the writer index of this buffer.- Specified by:
writerIndexin interfaceBuffer
-
markWriterIndex
Description copied from interface:BufferMarks the current writer index in this buffer.- Specified by:
markWriterIndexin interfaceBuffer
-
resetWriterIndex
Description copied from interface:BufferRepositions the current writer index to the marked index in this buffer.- Specified by:
resetWriterIndexin interfaceBuffer
-
capacity
public int capacity()Description copied from interface:BufferReturns the number of bytes (octets) this buffer can contain. -
isDirect
public boolean isDirect()Description copied from interface:BufferReturnstrueif and only if this buffer is backed by an NIO direct buffer. -
readBoolean
public boolean readBoolean()Description copied from interface:BufferGets a boolean and advances the reader index.- Specified by:
readBooleanin interfaceBuffer
-
readByte
public byte readByte()Description copied from interface:BufferGets a byte and advances the reader index. -
readShort
public short readShort()Description copied from interface:BufferGets a 16-bit short integer and advances the reader index. -
readInt
public int readInt()Description copied from interface:BufferGets a 32-bit integer at the current index and advances the reader index. -
readLong
public long readLong()Description copied from interface:BufferGets a 64-bit integer and advances the reader index. -
readFloat
public float readFloat()Description copied from interface:BufferGets a 32-bit floating point number and advances the reader index. -
readDouble
public double readDouble()Description copied from interface:BufferGets a 64-bit floating point number and advances the reader index.- Specified by:
readDoublein interfaceBuffer
-
readBytes
Description copied from interface:BufferTransfers this buffer's data to the specified destination starting at the current reader index and advances the reader index. -
readBytes
Description copied from interface:BufferTransfers this buffer's data to the specified destination starting at the current reader index and advances the reader index. -
readBytes
Description copied from interface:BufferTransfers this buffer's data to the specified destination starting at the current reader index until the destination's position reaches its limit, and advances the reader index. -
readBytes
Description copied from interface:BufferTransfers this buffer's data to the specified stream starting at the current reader index and advances the index.- Specified by:
readBytesin interfaceBufferlength- the number of bytes to transfer- Throws:
IOException- if the specified stream threw an exception during I/O
-
writeBoolean
Description copied from interface:BufferSets the specified boolean at the current writer index and advances the index.- Specified by:
writeBooleanin interfaceBuffer
-
writeByte
Description copied from interface:BufferSets the specified byte at the current writer index and advances the index. -
writeShort
Description copied from interface:BufferSets the specified 16-bit short integer at the current writer index and advances the index.- Specified by:
writeShortin interfaceBuffer
-
writeInt
Description copied from interface:BufferSets the specified 32-bit integer at the current writer index and advances the index. -
writeLong
Description copied from interface:BufferSets the specified 64-bit long integer at the current writer index and advances the index. -
writeFloat
Description copied from interface:BufferSets the specified 32-bit floating point number at the current writer index and advances the index.- Specified by:
writeFloatin interfaceBuffer
-
writeDouble
Description copied from interface:BufferSets the specified 64-bit floating point number at the current writer index and advances the index.- Specified by:
writeDoublein interfaceBuffer
-
writeBytes
Description copied from interface:BufferTransfers the specified source array's data to this buffer starting at the current writer index and advances the index.- Specified by:
writeBytesin interfaceBuffer
-
writeBytes
Description copied from interface:BufferTransfers the specified source byte data to this buffer starting at the current writer index and advances the index.- Specified by:
writeBytesin interfaceBuffer
-
writeBytes
Description copied from interface:BufferTransfers the specified source array's data to this buffer starting at the current writer index and advances the index.- Specified by:
writeBytesin interfaceBuffer
-
release
public boolean release()Description copied from interface:BufferDecreases the reference count by1and deallocates this object if the reference count reaches at0. -
retain
Description copied from interface:BufferIncreases the reference count by1. -
referenceCount
public int referenceCount()Description copied from interface:BufferReturns the reference count of this object.- Specified by:
referenceCountin interfaceBuffer
-
nioBufferCount
public int nioBufferCount()Description copied from interface:BufferReturns the maximum number of NIOByteBuffers that consist this buffer.- Specified by:
nioBufferCountin interfaceBuffer
-
nioBuffers
Description copied from interface:BufferExposes this buffer's readable bytes as NIO ByteBuffer's instances.- Specified by:
nioBuffersin interfaceBuffer
-
nioBuffers
Description copied from interface:BufferExposes this buffer's readable bytes as NIO ByteBuffer's instances.- Specified by:
nioBuffersin interfaceBuffer
-
nioBuffer
Description copied from interface:BufferExposes this buffer's readable bytes as a NIOByteBuffer. The returned buffer either share or contains the copied content of this buffer, while changing the position and limit of the returned NIO buffer does not affect the indexes and marks of this buffer. -
nioBuffer
Description copied from interface:BufferExposes this buffer's sub-region as an NIOByteBuffer. -
getBytes
Description copied from interface:BufferTransfers this buffer's data to the specified destination starting at the specified absoluteindex. This method does not modify reader or writer indexes.
-