MultiByteBufferOutputStream

Class name: com.datashyft.core.model.util.MultiByteBufferOutputStream

This class implements an OutputStream in which the data is written either into memory or into a temporary file, depending on the specified size of the data.  The data written to this OutputStream can be retrieved using the toMultiByteBuffer() method.  This method will return a MultiByteBuffer containing all the data written to the MultiByteBufferOutputStream.  The returned buffer will be positioned at the beginning.

public MultiByteBufferOutputStream(long size) throws IOException

Creates a new MultiByteBuffer with an estimated size. If the given size is less than 512kb, this buffer will be created in memory, otherwise it will be created on disk and memory mapped.

It is better, when estimating, to err on the high side - estimating that the size will be 1 MB when it is actually 1 KB is not great for performance, but it is functional.  Estimating that the size is 1kb when it is actually 1MB should also work but will consume excess memory.  Where you can get into trouble is estimating that the size is 1 KB but then writing like 1 GB.  Depending on the size of the Runtime, this can quickly lead to OutOfMemoryErrors.  Fatally, if you estimate 1 KB but write more than Integer.MAX_VALUE (~2GB), the process will outright fail during the write process.

Specifying a size less than 0 will cause the object to store the data on disk. Specifying a size of 0 will cause the object to store the data in memory (under the assumption that there is no data).

Parameters:

size   - The estimated amount of data this OutputStream will have written to it.

Throws:

IOException â€“ If, based on the size estimate, it is determined that the data should be written to disk, but there is insufficient disk space available

public MultiByteBuffer toMultiByteBuffer()

Returns the data written into this OutputStream as a MultiByteBuffer.  The MultiByteBuffer’s position is located at the beginning of the buffer.

Returns:

The data written into this OutputStream as a MultiByteBuffer.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us