Package io.protostuff
Class WriteSession
java.lang.Object
io.protostuff.WriteSession
- Direct Known Subclasses:
JsonXOutput
,KvpOutput
,ProtobufOutput
,ProtostuffOutput
,XmlXOutput
,YamlOutput
Designed to be subclassed by implementations of
Output
for easier serialization code for streaming or full
buffering. This is used when objects need to be serialzied/written into a LinkedBuffer
.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal LinkedBuffer
The main/root/head buffer of this write session.final int
The next buffer size used when growing the buffer.final OutputStream
The sink of this buffer.final WriteSink
The sink of this write session.protected int
The actual number of bytes written to the buffer.protected LinkedBuffer
The last buffer of this write session (This points to head if growing not needed). -
Constructor Summary
ConstructorsConstructorDescriptionWriteSession
(LinkedBuffer head) WriteSession
(LinkedBuffer head, int nextBufferSize) WriteSession
(LinkedBuffer head, OutputStream out) WriteSession
(LinkedBuffer head, OutputStream out, WriteSession.FlushHandler flushHandler, int nextBufferSize) -
Method Summary
Modifier and TypeMethodDescriptionclear()
The buffer will be cleared (tail will point to the head) and the size will be reset to zero.protected int
flush
(byte[] buf, int offset, int len) protected int
flush
(byte[] buf, int offset, int len, byte[] next, int nextoffset, int nextlen) protected int
flush
(LinkedBuffer lb, byte[] buf, int offset, int len) final int
getSize()
Returns the amount of bytes written in this session.void
reset()
Resets this session for re-use.final byte[]
Returns a single byte array containg all the contents written to the buffer(s).
-
Field Details
-
head
The main/root/head buffer of this write session. -
tail
The last buffer of this write session (This points to head if growing not needed). -
size
protected int sizeThe actual number of bytes written to the buffer. -
nextBufferSize
public final int nextBufferSizeThe next buffer size used when growing the buffer. -
out
The sink of this buffer. -
flushHandler
-
sink
The sink of this write session.
-
-
Constructor Details
-
WriteSession
-
WriteSession
-
WriteSession
public WriteSession(LinkedBuffer head, OutputStream out, WriteSession.FlushHandler flushHandler, int nextBufferSize) -
WriteSession
-
-
Method Details
-
reset
public void reset()Resets this session for re-use. Meant to be overridden by subclasses that have other state to reset. -
clear
The buffer will be cleared (tail will point to the head) and the size will be reset to zero. -
getSize
public final int getSize()Returns the amount of bytes written in this session. -
toByteArray
public final byte[] toByteArray()Returns a single byte array containg all the contents written to the buffer(s). -
flush
- Throws:
IOException
-
flush
protected int flush(byte[] buf, int offset, int len, byte[] next, int nextoffset, int nextlen) throws IOException - Throws:
IOException
-
flush
- Throws:
IOException
-