Class OperatorReader
java.lang.Object
org.apache.opendal.NativeObject
org.apache.opendal.OperatorReader
- All Implemented Interfaces:
AutoCloseable
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:
-
Field Summary
Fields inherited from class NativeObject
nativeHandle -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Releases this reader's native resources.Creates an independent stream over the whole file.createInputStream(long offset, long length) Creates a stream over a byte range using this reader's options.protected voiddisposeInternal(long handle) Deletes underlying native object pointer.byte[]read()Reads the whole file into a Java byte array.byte[]read(long offset, long length) Reads a byte range into a Java byte array without advancing a shared cursor.Methods inherited from class NativeObject
isDisposed
-
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 failsIllegalStateException- 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 offsetlength- 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 failsIllegalStateException- if this reader is closed
-
createInputStream
Creates an independent stream over the whole file.- Returns:
- a stream that the caller must close
- See Also:
-
createInputStream
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 offsetlength- 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 failsIllegalStateException- if this reader is closed
-
close
public void close()Releases this reader's native resources. Repeated calls have no effect.- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classNativeObject
-
disposeInternal
protected void disposeInternal(long handle) Description copied from class:NativeObjectDeletes underlying native object pointer.- Specified by:
disposeInternalin classNativeObject- Parameters:
handle- to the native object pointer
-