org.apache.velocity.io

Class VelocityWriter

public final class VelocityWriter extends 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.8.4.1 2004/03/03 23:22:54 geirm Exp $

Author: Jason van Zyl Jon S. Stevens Anil K. Vijendran

Field Summary
protected booleanautoFlush
protected intbufferSize
char[]cb
static intdefaultCharBufferSize
static intDEFAULT_BUFFER
constant indicating that the Writer is buffered and is using the implementation default buffer size
booleanflushed
intnextChar
static intNO_BUFFER
constant indicating that the Writer is not buffering output
static intUNBOUNDED_BUFFER
constant indicating that the Writer is buffered and is unbounded; this is used in BodyContent
Writerwriter
Constructor Summary
VelocityWriter(Writer writer)
Create a buffered character-output stream that uses a default-sized output buffer.
VelocityWriter(int bufferSize, boolean autoFlush)
private constructor.
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
voidbufferOverflow()
voidclear()
Discard the output buffer.
voidclose()
Close the stream.
voidflush()
Flush the stream.
voidflushBuffer()
Flush the output buffer to the underlying character stream, without flushing the stream itself.
intgetBufferSize()
This method returns the size of the buffer used by the JspWriter.
intgetRemaining()
voidinit(Writer writer, int sz, boolean autoFlush)
booleanisAutoFlush()
This method indicates whether the JspWriter is autoFlushing.
intmin(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.
voidrecycle(Writer writer)
resets this class so that it can be reused
voidwrite(int c)
Write a single character.
voidwrite(char[] cbuf, int off, int len)
Write a portion of an array of characters.
voidwrite(char[] buf)
Write an array of characters.
voidwrite(String s, int off, int len)
Write a portion of a String.
voidwrite(String s)
Write a string.

Field Detail

autoFlush

protected boolean autoFlush

bufferSize

protected int bufferSize

cb

private char[] cb

defaultCharBufferSize

private static int defaultCharBufferSize

DEFAULT_BUFFER

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

flushed

private boolean flushed

nextChar

private int nextChar

NO_BUFFER

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

UNBOUNDED_BUFFER

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

writer

private Writer writer

Constructor Detail

VelocityWriter

public VelocityWriter(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(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: IllegalArgumentException If sz is <= 0

Method Detail

bufferOverflow

private final void bufferOverflow()

clear

public final void clear()
Discard the output buffer.

close

public final void close()
Close the stream.

flush

public final void flush()
Flush the stream.

flushBuffer

private final void flushBuffer()
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.

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.

getRemaining

public final int getRemaining()

Returns: the number of bytes unused in the buffer

init

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

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

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.

recycle

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

write

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

write

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

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)
Write an array of characters. This method cannot be inherited from the Writer class because it must suppress I/O exceptions.

write

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

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(String s)
Write a string. This method cannot be inherited from the Writer class because it must suppress I/O exceptions.
Copyright B) 2002 Apache Software Foundation. All Rights Reserved.