org.japano
Class Buffer

java.lang.Object
  extended by java.io.Writer
      extended by javax.servlet.jsp.JspWriter
          extended by org.japano.Buffer
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable

public class Buffer
extends javax.servlet.jsp.JspWriter

Collects String object references and finally flushes them to a Writer.

Version:
$Id: Buffer.java,v 1.13 2005/12/30 15:54:02 fforw Exp $ SourceForge.net Logo
Author:
Sven Helmberger ( sven dot helmberger at gmx dot de )

Field Summary
static int DEFAULT_CAPACITY
          default capacity counted in String objects
 
Fields inherited from class javax.servlet.jsp.JspWriter
autoFlush, bufferSize, DEFAULT_BUFFER, NO_BUFFER, UNBOUNDED_BUFFER
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
Buffer()
          Creates a new instance of Buffer with default capacity,
Buffer(int capacity)
          Creates a new instance of Buffer with given capacity.
 
Method Summary
 void clear()
          Clears the Buffer.
 void clearBuffer()
           
 void close()
           
 void ensureCapacity(int capacity)
          Ensures that the Buffer has enough capacity for the given amount of String objects.
 void flush()
          Flushes all collected Strings
 int getCapacity()
          Gets the current capacity in String objects (NOT character)
 int getRemaining()
           
 void insert(Buffer b, int offset)
           
 void insertInHead(Buffer b)
          Inserts the given buffer content into the page's head section
 int length()
          Returns the length of the buffer content (not the fragment count).
 void newLine()
           
 void print(boolean param)
           
 void print(char param)
           
 void print(char[] values)
           
 void print(double param)
           
 void print(float param)
           
 void print(int param)
           
 void print(long param)
           
 void print(java.lang.Object obj)
           
 void print(java.lang.String str)
           
 void println()
           
 void println(boolean param)
           
 void println(char param)
           
 void println(char[] values)
           
 void println(double param)
           
 void println(float param)
           
 void println(int param)
           
 void println(long param)
           
 void println(java.lang.Object obj)
           
 void println(java.lang.String str)
           
 void printNode(java.lang.Object o)
           
 void setHeadMarker()
           
 void setSize(int size)
          Cuts the length of the buffer to the given fragment count.
 void setWriter(java.io.Writer writer)
          Sets the writer this buffer flushes to.
 int size()
           
 java.lang.String substring(int start, int end)
          Returns a substring of the buffer starting with the given fragment position and ending at the given fragment position.
 java.lang.String toString()
           
 void write(char[] cbuf)
           
 void write(char[] cbuf, int off, int len)
           
 void write(int c)
           
 void write(java.lang.String str)
           
 void write(java.lang.String str, int off, int len)
           
 
Methods inherited from class javax.servlet.jsp.JspWriter
getBufferSize, isAutoFlush
 
Methods inherited from class java.io.Writer
append, append, append
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_CAPACITY

public static final int DEFAULT_CAPACITY
default capacity counted in String objects

See Also:
Constant Field Values
Constructor Detail

Buffer

public Buffer()
Creates a new instance of Buffer with default capacity,


Buffer

public Buffer(int capacity)
Creates a new instance of Buffer with given capacity.

Parameters:
capacity - capacity counted in string fragments ( not characters!). if this is 0 the allocation of the string array will be defered until the first access to buffer (with print or ensureCapacity(int))
Method Detail

setWriter

public void setWriter(java.io.Writer writer)
Sets the writer this buffer flushes to.

Parameters:
writer - Writer

ensureCapacity

public void ensureCapacity(int capacity)
Ensures that the Buffer has enough capacity for the given amount of String objects.

Parameters:
capacity - Capacity in String objects (NOT character)

getCapacity

public int getCapacity()
Gets the current capacity in String objects (NOT character)

Returns:
capacity in String objects (NOT character)

clear

public void clear()
Clears the Buffer.

Specified by:
clear in class javax.servlet.jsp.JspWriter

flush

public void flush()
           throws java.io.IOException
Flushes all collected Strings

Specified by:
flush in interface java.io.Flushable
Specified by:
flush in class javax.servlet.jsp.JspWriter
Throws:
java.io.IOException

getRemaining

public int getRemaining()
Specified by:
getRemaining in class javax.servlet.jsp.JspWriter

print

public void print(java.lang.String str)
Specified by:
print in class javax.servlet.jsp.JspWriter

substring

public java.lang.String substring(int start,
                                  int end)
Returns a substring of the buffer starting with the given fragment position and ending at the given fragment position.

Parameters:
start - position of the first fragment
end - position of the last fragment plus one.

length

public int length()
Returns the length of the buffer content (not the fragment count).

Returns:
length in characters

newLine

public void newLine()
Specified by:
newLine in class javax.servlet.jsp.JspWriter

print

public void print(char[] values)
Specified by:
print in class javax.servlet.jsp.JspWriter

print

public void print(int param)
Specified by:
print in class javax.servlet.jsp.JspWriter

print

public void print(boolean param)
Specified by:
print in class javax.servlet.jsp.JspWriter

print

public void print(char param)
Specified by:
print in class javax.servlet.jsp.JspWriter

print

public void print(float param)
Specified by:
print in class javax.servlet.jsp.JspWriter

print

public void print(java.lang.Object obj)
Specified by:
print in class javax.servlet.jsp.JspWriter

print

public void print(long param)
Specified by:
print in class javax.servlet.jsp.JspWriter

print

public void print(double param)
Specified by:
print in class javax.servlet.jsp.JspWriter

println

public void println()
Specified by:
println in class javax.servlet.jsp.JspWriter

println

public void println(float param)
Specified by:
println in class javax.servlet.jsp.JspWriter

println

public void println(java.lang.Object obj)
Specified by:
println in class javax.servlet.jsp.JspWriter

println

public void println(int param)
Specified by:
println in class javax.servlet.jsp.JspWriter

println

public void println(char param)
Specified by:
println in class javax.servlet.jsp.JspWriter

println

public void println(boolean param)
Specified by:
println in class javax.servlet.jsp.JspWriter

println

public void println(long param)
Specified by:
println in class javax.servlet.jsp.JspWriter

println

public void println(double param)
Specified by:
println in class javax.servlet.jsp.JspWriter

println

public void println(java.lang.String str)
Specified by:
println in class javax.servlet.jsp.JspWriter

println

public void println(char[] values)
Specified by:
println in class javax.servlet.jsp.JspWriter

write

public void write(char[] cbuf)
Overrides:
write in class java.io.Writer

write

public void write(char[] cbuf,
                  int off,
                  int len)
Specified by:
write in class java.io.Writer

write

public void write(int c)
Overrides:
write in class java.io.Writer

write

public void write(java.lang.String str)
Overrides:
write in class java.io.Writer

write

public void write(java.lang.String str,
                  int off,
                  int len)
Overrides:
write in class java.io.Writer

clearBuffer

public void clearBuffer()
Specified by:
clearBuffer in class javax.servlet.jsp.JspWriter

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Specified by:
close in class javax.servlet.jsp.JspWriter
Throws:
java.io.IOException

size

public int size()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setHeadMarker

public void setHeadMarker()

insertInHead

public void insertInHead(Buffer b)
Inserts the given buffer content into the page's head section


insert

public void insert(Buffer b,
                   int offset)

setSize

public void setSize(int size)
Cuts the length of the buffer to the given fragment count.


printNode

public void printNode(java.lang.Object o)