Interface InputFile
- All Superinterfaces:
AutoCloseable, Closeable
- All Known Implementing Classes:
S3InputFile
Abstraction for reading Parquet file data.
This interface decouples the read pipeline from memory-mapped local files, enabling alternative backends such as object stores or in-memory buffers.
An InputFile starts in an unopened state. The open() method
must be called before readRange(long, int) or length() can be used.
The framework (Hardwood, ParquetFileReader)
calls open() automatically and takes ownership of the files passed to it:
the reader closes them when it is closed or when opening it fails. Callers
create instances via of(Path) and close only files they have not handed
to a reader. Closeable.close() may be called on a file that was never opened.
Implementations must be safe for concurrent use from multiple threads once opened.
The returned ByteBuffer instances are owned by the caller and may
be slices of a larger mapping or freshly allocated buffers, depending on
the implementation.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionidentity()An identifier of the file's content, which differs for different content, if the backend can supply one without a request of its own; empty when it cannot.longlength()Returns the total size of the file in bytes.name()Returns an identifier for this file, used in log messages and JFR events.static InputFileof(ByteBuffer buffer) Creates anInputFilebacked by an in-memoryByteBuffer.static InputFileCreates an unopenedInputFilefor a local file path.ofBuffers(ByteBuffer first, ByteBuffer... more) CreatesInputFileinstances for the given in-memoryByteBuffers.ofBuffers(List<ByteBuffer> buffers) CreatesInputFileinstances for a list of in-memoryByteBuffers.Creates unopenedInputFileinstances for the given local file paths.Creates unopenedInputFileinstances for a list of local file paths.voidopen()Performs expensive resource acquisition (e.g. memory-mapping, network connect).readRange(long offset, int length) Read a range of bytes from the file.
-
Method Details
-
open
Performs expensive resource acquisition (e.g. memory-mapping, network connect). Must be called beforereadRange(long, int)orlength().- Throws:
IOException- if the resource cannot be acquired
-
readRange
Read a range of bytes from the file.- Parameters:
offset- the byte offset to start reading fromlength- the number of bytes to read- Returns:
- a
ByteBuffercontaining the requested data - Throws:
IOException- if the read failsIllegalStateException- ifopen()has not been calledIndexOutOfBoundsException- if offset or length is out of range
-
length
Returns the total size of the file in bytes.- Returns:
- the file size
- Throws:
IOException- if the size cannot be determinedIllegalStateException- ifopen()has not been called
-
name
String name()Returns an identifier for this file, used in log messages and JFR events.- Returns:
- a human-readable name or path
-
identity
An identifier of the file's content, which differs for different content, if the backend can supply one without a request of its own; empty when it cannot.
Resolved by
open()and fixed for the file's lifetime: it names the content the file was opened against, not the content at its location at the time of the call. AParsedFooterrecords the identity of the file it was read from, and a reader compares the two before using a footer aMetadataSourcesupplied.Backend Identity Local file ( of(Path))the file's size, modification time and file key (or absolute path where the file system has no file keys), read when it is opened; when a reader whose context has no MetadataSourceopened it, read when first asked forS3 the object's ETagIn-memory ( of(ByteBuffer))empty Implement it whenever the backend can supply an identity: a
MetadataSourcethat keys its cache on it can only detect a replaced file through it, and an empty identity turns that detection off. AnInputFilethat wraps another returns the wrapped file's identity. The default implementation returns empty.- Returns:
- the identity, or empty when the backend has none
- Throws:
IOException- if the identity cannot be determinedIllegalStateException- if the implementation resolves its identity inopen()andopen()has not been called
-
of
Creates an
InputFilebacked by an in-memoryByteBuffer.The file is the buffer's remaining content, from its position to its limit, taken when this method is called. The content is not copied, and the buffer's position and limit are not changed; later changes to them do not affect the file. Since the data is already in memory, no resource acquisition is needed and
open()is a no-op.- Parameters:
buffer- the buffer containing Parquet file data between its position and limit- Returns:
- a new InputFile backed by the buffer
-
of
-
ofPaths
-
ofPaths
-
ofBuffers
Creates
InputFileinstances for a list of in-memoryByteBuffers. Each file is its buffer's remaining content, as described inof(ByteBuffer).Since the data is already in memory, no resource acquisition is needed and
open()is a no-op for each instance.- Parameters:
buffers- the buffers containing Parquet file data- Returns:
- a list of new InputFile instances backed by the buffers
-
ofBuffers
Creates
InputFileinstances for the given in-memoryByteBuffers. Each file is its buffer's remaining content, as described inof(ByteBuffer).Since the data is already in memory, no resource acquisition is needed and
open()is a no-op for each instance.- Parameters:
first- the first buffer containing Parquet file datamore- additional buffers containing Parquet file data- Returns:
- a list of new InputFile instances backed by the buffers
-