APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.org.apache.xml.internal.serializer

pack-priv final Class WriterToUTF8Buffered

extends Writer
implements WriterChain
Class Inheritance
All Implemented Interfaces
com.sun.org.apache.xml.internal.serializer.WriterChain
Imports
java.io.IOException, .OutputStream, .UnsupportedEncodingException, .Writer

This class writes unicode characters to a byte stream (java.io.OutputStream) as quickly as possible. It buffers the output in an internal buffer which must be flushed to the OutputStream when done. This flushing is done via the close() flush() or flushBuffer() method. This class is only used internally within Xalan.

Field Summary

Modifier and TypeField and Description
private static final int
BYTES_MAX

number of bytes that the byte buffer can hold.

private static final int
CHARS_MAX

number of characters that the character buffer can hold.

private int
count

The number of valid bytes in the buffer.

private final char[]
private final OutputStream
m_os

The byte stream to write to.

private final byte[]
m_outputBytes

The internal buffer where data is stored.

Inherited from java.io.Writer:
lock

Constructor Summary

AccessConstructor and Description
public
WriterToUTF8Buffered(OutputStream
the underlying output stream.
out
)

Create an buffered UTF-8 writer.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract java.io.Writer.close.

Implements com.sun.org.apache.xml.internal.serializer.WriterChain.close, java.io.Closeable.close.

Close the stream, flushing it first.

public void
public void
flushBuffer()

Flush the internal buffer

public OutputStream

Returns:

reference to the result stream, or null of only a writer was set.
getOutputStream
()

Implements com.sun.org.apache.xml.internal.serializer.WriterChain.getOutputStream.

Get the output stream where the events will be serialized to.

public Writer
getWriter()

Implements com.sun.org.apache.xml.internal.serializer.WriterChain.getWriter.

If this method returns null, getOutputStream() must return non-null.

public void
write(final int
int specifying a character to be written.
c
)

Overrides java.io.Writer.write.

Implements com.sun.org.apache.xml.internal.serializer.WriterChain.write.

Write a single character.

public void
write(final char[]
Array of characters
chars
,
final int
Offset from which to start writing characters
start
,
final int
Number of characters to write
length
)

Implements abstract java.io.Writer.write.

Implements com.sun.org.apache.xml.internal.serializer.WriterChain.write.

Write a portion of an array of characters.

public void
write(final String
String to be written
s
)

Overrides java.io.Writer.write.

Implements com.sun.org.apache.xml.internal.serializer.WriterChain.write.

Write a string.

Inherited from java.io.Writer:
appendappendappendnullWriterwritewrite

Field Detail

BYTES_MAXback to summary
private static final int BYTES_MAX

number of bytes that the byte buffer can hold. This is a fixed constant is used rather than m_outputBytes.lenght for performance.

CHARS_MAXback to summary
private static final int CHARS_MAX

number of characters that the character buffer can hold. This is 1/3 of the number of bytes because UTF-8 encoding can expand one unicode character by up to 3 bytes.

countback to summary
private int count

The number of valid bytes in the buffer. This value is always in the range 0 through m_outputBytes.length; elements m_outputBytes[0] through m_outputBytes[count-1] contain valid byte data.

m_inputCharsback to summary
private final char[] m_inputChars
m_osback to summary
private final OutputStream m_os

The byte stream to write to. (sc & sb remove final to compile in JDK 1.1.8)

m_outputBytesback to summary
private final byte[] m_outputBytes

The internal buffer where data is stored. (sc & sb remove final to compile in JDK 1.1.8)

Constructor Detail

WriterToUTF8Bufferedback to summary
public WriterToUTF8Buffered(OutputStream out) throws UnsupportedEncodingException

Create an buffered UTF-8 writer.

Parameters
out:OutputStream

the underlying output stream.

Method Detail

closeback to summary
public void close() throws IOException

Implements abstract java.io.Writer.close.

Implements com.sun.org.apache.xml.internal.serializer.WriterChain.close, java.io.Closeable.close.

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

Exceptions
IOException:
If an I/O error occurs
flushback to summary
public void flush() throws IOException

Implements abstract java.io.Writer.flush.

Implements com.sun.org.apache.xml.internal.serializer.WriterChain.flush, java.io.Flushable.flush.

Flush 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.

Exceptions
IOException:
If an I/O error occurs
flushBufferback to summary
public void flushBuffer() throws IOException

Flush the internal buffer

getOutputStreamback to summary
public OutputStream getOutputStream()

Implements com.sun.org.apache.xml.internal.serializer.WriterChain.getOutputStream.

Get the output stream where the events will be serialized to.

Returns:OutputStream

reference to the result stream, or null of only a writer was set.

getWriterback to summary
public Writer getWriter()

Implements com.sun.org.apache.xml.internal.serializer.WriterChain.getWriter.

Doc from com.sun.org.apache.xml.internal.serializer.WriterChain.getWriter.

If this method returns null, getOutputStream() must return non-null. Get the writer that this writer sends its output to. It is possible that the Writer returned by this method does not implement the WriterChain interface.

writeback to summary
public void write(final int c) throws IOException

Overrides java.io.Writer.write.

Implements com.sun.org.apache.xml.internal.serializer.WriterChain.write.

Write 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.

Parameters
c:int

int specifying a character to be written.

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

Implements abstract java.io.Writer.write.

Implements com.sun.org.apache.xml.internal.serializer.WriterChain.write.

Write a portion of an array of characters.

Parameters
chars:char[]

Array of characters

start:int

Offset from which to start writing characters

length:int

Number of characters to write

Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(final String s) throws IOException

Overrides java.io.Writer.write.

Implements com.sun.org.apache.xml.internal.serializer.WriterChain.write.

Write a string.

Parameters
s:String

String to be written

Exceptions
IOException:
If an I/O error occurs