public class ChunkedOutput extends BufferedOutput
BufferedOutput
using ChunkList
as an output.
Written chunks can be retrieved with getOutput
method.
Subclasses of this implementation can override flush
method to
write composed chunks to an underlying persistence mechanism as soon as they are complete.Modifier and Type | Field and Description |
---|---|
protected static int |
MAX_COPY_BYTES
Maximal number of bytes to copy when making a decision to merge two chunks together
in
writeFromChunk(Chunk, Object) method. |
buffer, EMPTY_BYTE_ARRAY, limit, position, totalPositionBase
Constructor and Description |
---|
ChunkedOutput()
Constructs new chunked output with
default pool. |
ChunkedOutput(ChunkPool pool)
Constructs new chunked output with a specified pool.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears this chunked output and recycles all contained chunks.
|
void |
close()
This implementation does
flush() . |
long |
discard(long n)
Discards n last bytes of output.
|
void |
flush() |
ChunkList |
getOutput(Object owner)
Retrieves generated output chunks for specified owner.
|
protected void |
needSpace()
This method is invoked when output methods need more space to write data.
|
String |
toString()
Returns a string representation of the object.
|
void |
writeAllFromChunkList(ChunkList chunks,
Object owner)
Writes all data from specified chunk list into this buffered output.
|
void |
writeFromChunk(Chunk chunk,
Object owner)
Writes data from specified chunk into this buffered output.
|
checkEOB, totalPosition, write, write, write, writeBoolean, writeByte, writeByteArray, writeBytes, writeChar, writeChars, writeCompactInt, writeCompactLong, writeDouble, writeFloat, writeFromByteBuffer, writeFromDataInput, writeFromInputStream, writeInt, writeLong, writeMarshalled, writeObject, writeShort, writeUTF, writeUTFChar, writeUTFString
protected static final int MAX_COPY_BYTES
writeFromChunk(Chunk, Object)
method.public ChunkedOutput()
default
pool.public ChunkedOutput(ChunkPool pool)
pool
- chunk pool to use for acquiring new chunkspublic void clear()
totalPosition
is reset to 0.public ChunkList getOutput(Object owner)
totalPosition
.owner
- new owner for generated chunk listnull
if there is no output yetpublic void close() throws IOException
flush()
.close
in interface Closeable
close
in interface ObjectOutput
close
in interface AutoCloseable
close
in class OutputStream
IOException
public void flush() throws IOException
Subclasses shall override flush
, call getOutput
from inside it to obtain completed chunks, and write them to an underlying persistence mechanism.
This implementation does nothing.
flush
in interface Flushable
flush
in interface ObjectOutput
flush
in class OutputStream
IOException
public long discard(long n)
n
- the number of bytes to be discardedpublic void writeFromChunk(Chunk chunk, Object owner) throws IOException
read-only
.
A reference to the chunk is considered to become invalid after
invocation of this method and may no longer be used, unless the chunk was read-only.writeFromChunk
in class BufferedOutput
chunk
- the source chunk of bytesowner
- current owner of the chunkIOException
- if an I/O error occurspublic void writeAllFromChunkList(ChunkList chunks, Object owner) throws IOException
read-only
.
A reference to the chunk list is considered to become invalid after
invocation of this method and may no longer be used, unless the chunk list was read-only.writeAllFromChunkList
in class BufferedOutput
chunks
- the source chunk listowner
- current owner of the chunk listIOException
- if an I/O error occursprotected void needSpace() throws IOException
BufferedOutput
(position < limit)
is true or throw an exception. This method may block if needed.
This method is allowed to update BufferedOutput.buffer
, BufferedOutput.position
and
BufferedOutput.limit
fields as needed and should maintain BufferedOutput.totalPositionBase
accordingly.needSpace
in class BufferedOutput
IOException
- if an I/O error occursCopyright © 2002–2025 Devexperts LLC. All rights reserved.