com.ibm.commons.util.io
Class CharacterStreamCache

java.lang.Object
  extended by com.ibm.commons.util.io.CharacterStreamCache

public class CharacterStreamCache
extends java.lang.Object

Characters buffer.

This class is used to store characters and provides both an Writer for storing the bytes and an Reader for reading them. It stores the characters in memory in a highly optimized way, with a possibility of using a backing file when the content is bigger than a predefined threshold.


Nested Class Summary
protected  class CharacterStreamCache.InternalReader
           
protected  class CharacterStreamCache.InternalWriter
           
 
Field Summary
static int DEFAULT_BLOCKSIZE
           
static int DEFAULT_THRESHOLD
           
 
Constructor Summary
CharacterStreamCache()
           
CharacterStreamCache(int blockSize, int threshold)
           
 
Method Summary
 void clear()
          Clear the data inside the cache.
 void copyFrom(java.io.Reader r)
          Init the data from an existing reader.
 void copyTo(java.io.File f)
          Copy the stream to a file.
 void copyTo(java.io.Writer w)
          Copy the stream to another stream.
 char getChar(int pos)
          Get an indexed character.
 long getLength()
          Get the number of stored bytes.
 java.io.Reader getReader()
          Get a reader on the stored data.
 java.io.Writer getWriter()
          Get a writer to store the data.
 boolean isEqual(CharacterStreamCache other)
           
 char[] toCharArray()
          Convert to a char array.
 java.lang.String toString()
           
 void write(char[] b)
           
 void write(char[] b, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_BLOCKSIZE

public static final int DEFAULT_BLOCKSIZE
See Also:
Constant Field Values

DEFAULT_THRESHOLD

public static final int DEFAULT_THRESHOLD
See Also:
Constant Field Values
Constructor Detail

CharacterStreamCache

public CharacterStreamCache()

CharacterStreamCache

public CharacterStreamCache(int blockSize,
                            int threshold)
Method Detail

isEqual

public boolean isEqual(CharacterStreamCache other)

getLength

public long getLength()
Get the number of stored bytes.


getChar

public char getChar(int pos)
Get an indexed character.


clear

public void clear()
Clear the data inside the cache.


getReader

public java.io.Reader getReader()
Get a reader on the stored data.


getWriter

public java.io.Writer getWriter()
Get a writer to store the data.


copyFrom

public void copyFrom(java.io.Reader r)
              throws java.io.IOException
Init the data from an existing reader.

Throws:
java.io.IOException

copyTo

public void copyTo(java.io.Writer w)
            throws java.io.IOException
Copy the stream to another stream.

Throws:
java.io.IOException

copyTo

public void copyTo(java.io.File f)
            throws java.io.IOException
Copy the stream to a file.

Throws:
java.io.IOException

toCharArray

public char[] toCharArray()
Convert to a char array. WARN: this fct is *not* really optimized!


toString

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

write

public final void write(int b)
                 throws java.io.IOException
Throws:
java.io.IOException

write

public final void write(char[] b)
                 throws java.io.IOException
Throws:
java.io.IOException

write

public final void write(char[] b,
                        int off,
                        int len)
                 throws java.io.IOException
Throws:
java.io.IOException