org.apache.velocity.io
Class VelocityWriter

java.lang.Object
  |
  +--java.io.Writer
        |
        +--org.apache.velocity.io.VelocityWriter

public final class VelocityWriter
extends java.io.Writer

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

Version:
$Id: VelocityWriter.java,v 1.6 2001/10/22 03:53:23 jon Exp $
Author:
Jason van Zyl, Jon S. Stevens, Anil K. Vijendran

Field Summary
protected  boolean autoFlush
           
protected  int bufferSize
           
private  char[] cb
           
static int DEFAULT_BUFFER
          constant indicating that the Writer is buffered and is using the implementation default buffer size
private static int defaultCharBufferSize
           
private  boolean flushed
           
private  int nextChar
           
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
private  java.io.Writer writer
           
 
Fields inherited from class java.io.Writer
lock, writeBuffer, writeBufferSize
 
Constructor Summary
private VelocityWriter(int bufferSize, boolean autoFlush)
          private constructor.
  VelocityWriter(java.io.Writer writer)
          Create a buffered character-output stream that uses a default-sized output buffer.
  VelocityWriter(java.io.Writer writer, int sz, boolean autoFlush)
          Create a new buffered character-output stream that uses an output buffer of the given size.
 
Method Summary
private  void bufferOverflow()
           
 void clear()
          Discard the output buffer.
 void close()
          Close the stream.
 void flush()
          Flush the stream.
private  void flushBuffer()
          Flush the output buffer to the underlying character stream, without flushing the stream itself.
 int getBufferSize()
          This method returns the size of the buffer used by the JspWriter.
 int getRemaining()
           
private  void init(java.io.Writer writer, int sz, boolean autoFlush)
           
 boolean isAutoFlush()
          This method indicates whether the JspWriter is autoFlushing.
private  int min(int a, int b)
          Our own little min method, to avoid loading java.lang.Math if we've run out of file descriptors and we're trying to print a stack trace.
 void recycle(java.io.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(java.lang.String s)
          Write a string.
 void write(java.lang.String s, int off, int len)
          Write a portion of a String.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

NO_BUFFER

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

DEFAULT_BUFFER

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

UNBOUNDED_BUFFER

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

bufferSize

protected int bufferSize

autoFlush

protected boolean autoFlush

writer

private java.io.Writer writer

cb

private char[] cb

nextChar

private int nextChar

defaultCharBufferSize

private static int defaultCharBufferSize

flushed

private boolean flushed
Constructor Detail

VelocityWriter

public VelocityWriter(java.io.Writer writer)
Create a buffered character-output stream that uses a default-sized output buffer.
Parameters:
response - A Servlet Response

VelocityWriter

private VelocityWriter(int bufferSize,
                       boolean autoFlush)
private constructor.

VelocityWriter

public VelocityWriter(java.io.Writer writer,
                      int sz,
                      boolean autoFlush)
Create a new buffered character-output stream that uses an output buffer of the given size.
Parameters:
response - A Servlet Response
sz - Output-buffer size, a positive integer
Throws:
java.lang.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

init

private final void init(java.io.Writer writer,
                        int sz,
                        boolean autoFlush)

flushBuffer

private final void flushBuffer()
                        throws java.io.IOException
Flush the output buffer to the underlying character stream, without flushing the stream itself. This method is non-private only so that it may be invoked by PrintStream.

clear

public final void clear()
Discard the output buffer.

bufferOverflow

private final void bufferOverflow()
                           throws java.io.IOException

flush

public final void flush()
                 throws java.io.IOException
Flush the stream.
Overrides:
flush in class java.io.Writer

close

public final void close()
                 throws java.io.IOException
Close the stream.
Overrides:
close in class java.io.Writer

getRemaining

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

write

public final void write(int c)
                 throws java.io.IOException
Write a single character.
Overrides:
write in class java.io.Writer

min

private final int min(int a,
                      int b)
Our own little min method, to avoid loading java.lang.Math if we've run out of file descriptors and we're trying to print a stack trace.

write

public final void write(char[] cbuf,
                        int off,
                        int len)
                 throws java.io.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.

Overrides:
write in class java.io.Writer
Parameters:
cbuf - A character array
off - Offset from which to start reading characters
len - Number of characters to write

write

public final void write(char[] buf)
                 throws java.io.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 java.io.Writer

write

public final void write(java.lang.String s,
                        int off,
                        int len)
                 throws java.io.IOException
Write a portion of a String.
Overrides:
write in class java.io.Writer
Parameters:
s - String to be written
off - Offset from which to start reading characters
len - Number of characters to be written

write

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

recycle

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


Copyright © 2003 Apache Software Foundation. All Rights Reserved.