Package org.apache.johnzon.core
Class Snippet.Buffer.SnippetWriter
- java.lang.Object
-
- java.io.Writer
-
- org.apache.johnzon.core.Snippet.PassthroughWriter
-
- org.apache.johnzon.core.Snippet.Buffer.SnippetWriter
-
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
,Buffered
- Enclosing class:
- Snippet.Buffer
class Snippet.Buffer.SnippetWriter extends Snippet.PassthroughWriter implements Buffered
Specialized Writer with three internal states: Writing, Completed, Truncated. When there is still space left for more json, the state will be Writing If the last write brought is exactly to the end of the max length, the state will be Completed. If the last write brought us over the max length, the state will be Truncated.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
Snippet.Buffer.SnippetWriter.Completed
Signifies the last write was fully written, but there is no more space for future writes.(package private) class
Snippet.Buffer.SnippetWriter.Truncated
Signifies the last write was not completely written and there was no more space for this or future writes.(package private) class
Snippet.Buffer.SnippetWriter.Writing
-
Field Summary
Fields Modifier and Type Field Description private ByteArrayOutputStream
buffer
private int
max
private Snippet.PassthroughWriter
mode
-
Constructor Summary
Constructors Constructor Description SnippetWriter(int max)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
bufferSize()
The buffer size used by this stream while reading input or before writing output to the underlying stream.void
close()
void
flush()
String
get()
boolean
isTruncated()
boolean
terminate()
Calling this method implies the need to continue writing and a question on if that is ok.void
write(char[] cbuf, int off, int len)
-
Methods inherited from class org.apache.johnzon.core.Snippet.PassthroughWriter
append, append, append, write, write, write
-
Methods inherited from class java.io.Writer
nullWriter, write
-
-
-
-
Field Detail
-
buffer
private final ByteArrayOutputStream buffer
-
max
private final int max
-
mode
private Snippet.PassthroughWriter mode
-
-
Method Detail
-
get
public String get()
-
bufferSize
public int bufferSize()
Description copied from interface:Buffered
The buffer size used by this stream while reading input or before writing output to the underlying stream.- Specified by:
bufferSize
in interfaceBuffered
- Returns:
- the size of the buffer
-
terminate
public boolean terminate()
Calling this method implies the need to continue writing and a question on if that is ok. It impacts internal state in the same way as calling a write method.- Returns:
- true if no more writes are possible
-
isTruncated
public boolean isTruncated()
-
write
public void write(char[] cbuf, int off, int len) throws IOException
- Specified by:
write
in classWriter
- Throws:
IOException
-
flush
public void flush() throws IOException
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classSnippet.PassthroughWriter
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classSnippet.PassthroughWriter
- Throws:
IOException
-
-