Class InMemoryOutputFile
- All Implemented Interfaces:
OutputFile, Closeable, AutoCloseable
An OutputFile that keeps the file in memory and hands it back.
Use it to produce Parquet bytes without a filesystem: a file to upload to an object store,
a payload to send over a network, or one written and read back in the same process. It is
created with OutputFile.inMemory(), and the buffer buffer() returns can be passed
straight to InputFile.of(ByteBuffer):
InMemoryOutputFile out = OutputFile.inMemory();
try (ParquetFileWriter writer = ParquetFileWriter.create(out, schema)) {
// write the file
}
try (ParquetFileReader reader = ParquetFileReader.open(InputFile.of(out.buffer()))) {
// read it back
}
The whole file is held on the heap, which costs the size of the finished file in addition
to the memory the writer uses for the row group it has open. A file can be at most
Integer.MAX_VALUE - 8 bytes; a write past that fails with an IOException.
This API is Experimental: the shape may change in future releases.
-
Method Summary
Modifier and TypeMethodDescriptionbuffer()The file that was written.protected voidReleases the resources and throws away what was written, leaving the destination as if nothing was written.protected voiddoWrite(ByteBuffer data) Appends the remaining bytes ofdata, consuming the buffer.Methods inherited from class AbstractOutputFile
close, create, discard, doClose, doCreate, position, requireClosed, write
-
Method Details
-
doWrite
Description copied from class:AbstractOutputFileAppends the remaining bytes ofdata, consuming the buffer. Returning with bytes left indatamakeswritethrowIllegalStateException, sinceposition()would no longer match the file.- Specified by:
doWritein classAbstractOutputFile- Parameters:
data- the bytes to append- Throws:
IOException- if the write fails
-
doDiscard
protected void doDiscard()Description copied from class:AbstractOutputFileReleases the resources and throws away what was written, leaving the destination as if nothing was written. Releases what it can before it throws, since it is not called again. Does nothing by default.- Overrides:
doDiscardin classAbstractOutputFile
-
buffer
The file that was written.
The returned buffer contains the whole file: its position is
0and its limit is the number of bytes written, which is the rangeInputFile.of(ByteBuffer)reads, so it can be passed there unchanged. Each call returns a buffer with its own position and limit, so reading one buffer does not affect another. Do not modify the buffer's contents: whether a change shows in the buffers other calls return is unspecified.- Returns:
- the bytes of the finished file
- Throws:
IllegalStateException- if the file has not been closed, or was discarded
-