org.apache.velocity.io
Class VelocityWriter

java.lang.Object
  extended by java.io.Writer
      extended by org.apache.velocity.io.VelocityWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, Filter

public final class VelocityWriter
extends Writer
implements Filter

Implementation of a fast Writer. It was originally taken from JspWriter and modified to have less syncronization going on.

Version:
$Id: VelocityWriter.java 960033 2010-07-02 15:39:52Z apetrelli $
Author:
Jason van Zyl, Jon S. Stevens, Anil K. Vijendran

Field Summary
static int DEFAULT_BUFFER
          constant indicating that the Writer is buffered and is using the implementation default buffer size
static int NO_BUFFER
          constant indicating that the Writer is not buffering output
static int UNBOUNDED_BUFFER
          constant indicating that the Writer is buffered and is unbounded; this is used in BodyContent
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
VelocityWriter(Writer writer)
          Create a buffered character-output stream that uses a default-sized output buffer.
VelocityWriter(Writer writer, int sz, boolean autoFlush)
          Create a new buffered character-output stream that uses an output buffer of the given size.
 
Method Summary
 void clear()
          Discard the output buffer.
 void close()
          Close the stream.
 void flush()
          Flush the stream.
 int getBufferSize()
          This method returns the size of the buffer used by the JspWriter.
 int getRemaining()
           
 boolean isAutoFlush()
          This method indicates whether the JspWriter is autoFlushing.
 void recycle(Writer writer)
          resets this class so that it can be reused
 void write(char[] buf)
          Write an array of characters.
 void write(char[] cbuf, int off, int len)
          Write a portion of an array of characters.
 void write(int c)
          Write a single character.
 void write(String s)
          Write a string.
 void write(String s, int off, int len)
          Write a portion of a String.
 void writeReference(String ref)
          Send the content of a reference, e.g.; $foo, to the writer.
 
Methods inherited from class java.io.Writer
append, append, append
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_BUFFER

public static final int NO_BUFFER
constant indicating that the Writer is not buffering output

See Also:
Constant Field Values

DEFAULT_BUFFER

public static final int DEFAULT_BUFFER
constant indicating that the Writer is buffered and is using the implementation default buffer size

See Also:
Constant Field Values

UNBOUNDED_BUFFER

public static final int UNBOUNDED_BUFFER
constant indicating that the Writer is buffered and is unbounded; this is used in BodyContent

See Also:
Constant Field Values
Constructor Detail

VelocityWriter

public VelocityWriter(Writer writer)
Create a buffered character-output stream that uses a default-sized output buffer.

Parameters:
writer - Writer to wrap around

VelocityWriter

public VelocityWriter(Writer writer,
                      int sz,
                      boolean autoFlush)
Create a new buffered character-output stream that uses an output buffer of the given size.

Parameters:
writer - Writer to wrap around
sz - Output-buffer size, a positive integer
autoFlush -
Throws:
IllegalArgumentException - If sz is <= 0
Method Detail

getBufferSize

public int getBufferSize()
This method returns the size of the buffer used by the JspWriter.

Returns:
the size of the buffer in bytes, or 0 is unbuffered.

isAutoFlush

public boolean isAutoFlush()
This method indicates whether the JspWriter is autoFlushing.

Returns:
if this JspWriter is auto flushing or throwing IOExceptions on buffer overflow conditions

clear

public final void clear()
Discard the output buffer.


flush

public final void flush()
                 throws IOException
Flush the stream.

Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
IOException

close

public final void close()
                 throws IOException
Close the stream.

Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException

getRemaining

public final int getRemaining()
Returns:
the number of bytes unused in the buffer

write

public final void write(int c)
                 throws IOException
Write a single character.

Overrides:
write in class Writer
Parameters:
c -
Throws:
IOException

write

public final void write(char[] cbuf,
                        int off,
                        int len)
                 throws IOException
Write a portion of an array of characters.

Ordinarily this method stores characters from the given array into this stream's buffer, flushing the buffer to the underlying stream as needed. If the requested length is at least as large as the buffer, however, then this method will flush the buffer and write the characters directly to the underlying stream. Thus redundant DiscardableBufferedWriters will not copy data unnecessarily.

Specified by:
write in class Writer
Parameters:
cbuf - A character array
off - Offset from which to start reading characters
len - Number of characters to write
Throws:
IOException

write

public final void write(char[] buf)
                 throws IOException
Write an array of characters. This method cannot be inherited from the Writer class because it must suppress I/O exceptions.

Overrides:
write in class Writer
Parameters:
buf -
Throws:
IOException

write

public final void write(String s,
                        int off,
                        int len)
                 throws IOException
Write a portion of a String.

Overrides:
write in class Writer
Parameters:
s - String to be written
off - Offset from which to start reading characters
len - Number of characters to be written
Throws:
IOException

write

public final void write(String s)
                 throws IOException
Write a string. This method cannot be inherited from the Writer class because it must suppress I/O exceptions.

Overrides:
write in class Writer
Parameters:
s -
Throws:
IOException

recycle

public final void recycle(Writer writer)
resets this class so that it can be reused

Parameters:
writer -

writeReference

public void writeReference(String ref)
                    throws IOException
Send the content of a reference, e.g.; $foo, to the writer. The default implementation is to call the wrapped Writer's write(String) method.

Specified by:
writeReference in interface Filter
Throws:
IOException


Copyright © 2000-2012 The Apache Software Foundation. All Rights Reserved.