Class OperatorReader

java.lang.Object
org.apache.opendal.NativeObject
org.apache.opendal.OperatorReader
All Implemented Interfaces:
AutoCloseable

public final class OperatorReader extends NativeObject
Reads a file synchronously through a reusable Rust core reader. Each read selects its own range and does not advance a shared cursor. Reader options apply to every request, including streams. A reader does not snapshot the file; changes to the file may be visible to subsequent reads.

Close the reader when it is no longer needed, preferably with try-with-resources. Closing the operator that created it does not close the reader. Calls on one reader are serialized, including close.

See Also:
  • Method Details

    • read

      public byte[] read()
      Reads the whole file into a Java byte array.
      Returns:
      file contents
      Throws:
      OpenDALException - if the file does not exist (NotFound), a condition fails (ConditionNotMatch), or reading fails
      IllegalStateException - if this reader is closed
    • read

      public byte[] read(long offset, long length)
      Reads a byte range into a Java byte array without advancing a shared cursor.
      Parameters:
      offset - non-negative starting byte offset
      length - number of bytes to read, or -1 to read to the end; zero returns an empty array
      Returns:
      contents of the requested range
      Throws:
      OpenDALException - if the range is invalid (RangeNotSatisfied), the file does not exist (NotFound), a condition fails (ConditionNotMatch), or reading fails
      IllegalStateException - if this reader is closed
    • createInputStream

      public OperatorInputStream createInputStream()
      Creates an independent stream over the whole file.
      Returns:
      a stream that the caller must close
      See Also:
    • createInputStream

      public OperatorInputStream createInputStream(long offset, long length)
      Creates a stream over a byte range using this reader's options. Each stream has its own cursor and native resources. Closing this reader does not close its streams, and closing a stream does not close this reader or its other streams.
      Parameters:
      offset - non-negative starting byte offset
      length - number of bytes to read, or -1 to read to the end; zero creates an empty stream
      Returns:
      a stream that the caller must close
      Throws:
      OpenDALException - if the range is invalid (RangeNotSatisfied) or opening the stream fails
      IllegalStateException - if this reader is closed
    • close

      public void close()
      Releases this reader's native resources. Repeated calls have no effect.
      Specified by:
      close in interface AutoCloseable
      Overrides:
      close in class NativeObject
    • disposeInternal

      protected void disposeInternal(long handle)
      Description copied from class: NativeObject
      Deletes underlying native object pointer.
      Specified by:
      disposeInternal in class NativeObject
      Parameters:
      handle - to the native object pointer