public interface BytesCommon
Modifier and Type | Method and Description |
---|---|
void |
alignPositionAddr(int alignment)
Align the position address to a power of 2.
|
ByteOrder |
byteOrder() |
long |
capacity() |
void |
checkEndOfBuffer() |
Bytes |
clear()
Clears this buffer.
|
void |
finish()
Mark the end of the message if writing and check we are at the end of the message if reading.
|
Bytes |
flip()
Flips this buffer.
|
InputStream |
inputStream() |
boolean |
isFinished() |
long |
limit() |
Bytes |
limit(long limit) |
Bytes |
load()
Access every page to ensure those pages are in memory.
|
ObjectSerializer |
objectSerializer() |
OutputStream |
outputStream() |
long |
position() |
Bytes |
position(long position) |
long |
remaining() |
Bytes |
slice()
Creates a new bytes whose content is a shared subsequence of this bytes'
content.
|
Bytes |
slice(long offset,
long length)
Creates a new bytes whose content is a shared subsequence of this bytes'
content.
|
ByteBuffer |
sliceAsByteBuffer(ByteBuffer toReuse)
Returns a
ByteBuffer whose content is a shared subsequence of this bytes' content. |
String |
toDebugString() |
String |
toDebugString(long limit) |
String |
toHexString(long limit) |
void |
toString(Appendable sb,
long start,
long position,
long end)
Write a portion of the Bytes to an Appendable for printing.
|
long position()
Bytes position(long position) throws IllegalArgumentException
position
- to skip toIllegalArgumentException
- if positions < 0 || position >= limitlong limit()
Bytes limit(long limit)
limit
- the new limit which must be >= capacity()long capacity()
long remaining()
void finish() throws IndexOutOfBoundsException
IndexOutOfBoundsException
- if too much data was written.boolean isFinished()
Bytes clear()
Invoke this method before using a sequence of channel-read or put operations to fill this buffer. For example:
buf.clear(); // Prepare buffer for reading
in.read(buf); // Read data
This method does not actually erase the data in the buffer, but it is named as if it did because it will most often be used in situations in which that might as well be the case.
Bytes flip()
After a sequence of channel-read or put operations, invoke this method to prepare for a sequence of channel-write or relative get operations. For example:
buf.put(magic); // Prepend header
in.read(buf); // Read data into rest of buffer
buf.flip(); // Flip buffer
out.write(buf); // Write header + data to channel
This method is often used in conjunction with the compact
method when transferring data from
one place to another.
@NotNull InputStream inputStream()
@NotNull OutputStream outputStream()
@NotNull ObjectSerializer objectSerializer()
void checkEndOfBuffer() throws IndexOutOfBoundsException
IndexOutOfBoundsException
- if the bounds of the Bytes has been exceeded.Bytes load()
void toString(Appendable sb, long start, long position, long end)
sb
- to append tostart
- first byteposition
- where to place a cursor or 0 = none.end
- last byte to append.void alignPositionAddr(int alignment)
alignment
- power of 2 to align to.Bytes slice()
The content of the new bytes will start at this bytes' current position. Changes to this bytes' content will be visible in the new bytes, and vice versa; the two bytes' position and limit values will be independent.
The new bytes' position will be zero, its capacity and its limit will be the number of bytes remaining in this bytes.
slice()
is equivalent of slice(0, remaining())
.
slice(long, long)
ByteBuffer sliceAsByteBuffer(@Nullable ByteBuffer toReuse)
ByteBuffer
whose content is a shared subsequence of this bytes' content.
The content of the returned ByteBuffer
will start at this bytes' current
position. Changes to this bytes' content will be visible in the returned ByteBuffer
,
and vice versa; this bytes' and the returned ByteBuffer
's position and limit values
will be independent.
The returned ByteBuffer
's position will be zero, its capacity and its limit
will be the number of bytes remaining in this bytes.
If this bytes object is able to reuse to given toReuse
ByteBuffer
, it will
be reused and returned back from this method, otherwise a new ByteBuffer
instance
is created and returned.
toReuse
- a ByteBuffer
to reuseByteBuffer
view of this Bytes
slice()
,
ByteBuffer.slice()
Bytes slice(long offset, long length)
The content of the new bytes will start at this bytes' current
position()
+ offset
. Changes to this bytes' content
will be visible in the new bytes, and vice versa; the two bytes'
position and limit values will be independent.
The new bytes' position will be zero, its capacity and its limit
will be equal to length
.
offset
can be negative (if current bytes' position is positive)
and length
can run out of current bytes' limit, the restriction
is that new bytes' should be within this bytes' absolute bounds.
offset
- relative offset of the new bytes from the current bytes'
positionlength
- capacity of the new bytesslice()
String toDebugString(long limit)
String toHexString(long limit)
Copyright © 2019. All rights reserved.