org.melati.template.webmacro
Class FastWriter

java.lang.Object
  extended by java.io.Writer
      extended by org.melati.template.webmacro.FastWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable

public class FastWriter
extends java.io.Writer

FastWriter attempts to optimize output speed in a WebMacro template through several specific optimizations:

Note that the FastWriter requires an explicit flush

Version:
27-07-2002
Author:
Marcel Huijkman

Field Summary
static java.lang.String SAFE_UNICODE_ENCODING
          This encoding is either UTF16-BE or, if the platform does not support it, UTF8.
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
FastWriter(org.webmacro.Broker broker, java.io.OutputStream out, java.lang.String encoding)
          Create a FastWriter to the target outputstream.
FastWriter(org.webmacro.Broker broker, java.lang.String encoding)
          Create a new FastWriter with no output stream target.
 
Method Summary
 void close()
           
 void flush()
          Flush all data out to the OutputStream, if any, clearing the internal buffers.
 org.webmacro.util.Encoder getEncoder()
          Get the encoder used by this FastWriter to transform char[] data into byte[] data.
 java.lang.String getEncoding()
          Get the character encoding this FastWriter uses to convert characters to byte[]
static FastWriter getInstance(org.webmacro.Broker broker)
          Return a FastWriter with default encoding and no output stream.
static FastWriter getInstance(org.webmacro.Broker broker, java.io.OutputStream out)
          Get a new FastWriter.
static FastWriter getInstance(org.webmacro.Broker broker, java.io.OutputStream out, java.lang.String encoding)
          Get a new FastWriter.
static FastWriter getInstance(org.webmacro.Broker broker, java.lang.String encoding)
          Return a FastWriter with the specified encoding and no output stream.
 java.io.OutputStream getOutputStream()
          Get the output stream this FastWriter sends output to.
 void reset(java.io.OutputStream out)
          Reset the fastwriter, clearing any contents that have been generated so far.
 int size()
          Return the number of bytes that would be written out if flush() is called.
 byte[] toByteArray()
          Copy the contents written so far into a byte array.
 java.lang.String toString()
          Copy the contents written so far into a String.
 void write(byte[] rawBytes)
          Write raw bytes to the underlying stream.
 void write(byte[] rawBytes, int offset, int len)
          Write raw bytes to the underlying stream.
 void write(char[] cbuf)
          Write characters to the output stream performing slow unicode conversion unless AsciiHack is on.
 void write(char[] cbuf, int offset, int len)
          Write characters to to the output stream performing slow unicode conversion.
 void write(int c)
          Write a single character, performing slow unicode conversion
 void write(java.lang.String s)
          Write a string to the underlying output stream, performing unicode conversion.
 void write(java.lang.String s, int off, int len)
          Write a string to the underlying output stream, performing unicode conversion.
 void writeStatic(java.lang.String s)
          Write a string to the underlying output stream, performing unicode conversion if necessary--try and read the encoding from an encoding cache if possible.
 void writeTo(java.io.OutputStream out)
          Copy the contents written so far to the suppiled output stream
 
Methods inherited from class java.io.Writer
append, append, append
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SAFE_UNICODE_ENCODING

public static final java.lang.String SAFE_UNICODE_ENCODING
This encoding is either UTF16-BE or, if the platform does not support it, UTF8. It is a Unicode encoding which can have encoded strings concatenated together.

Constructor Detail

FastWriter

public FastWriter(org.webmacro.Broker broker,
                  java.io.OutputStream out,
                  java.lang.String encoding)
           throws java.io.UnsupportedEncodingException
Create a FastWriter to the target outputstream. You must specify a character encoding. You can also call writeTo(), toString(), and toByteArray() to access any un-flush()ed contents.

Throws:
java.io.UnsupportedEncodingException

FastWriter

public FastWriter(org.webmacro.Broker broker,
                  java.lang.String encoding)
           throws java.io.UnsupportedEncodingException
Create a new FastWriter with no output stream target. You can still call writeTo(), toString(), and toByteArray().

Throws:
java.io.UnsupportedEncodingException
Method Detail

getEncoding

public java.lang.String getEncoding()
Get the character encoding this FastWriter uses to convert characters to byte[]


getEncoder

public org.webmacro.util.Encoder getEncoder()
Get the encoder used by this FastWriter to transform char[] data into byte[] data.


getOutputStream

public java.io.OutputStream getOutputStream()
Get the output stream this FastWriter sends output to. It may be null, in which case output is not sent anywhere.


write

public void write(char[] cbuf)
           throws java.io.IOException
Write characters to the output stream performing slow unicode conversion unless AsciiHack is on.

Overrides:
write in class java.io.Writer
Throws:
java.io.IOException

write

public void write(char[] cbuf,
                  int offset,
                  int len)
           throws java.io.IOException
Write characters to to the output stream performing slow unicode conversion.

Specified by:
write in class java.io.Writer
Throws:
java.io.IOException

write

public void write(int c)
           throws java.io.IOException
Write a single character, performing slow unicode conversion

Overrides:
write in class java.io.Writer
Throws:
java.io.IOException

write

public void write(java.lang.String s)
           throws java.io.IOException
Write a string to the underlying output stream, performing unicode conversion.

Overrides:
write in class java.io.Writer
Throws:
java.io.IOException

write

public void write(java.lang.String s,
                  int off,
                  int len)
           throws java.io.IOException
Write a string to the underlying output stream, performing unicode conversion.

Overrides:
write in class java.io.Writer
Throws:
java.io.IOException

writeStatic

public void writeStatic(java.lang.String s)
Write a string to the underlying output stream, performing unicode conversion if necessary--try and read the encoding from an encoding cache if possible.


write

public void write(byte[] rawBytes)
Write raw bytes to the underlying stream. These bytes must be properly encoded with the encoding returned by getEncoding().


write

public void write(byte[] rawBytes,
                  int offset,
                  int len)
Write raw bytes to the underlying stream. Tehse bytes must be properly encoded witht he encoding returned by getEncoding()


flush

public void flush()
           throws java.io.IOException
Flush all data out to the OutputStream, if any, clearing the internal buffers. Note that data is ONLY written to the output stream on a flush() operation, and never at any other time. Consequently this is one of the few places that you may actually encounter an IOException when using the FastWriter class.

Specified by:
flush in interface java.io.Flushable
Specified by:
flush in class java.io.Writer
Throws:
java.io.IOException

size

public int size()
Return the number of bytes that would be written out if flush() is called.


toByteArray

public byte[] toByteArray()
Copy the contents written so far into a byte array.


toString

public java.lang.String toString()
Copy the contents written so far into a String.

Overrides:
toString in class java.lang.Object

writeTo

public void writeTo(java.io.OutputStream out)
Copy the contents written so far to the suppiled output stream


reset

public void reset(java.io.OutputStream out)
Reset the fastwriter, clearing any contents that have been generated so far.


getInstance

public static FastWriter getInstance(org.webmacro.Broker broker,
                                     java.io.OutputStream out,
                                     java.lang.String encoding)
                              throws java.io.UnsupportedEncodingException
Get a new FastWriter. You must then call writeTo(..) before attempting to write to the FastWriter.

Throws:
java.io.UnsupportedEncodingException

getInstance

public static FastWriter getInstance(org.webmacro.Broker broker,
                                     java.io.OutputStream out)
                              throws java.io.UnsupportedEncodingException
Get a new FastWriter. You must then call writeTo(..) before attempting to write to the FastWriter.

Throws:
java.io.UnsupportedEncodingException

getInstance

public static FastWriter getInstance(org.webmacro.Broker broker,
                                     java.lang.String encoding)
                              throws java.io.UnsupportedEncodingException
Return a FastWriter with the specified encoding and no output stream.

Throws:
java.io.UnsupportedEncodingException

getInstance

public static FastWriter getInstance(org.webmacro.Broker broker)
Return a FastWriter with default encoding and no output stream.


close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Writer
Throws:
java.io.IOException


Copyright © 2000-2008 PanEris. All Rights Reserved.