Class Buffer.UnsafeCursor
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()final longexpandBuffer(int minByteCount) Grow the buffer by adding a contiguous range of capacity in a single segment.intnext()Seeks to the next range of bytes, advancing the offset byend - start.longresizeBuffer(long newSize) Change the size of the buffer so that it equalsnewSizeby either adding new capacity at the end or truncating the buffer at the end.intseek(long offset) Reposition the cursor so that the data atoffsetis readable atdata[start].
-
Field Details
-
buffer
-
readWrite
public boolean readWrite -
offset
public long offset -
data
public byte[] data -
start
public int start -
end
public int end
-
-
Constructor Details
-
UnsafeCursor
public UnsafeCursor()
-
-
Method Details
-
next
public int next()Seeks to the next range of bytes, advancing the offset byend - start. Returns the size of the readable range (at least 1), or -1 if we have reached the end of the buffer and there are no more bytes to read. -
seek
public int seek(long offset) Reposition the cursor so that the data atoffsetis readable atdata[start]. Returns the number of bytes readable indata(at least 1), or -1 if there are no data to read. -
resizeBuffer
public long resizeBuffer(long newSize) Change the size of the buffer so that it equalsnewSizeby either adding new capacity at the end or truncating the buffer at the end. Newly added capacity may span multiple segments.As a side-effect this cursor will
seek. If the buffer is being enlarged it will moveoffsetto the first byte of newly-added capacity. This is the size of the buffer prior to theresizeBuffer()call. If the buffer is being shrunk it will moveoffsetto the end of the buffer.Warning: it is the caller’s responsibility to write new data to every byte of the newly-allocated capacity. Failure to do so may cause serious security problems as the data in the returned buffers is not zero filled. Buffers may contain dirty pooled segments that hold very sensitive data from other parts of the current process.
- Returns:
- the previous size of the buffer.
-
expandBuffer
public final long expandBuffer(int minByteCount) Grow the buffer by adding a contiguous range of capacity in a single segment. This adds at leastminByteCountbytes but may add up to a full segment of additional capacity.As a side-effect this cursor will
seek. It will moveoffsetto the first byte of newly-added capacity. This is the size of the buffer prior to theexpandBuffer()call.If
minByteCountbytes are available in the buffer's current tail segment that will be used; otherwise another segment will be allocated and appended. In either case this returns the number of bytes of capacity added to this buffer.Warning: it is the caller’s responsibility to either write new data to every byte of the newly-allocated capacity, or to
shrinkthe buffer to the data written. Failure to do so may cause serious security problems as the data in the returned buffers is not zero filled. Buffers may contain dirty pooled segments that hold very sensitive data from other parts of the current process.- Parameters:
minByteCount- the size of the contiguous capacity. Must be positive and not greater than the capacity size of a single segment (8 KiB).- Returns:
- the number of bytes expanded by. Not less than
minByteCount.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-