Top Description Inners Fields Constructors Methods
org.eclipse.jetty.io

public abstract Class WriteThroughWriter

extends Writer
Class Inheritance
Known Direct Subclasses
org.eclipse.jetty.io.WriteThroughWriter.Iso88591Writer, org.eclipse.jetty.io.WriteThroughWriter.Utf8Writer, org.eclipse.jetty.io.WriteThroughWriter.EncodingWriter
Imports
java.io.IOException, .OutputStream, .OutputStreamWriter, .Writer, java.nio.CharBuffer, java.nio.charset.Charset, .StandardCharsets, java.util.Objects, org.eclipse.jetty.util.ByteArrayOutputStream2

An alternate to java.io.OutputStreamWriter that supports several optimized implementation for well known Charsets, specifically StandardCharsets#UTF_8 and StandardCharsets#ISO_8859_1.

The implementations of this class will never buffer characters or bytes beyond a call to the write(char[], int, int) method, thus written characters will always be passed as bytes to the passed OutputStream

.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
WriteThroughWriter.Iso88591Writer

An implementation of WriteThroughWriter for optimal ISO-8859-1 conversion.

private static class
WriteThroughWriter.Utf8Writer

An implementation of WriteThroughWriter for an optimal UTF-8 conversion.

Field Summary

Modifier and TypeField and Description
pack-priv final ByteArrayOutputStream2
private final int
pack-priv final OutputStream
pack-priv static final int
Inherited from java.io.Writer:
lock

Constructor Summary

AccessConstructor and Description
protected
protected
WriteThroughWriter(OutputStream
The OutputStream to write the converted bytes to.
out
,
int
The maximum size in characters of a single conversion
maxWriteSize
)

Construct an java.io.OutputStreamWriter

Method Summary

Modifier and TypeMethod and Description
public abstract WriteThroughWriter
append(CharSequence
The character sequence to append. If csq is null, then the four characters "null" are appended to this writer.
sequence
)

Redeclares java.lang.Appendable.append.

Overrides java.io.Writer.append.

Appends the specified character sequence to this writer.
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 int
public static WriteThroughWriter

Returns:

A Writer that will
newWriter
(OutputStream
The OutputStream to write to/
outputStream
,
String
The Charset name.
charset
)

Obtain a new Writer that converts characters written to bytes written to an OutputStream.

public static WriteThroughWriter

Returns:

A Writer that will
newWriter
(OutputStream
The OutputStream to write to/
outputStream
,
Charset
The Charset.
charset
)

Obtain a new Writer that converts characters written to bytes written to an OutputStream.

pack-priv static CharSequence

Returns:

A new CharSequence containing the subsequence, backed by the passed String or the original String if it is the same.
subSequence
(String
The String to take a subsequence of.
string
,
int
The offset in characters into the string to start the subsequence
offset
,
int
The length in characters of the substring
length
)

Get a zero copy subsequence of a String.

pack-priv static CharSequence

Returns:

A new CharSequence containing the subsequence.
subSequence
(char[]
The characters to take a subsequence of. These character are not copied and the array should not be modified for the life of the returned CharSequence.
chars
,
int
The offset in characters into the string to start the subsequence
offset
,
int
The length in characters of the substring
length
)

Get a zero copy subsequence of a char array.

public void
write(String
A String
string
,
int
Offset from which to start writing characters
offset
,
int
Number of characters to write
length
)

Overrides java.io.Writer.write.

Writes a portion of a string.
public void
write(char[]
Array of characters
chars
,
int
Offset from which to start writing characters
offset
,
int
Number of characters to write
length
)

Implements abstract java.io.Writer.write.

Writes a portion of an array of characters.
Inherited from java.io.Writer:
appendappendnullWriterwritewritewrite

Field Detail

_bytesback to summary
pack-priv final ByteArrayOutputStream2 _bytes
_maxWriteSizeback to summary
private final int _maxWriteSize
_outback to summary
pack-priv final OutputStream _out
DEFAULT_MAX_WRITE_SIZEback to summary
pack-priv static final int DEFAULT_MAX_WRITE_SIZE

Constructor Detail

WriteThroughWriterback to summary
protected WriteThroughWriter(OutputStream out)
WriteThroughWriterback to summary
protected WriteThroughWriter(OutputStream out, int maxWriteSize)

Construct an java.io.OutputStreamWriter

Parameters
out:OutputStream

The OutputStream to write the converted bytes to.

maxWriteSize:int

The maximum size in characters of a single conversion

Method Detail

appendback to summary
public abstract WriteThroughWriter append(CharSequence sequence) throws IOException

Redeclares java.lang.Appendable.append.

Overrides java.io.Writer.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) 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.

Parameters
sequence:CharSequence

The character sequence to append. If csq is null, then the four characters "null" are appended to this writer.

Returns:WriteThroughWriter

This writer

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
closeback to summary
public void close() throws IOException

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
Exceptions
IOException:
If an I/O error occurs
flushback to summary
public void flush() throws IOException

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
Exceptions
IOException:
If an I/O error occurs
getMaxWriteSizeback to summary
public int getMaxWriteSize()
newWriterback to summary
public static WriteThroughWriter newWriter(OutputStream outputStream, String charset) throws IOException

Obtain a new Writer that converts characters written to bytes written to an OutputStream.

Parameters
outputStream:OutputStream

The OutputStream to write to/

charset:String

The Charset name.

Returns:WriteThroughWriter

A Writer that will

Exceptions
IOException:
If there is a problem creating the Writer.
newWriterback to summary
public static WriteThroughWriter newWriter(OutputStream outputStream, Charset charset) throws IOException

Obtain a new Writer that converts characters written to bytes written to an OutputStream.

Parameters
outputStream:OutputStream

The OutputStream to write to/

charset:Charset

The Charset.

Returns:WriteThroughWriter

A Writer that will

Exceptions
IOException:
If there is a problem creating the Writer.
subSequenceback to summary
pack-priv static CharSequence subSequence(String string, int offset, int length)

Get a zero copy subsequence of a String.

Use of this is method can result in unforeseen GC consequences and can bypass JVM optimizations available in String#subSequence(int, int). It should only be used in cases where there is a known benefit: large sub sequence of a larger string with no retained references to the sub sequence beyond the life time of the string.

Parameters
string:String

The String to take a subsequence of.

offset:int

The offset in characters into the string to start the subsequence

length:int

The length in characters of the substring

Returns:CharSequence

A new CharSequence containing the subsequence, backed by the passed String or the original String if it is the same.

subSequenceback to summary
pack-priv static CharSequence subSequence(char[] chars, int offset, int length)

Get a zero copy subsequence of a char array.

Parameters
chars:char[]

The characters to take a subsequence of. These character are not copied and the array should not be modified for the life of the returned CharSequence.

offset:int

The offset in characters into the string to start the subsequence

length:int

The length in characters of the substring

Returns:CharSequence

A new CharSequence containing the subsequence.

writeback to summary
public void write(String string, int offset, int length) throws IOException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a portion of a string.

Parameters
string:String

A String

offset:int

Offset from which to start writing characters

length:int

Number of characters to write

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(char[] chars, int offset, int length) throws IOException

Implements abstract java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a portion of an array of characters.

Parameters
chars:char[]

Array of characters

offset:int

Offset from which to start writing characters

length:int

Number of characters to write

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
org.eclipse.jetty.io back to summary

private Class WriteThroughWriter.EncodingWriter

extends WriteThroughWriter
Class Inheritance

An implementation of WriteThroughWriter that internally uses java.io.OutputStreamWriter.

Field Summary

Modifier and TypeField and Description
pack-priv final Writer
Inherited from org.eclipse.jetty.io.WriteThroughWriter:
_bytes_outDEFAULT_MAX_WRITE_SIZE

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public WriteThroughWriter
append(CharSequence
The character sequence to append. If csq is null, then the four characters "null" are appended to this writer.
charSequence
)

Implements abstract org.eclipse.jetty.io.WriteThroughWriter.append.

Implements java.lang.Appendable.append.

Appends the specified character sequence to this writer.
Inherited from org.eclipse.jetty.io.WriteThroughWriter:
closeflushgetMaxWriteSizenewWriternewWritersubSequencesubSequencewritewrite

Field Detail

_converterback to summary
pack-priv final Writer _converter

Constructor Detail

EncodingWriterback to summary
public EncodingWriter(OutputStream out, String encoding) throws IOException
EncodingWriterback to summary
public EncodingWriter(OutputStream out, Charset charset) throws IOException

Method Detail

appendback to summary
public WriteThroughWriter append(CharSequence charSequence) throws IOException

Implements abstract org.eclipse.jetty.io.WriteThroughWriter.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) 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.

Parameters
charSequence:CharSequence

The character sequence to append. If csq is null, then the four characters "null" are appended to this writer.

Returns:WriteThroughWriter

This writer

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
org.eclipse.jetty.io back to summary

private Class WriteThroughWriter.Iso88591Writer

extends WriteThroughWriter
Class Inheritance

An implementation of WriteThroughWriter for optimal ISO-8859-1 conversion. The ISO-8859-1 encoding is done by this class and no additional buffers or Writers are used.

Field Summary

Inherited from org.eclipse.jetty.io.WriteThroughWriter:
_bytes_outDEFAULT_MAX_WRITE_SIZE

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public WriteThroughWriter
append(CharSequence
The character sequence to append. If csq is null, then the four characters "null" are appended to this writer.
charSequence
)

Implements abstract org.eclipse.jetty.io.WriteThroughWriter.append.

Implements java.lang.Appendable.append.

Appends the specified character sequence to this writer.
Inherited from org.eclipse.jetty.io.WriteThroughWriter:
closeflushgetMaxWriteSizenewWriternewWritersubSequencesubSequencewritewrite

Constructor Detail

Iso88591Writerback to summary
private Iso88591Writer(OutputStream out)

Method Detail

appendback to summary
public WriteThroughWriter append(CharSequence charSequence) throws IOException

Implements abstract org.eclipse.jetty.io.WriteThroughWriter.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) 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.

Parameters
charSequence:CharSequence

The character sequence to append. If csq is null, then the four characters "null" are appended to this writer.

Returns:WriteThroughWriter

This writer

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
org.eclipse.jetty.io back to summary

private Class WriteThroughWriter.Utf8Writer

extends WriteThroughWriter
Class Inheritance

An implementation of WriteThroughWriter for an optimal UTF-8 conversion. The UTF-8 encoding is done by this class and no additional buffers or Writers are used. The UTF-8 code was inspired by ...

Field Summary

Modifier and TypeField and Description
pack-priv int
Inherited from org.eclipse.jetty.io.WriteThroughWriter:
_bytes_outDEFAULT_MAX_WRITE_SIZE

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public WriteThroughWriter
append(CharSequence
The character sequence to append. If csq is null, then the four characters "null" are appended to this writer.
charSequence
)

Implements abstract org.eclipse.jetty.io.WriteThroughWriter.append.

Implements java.lang.Appendable.append.

Appends the specified character sequence to this writer.
Inherited from org.eclipse.jetty.io.WriteThroughWriter:
closeflushgetMaxWriteSizenewWriternewWritersubSequencesubSequencewritewrite

Field Detail

_surrogateback to summary
pack-priv int _surrogate

Constructor Detail

Utf8Writerback to summary
private Utf8Writer(OutputStream out)

Method Detail

appendback to summary
public WriteThroughWriter append(CharSequence charSequence) throws IOException

Implements abstract org.eclipse.jetty.io.WriteThroughWriter.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) 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.

Parameters
charSequence:CharSequence

The character sequence to append. If csq is null, then the four characters "null" are appended to this writer.

Returns:WriteThroughWriter

This writer

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs