org.webmacro.util
Class QueueWriter

java.lang.Object
  |
  +--java.io.Writer
        |
        +--org.webmacro.util.QueueWriter

public final class QueueWriter
extends java.io.Writer

This writer buffers characters into a char array. Also, if you pass it a char array, it queues it into a queue of char array. The goal is to handle string processing with as little copying as possible. You can reset it and re-use the same local buffer to avoid a malloc as well.

UNSYNCHRONIZED: It is not safe to use this writer from multiple threads. It is an unsynchronized writer. It is intended for use in WebMacro, where only one thread exists within a single request, and is also the only thread with access to mutable data.


Fields inherited from class java.io.Writer
lock
 
Constructor Summary
QueueWriter()
          Create a new Writer
QueueWriter(int defaultSize)
          Create a new buffer.
 
Method Summary
 void close()
          Does nothing
 void flush()
          Does nothing
static void main(java.lang.String[] arg)
           
 void reset()
          Reset the buffer so it can be used again
 int size()
          Return the total number of characters stored in the buffer
 java.lang.String toString()
           
 void write(char[] c, int off, int len)
          Write the c[] array to the local buffer for later writing out.
 void write(int c)
          Write a character to the buffer
 void write(java.lang.String str, int off, int len)
           
 void writeTo(java.io.Writer out)
           
 
Methods inherited from class java.io.Writer
write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QueueWriter

public QueueWriter()
Create a new Writer

QueueWriter

public QueueWriter(int defaultSize)
Create a new buffer. The integer argument is the expected number of bytes locally written
Method Detail

write

public void write(char[] c,
                  int off,
                  int len)
Write the c[] array to the local buffer for later writing out. Note that this copies a reference. Subsequent changes to c *will* be reflected in the output.
Overrides:
write in class java.io.Writer

write

public void write(int c)
Write a character to the buffer
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

toString

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

writeTo

public void writeTo(java.io.Writer out)
             throws java.io.IOException

size

public int size()
Return the total number of characters stored in the buffer

reset

public void reset()
Reset the buffer so it can be used again

flush

public void flush()
Does nothing
Overrides:
flush in class java.io.Writer

close

public void close()
Does nothing
Overrides:
close in class java.io.Writer

main

public static void main(java.lang.String[] arg)
                 throws java.lang.Exception