org.apache.derbyTesting.functionTests.util.streams
Class LoopingAlphabetReader

java.lang.Object
  extended by java.io.Reader
      extended by org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable

public class LoopingAlphabetReader
extends java.io.Reader

A stream returning characters by looping over an alphabet.


Field Summary
private  CharAlphabet alphabet
          The alphabet to draw letters from.
private  char[] buffer
          Internal buffer of characters.
private  boolean closed
          Tell if the reader is closed or not.
private  long length
          Number of characters in the reader.
private static int MAX_BUF_SIZE
          Maximum size of buffer.
private  long remainingBlanks
          Remaining blanks.
private  long remainingNonBlanks
          Remaining non-blank characters.
private static int SPACE
          The character used for blanks (SPACE).
private  int trailingBlanks
          Number of blanks at the end of stream.
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
LoopingAlphabetReader(long length)
          Create a looping modern latin alphabet reader of the specified length.
LoopingAlphabetReader(long length, CharAlphabet alphabet)
          Create a looping alphabet of the specified type and length.
LoopingAlphabetReader(long length, CharAlphabet alphabet, int trailingBlanks)
          Create a looping alphabet of the specified type and length, with the specified number of trailing blanks.
LoopingAlphabetReader(long length, int trailingBlanks)
          Create a looping modern latin alphabet of the specified length, with the specified number of trailing blanks.
 
Method Summary
 int available()
          Return remaining characters in the stream.
 void close()
          Close the reader.
private  void ensureOpen()
          Ensure reader is open.
private  int fillBlanks(char[] buf, int off, int length)
          Fill array with blanks (SPACE).
private  void fillBuffer(int bufSize)
          Fill internal buffer of character sequence.
 int read()
           
 int read(char[] buf, int off, int length)
           
 void reset()
          Reset the stream.
 
Methods inherited from class java.io.Reader
mark, markSupported, read, read, ready, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_BUF_SIZE

private static final int MAX_BUF_SIZE
Maximum size of buffer. Balance between size and memory usage.

See Also:
Constant Field Values

SPACE

private static final int SPACE
The character used for blanks (SPACE).

See Also:
Constant Field Values

length

private final long length
Number of characters in the reader.


trailingBlanks

private final int trailingBlanks
Number of blanks at the end of stream.


remainingNonBlanks

private long remainingNonBlanks
Remaining non-blank characters.


remainingBlanks

private long remainingBlanks
Remaining blanks.


buffer

private char[] buffer
Internal buffer of characters. Used by the read-methods with a char[] argument.


alphabet

private final CharAlphabet alphabet
The alphabet to draw letters from.


closed

private boolean closed
Tell if the reader is closed or not.

Constructor Detail

LoopingAlphabetReader

public LoopingAlphabetReader(long length)
Create a looping modern latin alphabet reader of the specified length.

Parameters:
length - the number of characters

LoopingAlphabetReader

public LoopingAlphabetReader(long length,
                             int trailingBlanks)
Create a looping modern latin alphabet of the specified length, with the specified number of trailing blanks. The number of non-blank characters is length - trailingBlanks.

Parameters:
length - total number of characters
trailingBlanks - number of blank characters at the end

LoopingAlphabetReader

public LoopingAlphabetReader(long length,
                             CharAlphabet alphabet)
Create a looping alphabet of the specified type and length.

Parameters:
length - the number of chars in the reader
alphabet - the alphabet to loop over

LoopingAlphabetReader

public LoopingAlphabetReader(long length,
                             CharAlphabet alphabet,
                             int trailingBlanks)
Create a looping alphabet of the specified type and length, with the specified number of trailing blanks. The number of non-blank characters is length - trailingBlanks.

Parameters:
length - total number of characters
alphabet - the alphabet to draw characters from
trailingBlanks - number of blank characters at the end
Method Detail

read

public int read()
         throws java.io.IOException
Overrides:
read in class java.io.Reader
Throws:
java.io.IOException

read

public int read(char[] buf,
                int off,
                int length)
         throws java.io.IOException
Specified by:
read in class java.io.Reader
Throws:
java.io.IOException

reset

public void reset()
           throws java.io.IOException
Reset the stream.

Overrides:
reset in class java.io.Reader
Throws:
java.io.IOException

available

public int available()
Return remaining characters in the stream.


close

public void close()
Close the reader.

Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Reader

fillBuffer

private void fillBuffer(int bufSize)
Fill internal buffer of character sequence.

Parameters:
bufSize - the wanted size, might be ignored if too big

fillBlanks

private int fillBlanks(char[] buf,
                       int off,
                       int length)
Fill array with blanks (SPACE).

Parameters:
buf - array to fill
off - starting offset
length - maximum number of blanks to fill in

ensureOpen

private final void ensureOpen()
                       throws java.io.IOException
Ensure reader is open.

Throws:
java.io.IOException - if reader is closed

Built on Wed 2009-11-25 18:43:31-0800, from revision 884373

Apache Derby V10.6 Internals - Copyright © 2004,2008 The Apache Software Foundation. All Rights Reserved.