Package org.apache.velocity.io
Class VelocityWriter
java.lang.Object
java.io.Writer
org.apache.velocity.io.VelocityWriter
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable,Filter
Implementation of a fast Writer. It was originally taken from JspWriter
and modified to have less synchronization going on.
- Version:
- $Id$
- Author:
- Jason van Zyl, Jon S. Stevens, Anil K. Vijendran
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intconstant indicating that the Writer is buffered and is using the implementation default buffer sizestatic final intconstant indicating that the Writer is not buffering outputstatic final intconstant indicating that the Writer is buffered and is unbounded; this is used in BodyContent -
Constructor Summary
ConstructorsConstructorDescriptionVelocityWriter(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
Modifier and TypeMethodDescriptionfinal voidclear()Discard the output buffer.final voidclose()Close the stream.final voidflush()Flush the stream.intThis method returns the size of the buffer used by the JspWriter.final intbooleanThis method indicates whether the JspWriter is autoFlushing.final voidresets this class so that it can be reusedfinal voidwrite(char[] buf) Write an array of characters.final voidwrite(char[] cbuf, int off, int len) Write a portion of an array of characters.final voidwrite(int c) Write a single character.final voidWrite a string.final voidWrite a portion of a String.voidwriteReference(String ref) Send the content of a reference, e.g.; $foo, to the writer.
-
Field Details
-
NO_BUFFER
public static final int NO_BUFFERconstant indicating that the Writer is not buffering output- See Also:
-
DEFAULT_BUFFER
public static final int DEFAULT_BUFFERconstant indicating that the Writer is buffered and is using the implementation default buffer size- See Also:
-
UNBOUNDED_BUFFER
public static final int UNBOUNDED_BUFFERconstant indicating that the Writer is buffered and is unbounded; this is used in BodyContent- See Also:
-
-
Constructor Details
-
VelocityWriter
Create a buffered character-output stream that uses a default-sized output buffer.- Parameters:
writer- Writer to wrap around
-
VelocityWriter
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:
IllegalArgumentException- If sz is <= 0
-
-
Method Details
-
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
Flush the stream.- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException
-
close
Close the stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
getRemaining
public final int getRemaining()- Returns:
- the number of bytes unused in the buffer
-
write
Write a single character.- Overrides:
writein classWriter- Parameters:
c-- Throws:
IOException
-
write
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:
writein classWriter- Parameters:
cbuf- A character arrayoff- Offset from which to start reading characterslen- Number of characters to write- Throws:
IOException
-
write
Write an array of characters. This method cannot be inherited from the Writer class because it must suppress I/O exceptions.- Overrides:
writein classWriter- Parameters:
buf-- Throws:
IOException
-
write
Write a portion of a String.- Overrides:
writein classWriter- Parameters:
s- String to be writtenoff- Offset from which to start reading characterslen- Number of characters to be written- Throws:
IOException
-
write
Write a string. This method cannot be inherited from the Writer class because it must suppress I/O exceptions.- Overrides:
writein classWriter- Parameters:
s-- Throws:
IOException
-
recycle
resets this class so that it can be reused- Parameters:
writer-
-
writeReference
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:
writeReferencein interfaceFilter- Throws:
IOException
-