Package io.protostuff
Class WriteSession
- java.lang.Object
-
- io.protostuff.WriteSession
-
- Direct Known Subclasses:
JsonXOutput
,KvpOutput
,ProtobufOutput
,ProtostuffOutput
,XmlXOutput
,YamlOutput
public class WriteSession extends java.lang.Object
Designed to be subclassed by implementations ofOutput
for easier serialization code for streaming or full buffering. This is used when objects need to be serialzied/written into aLinkedBuffer
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
WriteSession.FlushHandler
-
Field Summary
Fields Modifier and Type Field Description WriteSession.FlushHandler
flushHandler
LinkedBuffer
head
The main/root/head buffer of this write session.int
nextBufferSize
The next buffer size used when growing the buffer.java.io.OutputStream
out
The sink of this buffer.WriteSink
sink
The sink of this write session.protected int
size
The actual number of bytes written to the buffer.protected LinkedBuffer
tail
The last buffer of this write session (This points to head if growing not needed).
-
Constructor Summary
Constructors Constructor Description WriteSession(LinkedBuffer head)
WriteSession(LinkedBuffer head, int nextBufferSize)
WriteSession(LinkedBuffer head, java.io.OutputStream out)
WriteSession(LinkedBuffer head, java.io.OutputStream out, WriteSession.FlushHandler flushHandler, int nextBufferSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WriteSession
clear()
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)
int
getSize()
Returns the amount of bytes written in this session.void
reset()
Resets this session for re-use.byte[]
toByteArray()
Returns a single byte array containg all the contents written to the buffer(s).
-
-
-
Field Detail
-
head
public final LinkedBuffer head
The main/root/head buffer of this write session.
-
tail
protected LinkedBuffer tail
The last buffer of this write session (This points to head if growing not needed).
-
size
protected int size
The actual number of bytes written to the buffer.
-
nextBufferSize
public final int nextBufferSize
The next buffer size used when growing the buffer.
-
out
public final java.io.OutputStream out
The sink of this buffer.
-
flushHandler
public final WriteSession.FlushHandler flushHandler
-
sink
public final WriteSink sink
The sink of this write session.
-
-
Constructor Detail
-
WriteSession
public WriteSession(LinkedBuffer head)
-
WriteSession
public WriteSession(LinkedBuffer head, int nextBufferSize)
-
WriteSession
public WriteSession(LinkedBuffer head, java.io.OutputStream out, WriteSession.FlushHandler flushHandler, int nextBufferSize)
-
WriteSession
public WriteSession(LinkedBuffer head, java.io.OutputStream out)
-
-
Method Detail
-
reset
public void reset()
Resets this session for re-use. Meant to be overridden by subclasses that have other state to reset.
-
clear
public WriteSession 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
protected int flush(byte[] buf, int offset, int len) throws java.io.IOException
- Throws:
java.io.IOException
-
flush
protected int flush(byte[] buf, int offset, int len, byte[] next, int nextoffset, int nextlen) throws java.io.IOException
- Throws:
java.io.IOException
-
flush
protected int flush(LinkedBuffer lb, byte[] buf, int offset, int len) throws java.io.IOException
- Throws:
java.io.IOException
-
-