Class Buffer.UnsafeCursor

java.lang.Object
org.miaixz.bus.core.io.buffer.Buffer.UnsafeCursor
All Implemented Interfaces:
Closeable, AutoCloseable
Enclosing class:
Buffer

public static final class Buffer.UnsafeCursor extends Object implements Closeable
不安全的游标
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    byte[]
     
    int
     
    long
     
    boolean
     
    int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    final long
    expandBuffer(int minByteCount)
    Grow the buffer by adding a contiguous range of capacity in a single segment.
    int
    Seeks to the next range of bytes, advancing the offset by end - start.
    long
    resizeBuffer(long newSize)
    Change the size of the buffer so that it equals newSize by either adding new capacity at the end or truncating the buffer at the end.
    int
    seek(long offset)
    Reposition the cursor so that the data at offset is readable at data[start].

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • buffer

      public Buffer 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 by end - 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 at offset is readable at data[start]. Returns the number of bytes readable in data (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 equals newSize by 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 move offset to the first byte of newly-added capacity. This is the size of the buffer prior to the resizeBuffer() call. If the buffer is being shrunk it will move offset to 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 least minByteCount bytes but may add up to a full segment of additional capacity. As a side-effect this cursor will seek. It will move offset to the first byte of newly-added capacity. This is the size of the buffer prior to the expandBuffer() call. If minByteCount bytes 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 shrink the 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:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable