Package org.apache.johnzon.core
Class Snippet.Buffer
- java.lang.Object
-
- org.apache.johnzon.core.Snippet.Buffer
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Enclosing class:
- Snippet
private class Snippet.Buffer extends Object implements Closeable
There are several buffers involved in the creation of a json string. This class carefully manages them all. JsonGeneratorImpl with a 64k buffer (by default) ObjectStreamWriter with an 8k buffer SnippetOutputStream with a buffer of maxSnippetLength As we create json via calling the JsonGenerator it is critical we flush the work in progress all the way through these buffers and into the final SnippetOutputStream buffer. If we do not, we risk creating up to 64k of json when we may only need 50 bytes. We could potentially optimize this code so the buffer held by JsonGeneratorImpl is also the maxSnippetLength.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
Snippet.Buffer.SnippetWriter
Specialized Writer with three internal states: Writing, Completed, Truncated.
-
Field Summary
Fields Modifier and Type Field Description private jakarta.json.stream.JsonGenerator
generator
private Snippet.Buffer.SnippetWriter
snippet
-
Constructor Summary
Constructors Modifier Constructor Description private
Buffer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
private String
get()
private boolean
terminate()
private void
write(jakarta.json.JsonArray array)
private void
write(jakarta.json.JsonObject object)
private void
write(jakarta.json.JsonValue value)
private void
write(String name, jakarta.json.JsonValue value)
-
-
-
Field Detail
-
generator
private final jakarta.json.stream.JsonGenerator generator
-
snippet
private final Snippet.Buffer.SnippetWriter snippet
-
-
Method Detail
-
write
private void write(jakarta.json.JsonValue value)
-
write
private void write(jakarta.json.JsonArray array)
-
write
private void write(jakarta.json.JsonObject object)
-
write
private void write(String name, jakarta.json.JsonValue value)
-
terminate
private boolean terminate()
-
get
private String get()
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
-