Package com.fasterxml.jackson.core.io
Class SegmentedStringWriter
- java.lang.Object
-
- java.io.Writer
-
- com.fasterxml.jackson.core.io.SegmentedStringWriter
-
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
public final class SegmentedStringWriter extends Writer
Efficient alternative toStringWriter, based on using segmented internal buffer. Initial input buffer is also recyclable.This class is most useful when serializing JSON content as a String: if so, instance of this class can be given as the writer to
JsonGenerator.
-
-
Constructor Summary
Constructors Constructor Description SegmentedStringWriter(BufferRecycler br)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Writerappend(char c)Writerappend(CharSequence csq)Writerappend(CharSequence csq, int start, int end)voidclose()voidflush()StringgetAndClear()Main access method that will construct a String that contains all the contents, release all internal buffers we may have, and return result String.voidwrite(char[] cbuf)voidwrite(char[] cbuf, int off, int len)voidwrite(int c)voidwrite(String str)voidwrite(String str, int off, int len)-
Methods inherited from class java.io.Writer
nullWriter
-
-
-
-
Constructor Detail
-
SegmentedStringWriter
public SegmentedStringWriter(BufferRecycler br)
-
-
Method Detail
-
append
public Writer append(char c) throws IOException
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Throws:
IOException
-
append
public Writer append(CharSequence csq) throws IOException
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Throws:
IOException
-
append
public Writer append(CharSequence csq, int start, int end) throws IOException
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Throws:
IOException
-
close
public void close()
-
flush
public void flush()
-
write
public void write(char[] cbuf) throws IOException- Overrides:
writein classWriter- Throws:
IOException
-
write
public void write(char[] cbuf, int off, int len) throws IOException- Specified by:
writein classWriter- Throws:
IOException
-
write
public void write(int c) throws IOException- Overrides:
writein classWriter- Throws:
IOException
-
write
public void write(String str) throws IOException
- Overrides:
writein classWriter- Throws:
IOException
-
write
public void write(String str, int off, int len) throws IOException
- Overrides:
writein classWriter- Throws:
IOException
-
getAndClear
public String getAndClear() throws IOException
Main access method that will construct a String that contains all the contents, release all internal buffers we may have, and return result String. Note that the method is not idempotent -- if called second time, will just return an empty String.- Returns:
- String that contains all aggregated content
- Throws:
IOException- if there are general I/O or parse issues, including if the text is too large, seeStreamReadConstraints.Builder.maxStringLength(int)
-
-