Package org.apache.velocity.io
Class VelocityWriter
- java.lang.Object
-
- java.io.Writer
-
- org.apache.velocity.io.VelocityWriter
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.Appendable,java.lang.AutoCloseable
public final class VelocityWriter extends java.io.WriterImplementation of a fast Writer. It was originally taken from JspWriter and modified to have less syncronization going on.- Version:
- $Id: VelocityWriter.java 463298 2006-10-12 16:10:32Z henning $
-
-
Field Summary
Fields Modifier and Type Field Description private booleanautoFlushprivate intbufferSizeprivate char[]cbstatic intDEFAULT_BUFFERconstant indicating that the Writer is buffered and is using the implementation default buffer sizeprivate static intdefaultCharBufferSizeprivate intnextCharstatic intNO_BUFFERconstant indicating that the Writer is not buffering outputstatic intUNBOUNDED_BUFFERconstant indicating that the Writer is buffered and is unbounded; this is used in BodyContentprivate java.io.Writerwriter
-
Constructor Summary
Constructors Modifier Constructor Description privateVelocityWriter(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidbufferOverflow()voidclear()Discard the output buffer.voidclose()Close the stream.voidflush()Flush the stream.private 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()booleanisAutoFlush()This method indicates whether the JspWriter is autoFlushing.private intmin(int a, int b)Our own little min method, to avoid loadingjava.lang.Mathif we've run out of file descriptors and we're trying to print a stack trace.voidrecycle(java.io.Writer writer)resets this class so that it can be reusedvoidwrite(char[] buf)Write an array of characters.voidwrite(char[] cbuf, int off, int len)Write a portion of an array of characters.voidwrite(int c)Write a single character.voidwrite(java.lang.String s)Write a string.voidwrite(java.lang.String s, int off, int len)Write a portion of a String.
-
-
-
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
-
bufferSize
private int bufferSize
-
autoFlush
private boolean autoFlush
-
writer
private java.io.Writer writer
-
cb
private char[] cb
-
nextChar
private int nextChar
-
defaultCharBufferSize
private static int defaultCharBufferSize
-
-
Constructor Detail
-
VelocityWriter
public VelocityWriter(java.io.Writer writer)
Create a buffered character-output stream that uses a default-sized output buffer.- Parameters:
writer- Writer to wrap around
-
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:
writer- Writer to wrap aroundsz- Output-buffer size, a positive integerautoFlush-- 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
-
flushBuffer
private final void flushBuffer() throws java.io.IOExceptionFlush 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.- Throws:
java.io.IOException
-
clear
public final void clear()
Discard the output buffer.
-
bufferOverflow
private final void bufferOverflow() throws java.io.IOException- Throws:
java.io.IOException
-
flush
public final void flush() throws java.io.IOExceptionFlush the stream.- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin classjava.io.Writer- Throws:
java.io.IOException
-
close
public final void close() throws java.io.IOExceptionClose the stream.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Writer- Throws:
java.io.IOException
-
getRemaining
public final int getRemaining()
- Returns:
- the number of bytes unused in the buffer
-
write
public final void write(int c) throws java.io.IOExceptionWrite a single character.- Overrides:
writein classjava.io.Writer- Parameters:
c-- Throws:
java.io.IOException
-
min
private final int min(int a, int b)Our own little min method, to avoid loadingjava.lang.Mathif 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.IOExceptionWrite 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:
writein classjava.io.Writer- Parameters:
cbuf- A character arrayoff- Offset from which to start reading characterslen- Number of characters to write- Throws:
java.io.IOException
-
write
public final void write(char[] buf) throws java.io.IOExceptionWrite an array of characters. This method cannot be inherited from the Writer class because it must suppress I/O exceptions.- Overrides:
writein classjava.io.Writer- Parameters:
buf-- Throws:
java.io.IOException
-
write
public final void write(java.lang.String s, int off, int len) throws java.io.IOExceptionWrite a portion of a String.- Overrides:
writein classjava.io.Writer- Parameters:
s- String to be writtenoff- Offset from which to start reading characterslen- Number of characters to be written- Throws:
java.io.IOException
-
write
public final void write(java.lang.String s) throws java.io.IOExceptionWrite a string. This method cannot be inherited from the Writer class because it must suppress I/O exceptions.- Overrides:
writein classjava.io.Writer- Parameters:
s-- Throws:
java.io.IOException
-
recycle
public final void recycle(java.io.Writer writer)
resets this class so that it can be reused- Parameters:
writer-
-
-