Top Description Fields Constructors Methods
tools.jackson.core.io

public final Class SegmentedStringWriter

extends Writer
implements Gettable
Class Inheritance
All Implemented Interfaces
tools.jackson.core.util.BufferRecycler.Gettable
Imports
java.io.*, tools.jackson.core.JacksonException, tools.jackson.core.util.BufferRecycler, .TextBuffer

Efficient alternative to StringWriter, 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.

Field Summary

Modifier and TypeField and Description
private final TextBuffer
Inherited from java.io.Writer:
lock

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Writer
append(char c)

Overrides java.io.Writer.append.

Implements java.lang.Appendable.append.

Appends the specified character to this writer.

public Writer
append(CharSequence csq)

Overrides java.io.Writer.append.

Implements java.lang.Appendable.append.

Appends the specified character sequence to this writer.

public Writer
append(CharSequence csq, int start, int end)

Overrides java.io.Writer.append.

Implements java.lang.Appendable.append.

Appends a subsequence of the specified character sequence to this writer.

public BufferRecycler
public void
close()

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Closes the stream, flushing it first.

public void
flush()

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Flushes the stream.

public String

Returns:

String that contains all aggregated content
getAndClear
()

Main access method that will construct a String that contains all the contents, release all internal buffers we may have, and return result String.

public void
write(char[] cbuf)

Overrides java.io.Writer.write.

Writes an array of characters.

public void
write(char[] cbuf, int off, int len)

Implements abstract java.io.Writer.write.

Writes a portion of an array of characters.

public void
write(int c)

Overrides java.io.Writer.write.

Writes a single character.

public void
write(String str)

Overrides java.io.Writer.write.

Writes a string.

public void
write(String str, int off, int len)

Overrides java.io.Writer.write.

Writes a portion of a string.

Inherited from java.io.Writer:
nullWriter

Field Detail

_bufferback to summary
private final TextBuffer _buffer

Constructor Detail

SegmentedStringWriterback to summary
public SegmentedStringWriter(BufferRecycler br)

Method Detail

appendback to summary
public Writer append(char c) throws JacksonException

Overrides java.io.Writer.append.

Implements java.lang.Appendable.append.

Doc from java.io.Writer.append.

Appends the specified character to this writer.

An invocation of this method of the form out.append(c) behaves in exactly the same way as the invocation

out.write(c)
out.write(c)
Annotations
@Override
appendback to summary
public Writer append(CharSequence csq) throws JacksonException

Overrides java.io.Writer.append.

Implements java.lang.Appendable.append.

Doc from java.io.Writer.append.

Appends the specified character sequence to this writer.

An invocation of this method of the form out.append(csq) when csq is not null, behaves in exactly the same way as the invocation

out.write(csq.toString())
out.write(csq.toString())

Depending on the specification of toString for the character sequence csq, the entire sequence may not be appended. For instance, invoking the toString method of a character buffer will return a subsequence whose content depends upon the buffer's position and limit.

Annotations
@Override
appendback to summary
public Writer append(CharSequence csq, int start, int end) throws JacksonException

Overrides java.io.Writer.append.

Implements java.lang.Appendable.append.

Doc from java.io.Writer.append.

Appends a subsequence of the specified character sequence to this writer.

An invocation of this method of the form out.append(csq, start, end) when csq is not null behaves in exactly the same way as the invocation

out.write(csq.subSequence(start, end).toString())
out.write(csq.subSequence(start, end).toString())
Annotations
@Override
bufferRecyclerback to summary
public BufferRecycler bufferRecycler()

Implements tools.jackson.core.util.BufferRecycler.Gettable.bufferRecycler.

Annotations
@Override
closeback to summary
public void close()

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Doc from java.io.Writer.close.

Closes the stream, flushing it first. Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.

Annotations
@Override
flushback to summary
public void flush()

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Doc from java.io.Writer.flush.

Flushes the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Annotations
@Override
getAndClearback to summary
public String getAndClear() throws JacksonException

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

String that contains all aggregated content

Exceptions
JacksonException:
if there are general I/O or parse issues, including if the text is too large, see tools.jackson.core.StreamReadConstraints.Builder#maxStringLength(int)
writeback to summary
public void write(char[] cbuf) throws JacksonException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes an array of characters.

Annotations
@Override
writeback to summary
public void write(char[] cbuf, int off, int len) throws JacksonException

Implements abstract java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a portion of an array of characters.

Annotations
@Override
writeback to summary
public void write(int c) throws JacksonException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored.

Subclasses that intend to support efficient single-character output should override this method.

Annotations
@Override
writeback to summary
public void write(String str) throws JacksonException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a string.

Annotations
@Override
writeback to summary
public void write(String str, int off, int len) throws JacksonException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a portion of a string.

Annotations
@Override