org.apache.xml.serializer
Class SerializerTraceWriter

java.lang.Object
  extended by java.io.Writer
      extended by org.apache.xml.serializer.SerializerTraceWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable, WriterChain

final class SerializerTraceWriter
extends java.io.Writer
implements WriterChain

This class wraps the real writer, it only purpose is to send CHARACTERTOSTREAM events to the trace listener. Each method immediately sends the call to the wrapped writer unchanged, but in addition it collects characters to be issued to a trace listener. In this way the trace listener knows what characters have been written to the output Writer. There may still be differences in what the trace events say is going to the output writer and what is really going there. These differences will be due to the fact that this class is UTF-8 encoding before emiting the trace event and the underlying writer may not be UTF-8 encoding. There may also be encoding differences. So the main pupose of this class is to provide a resonable facsimile of the true output.


Field Summary
private  byte[] buf
          Internal buffer to collect the characters to go to the trace listener.
private  int buf_length
          The size of the internal buffer, just to keep too many events from being sent to the tracer
private  int count
          How many bytes have been collected and still need to go to trace listener.
private  SerializerTrace m_tracer
          The tracer to send events to
private  java.io.Writer m_writer
          The real writer to immediately write to.
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
SerializerTraceWriter(java.io.Writer out, SerializerTrace tracer)
          Constructor.
 
Method Summary
 void close()
          Flush the internal buffer and close the Writer
 void flush()
          Flush the internal buffer and flush the Writer
private  void flushBuffer()
          Flush out the collected characters by sending them to the trace listener.
 java.io.OutputStream getOutputStream()
          Get the OutputStream that is the at the end of the chain of writers.
 java.io.Writer getWriter()
          Get the writer that this one directly wraps.
private  void setBufferSize(int size)
          Creates or replaces the internal buffer, and makes sure it has a few extra bytes slight overflow of the last UTF8 encoded character.
 void write(char[] chars, int start, int length)
          Write a portion of an array of characters.
 void write(int c)
          Write a single character.
 void write(java.lang.String s)
          Write a string.
 
Methods inherited from class java.io.Writer
append, append, append, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.xml.serializer.WriterChain
write, write
 

Field Detail

m_writer

private final java.io.Writer m_writer
The real writer to immediately write to. This reference may be null, in which case nothing is written out, but only the trace events are fired for output.


m_tracer

private final SerializerTrace m_tracer
The tracer to send events to


buf_length

private int buf_length
The size of the internal buffer, just to keep too many events from being sent to the tracer


buf

private byte[] buf
Internal buffer to collect the characters to go to the trace listener.


count

private int count
How many bytes have been collected and still need to go to trace listener.

Constructor Detail

SerializerTraceWriter

public SerializerTraceWriter(java.io.Writer out,
                             SerializerTrace tracer)
Constructor. If the writer passed in is null, then this SerializerTraceWriter will only signal trace events of what would have been written to that writer. If the writer passed in is not null then the trace events will mirror what is going to that writer. In this way tools, such as a debugger, can gather information on what is being written out.

Parameters:
out - the Writer to write to (possibly null)
tracer - the tracer to inform that characters are being written
Method Detail

setBufferSize

private void setBufferSize(int size)
Creates or replaces the internal buffer, and makes sure it has a few extra bytes slight overflow of the last UTF8 encoded character.

Parameters:
size -

flushBuffer

private void flushBuffer()
                  throws java.io.IOException
Flush out the collected characters by sending them to the trace listener. These characters are never written to the real writer (m_writer) because that has already happened with every method call. This method simple informs the listener of what has already happened.

Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Flush the internal buffer and flush the Writer

Specified by:
flush in interface java.io.Flushable
Specified by:
flush in interface WriterChain
Specified by:
flush in class java.io.Writer
Throws:
java.io.IOException
See Also:
Writer.flush()

close

public void close()
           throws java.io.IOException
Flush the internal buffer and close the Writer

Specified by:
close in interface java.io.Closeable
Specified by:
close in interface WriterChain
Specified by:
close in class java.io.Writer
Throws:
java.io.IOException
See Also:
Writer.close()

write

public void write(int c)
           throws java.io.IOException
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.

Specified by:
write in interface WriterChain
Overrides:
write in class java.io.Writer
Parameters:
c - int specifying a character to be written.
Throws:
java.io.IOException - If an I/O error occurs

write

public void write(char[] chars,
                  int start,
                  int length)
           throws java.io.IOException
Write a portion of an array of characters.

Specified by:
write in interface WriterChain
Specified by:
write in class java.io.Writer
Parameters:
chars - Array of characters
start - Offset from which to start writing characters
length - Number of characters to write
Throws:
java.io.IOException - If an I/O error occurs
java.io.IOException

write

public void write(java.lang.String s)
           throws java.io.IOException
Write a string.

Specified by:
write in interface WriterChain
Overrides:
write in class java.io.Writer
Parameters:
s - String to be written
Throws:
java.io.IOException - If an I/O error occurs

getWriter

public java.io.Writer getWriter()
Get the writer that this one directly wraps.

Specified by:
getWriter in interface WriterChain

getOutputStream

public java.io.OutputStream getOutputStream()
Get the OutputStream that is the at the end of the chain of writers.

Specified by:
getOutputStream in interface WriterChain