de.rw7.token
Class FastInput

java.lang.Object
  |
  +--de.rw7.token.FastInput

public class FastInput
extends java.lang.Object

No concurrency for this and is;


Inner Class Summary
 class FastInput.EndException
          This exception is thrown by any method accessing the input stream, when the end of stream is reached.
 
Field Summary
private  int blocksread
          Number of bytes read without the currently loaded buffer.
private  byte[] buf
           
private  byte[] buf_bak
           
private  java.io.InputStream is
          The input stream.
private  int len
          Valid bytes in buffer.
private static int minimumBytesToRead
          The number bytes at least to be read on every readBuffer call.
private  int nbuf
           
private  int now
          The current byte in buffer, next to be read.
 
Constructor Summary
FastInput()
          Constructs a FastInput instance with default buffer size of 4kB.
FastInput(java.io.InputStream is)
          Constructs a FastInput instance with default buffer size of 4kB and opens it with the given InputStream.
FastInput(int nbuf)
          Constructs a FastInput instance with custom buffer size.
 
Method Summary
 void close()
          Closes the input stream.
 int getBytesRead()
           
 void open(java.io.InputStream is)
          Opens the FastInput object.
 char peek()
          Reads a single character from the stream without moving the file pointer.
 void pushBack()
          Moves the file pointer back by one character. pushBack() is available only for one character.
 char read()
          Reads a single character from the stream.
private  void readBuffer()
          Reads a new buffer.
 void skipUntil(byte c)
          Skips input until the first occurence of the given character.
 char skipUntil(byte c1, byte c2)
          Skips input until the first occurence of one of the two given characters.
 char skipUntil(byte c1, byte c2, byte c3)
          Skips input until the first occurence of one of the three given characters.
 char skipUntil(byte c1, byte c2, byte c3, byte c4)
          Skips input until the first occurence of one of the four given characters.
 void skipWhile(byte c)
          Skips input for all subsequent occurences of the given character.
 java.lang.String toString()
          Return a string showing the file pointer as a pipeline character in the context of the characters in the stream.
 CharNode traverse(CharNode n)
          The file pointer stops before the first character which not in the tree.
 
Methods inherited from class java.lang.Object
<clinit>, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

is

private java.io.InputStream is
The input stream. Is null after close().
See Also:
close()

nbuf

private int nbuf

buf

private byte[] buf

buf_bak

private byte[] buf_bak

blocksread

private int blocksread
Number of bytes read without the currently loaded buffer.

len

private int len
Valid bytes in buffer. There may be read at least len-now bytes without IO access.

now

private int now
The current byte in buffer, next to be read. The class ensures, that now is not zero, whenever pushBack is allowed.
See Also:
pushBack()

minimumBytesToRead

private static final int minimumBytesToRead
The number bytes at least to be read on every readBuffer call. If there are less bytes available in the stream, readBuffer blocks.
See Also:
readBuffer()
Constructor Detail

FastInput

public FastInput(java.io.InputStream is)
Constructs a FastInput instance with default buffer size of 4kB and opens it with the given InputStream.
See Also:
open(java.io.InputStream)

FastInput

public FastInput()
Constructs a FastInput instance with default buffer size of 4kB. You must call open before using this instance.
See Also:
open(java.io.InputStream)

FastInput

public FastInput(int nbuf)
Constructs a FastInput instance with custom buffer size. You must call open before using this instance.
See Also:
open(java.io.InputStream)
Method Detail

open

public final void open(java.io.InputStream is)
Opens the FastInput object. This means, the FastInput object is bound to an input stream.
Throws:
java.lang.IllegalArgumentException - if the FastInput object is already open.
See Also:
close()

close

public final void close()
                 throws java.io.IOException
Closes the input stream. Does nothing if already closed. A closed FastInput object may be opened with another input stream. In this case the allocated buffer is reused.
See Also:
open(java.io.InputStream)

readBuffer

private final void readBuffer()
                       throws java.io.IOException,
                              FastInput.EndException
Reads a new buffer. Do not call this method, when the last character in the current buffer has been read, but when the first character not in the current buffer gets read. Simply speaking, after calling readBuffer() you must read at least one character from buffer, so that you leave a non-zero buffer pointer.
See Also:
pushBack()

getBytesRead

public final int getBytesRead()

pushBack

public final void pushBack()
Moves the file pointer back by one character. pushBack() is available only for one character. Thus pushBack() is not available immediatly after pushBack(), skipWhile() and construction.

There is no explicit pushback buffer. The buffer pointer (now) simply gets decreased by one. The class ensures, that the buffer pointer is not zero outside of public methods, whenever pushBack() is available.

See Also:
skipWhile(byte)

read

public final char read()
                throws java.io.IOException,
                       FastInput.EndException
Reads a single character from the stream. This method makes pushback available again.
See Also:
pushBack()

peek

public final char peek()
                throws java.io.IOException,
                       FastInput.EndException
Reads a single character from the stream without moving the file pointer. This method leaves no pushback buffer!
See Also:
pushBack()

skipUntil

public final void skipUntil(byte c)
                     throws java.io.IOException,
                            FastInput.EndException
Skips input until the first occurence of the given character. The file pointer stops immediatly after this occurence. This method makes pushback available again.
See Also:
pushBack()

skipUntil

public final char skipUntil(byte c1,
                            byte c2)
                     throws java.io.IOException,
                            FastInput.EndException
Skips input until the first occurence of one of the two given characters. The file pointer stops immediatly after this occurence.
Returns:
the character matched This method makes pushback available again.
See Also:
pushBack()

skipUntil

public final char skipUntil(byte c1,
                            byte c2,
                            byte c3)
                     throws java.io.IOException,
                            FastInput.EndException
Skips input until the first occurence of one of the three given characters. The file pointer stops immediatly after this occurence.
Returns:
the character matched This method makes pushback available again.
See Also:
pushBack()

skipUntil

public final char skipUntil(byte c1,
                            byte c2,
                            byte c3,
                            byte c4)
                     throws java.io.IOException,
                            FastInput.EndException
Skips input until the first occurence of one of the four given characters. The file pointer stops immediatly after this occurence.
Returns:
the character matched This method makes pushback available again.
See Also:
pushBack()

skipWhile

public final void skipWhile(byte c)
                     throws java.io.IOException,
                            FastInput.EndException
Skips input for all subsequent occurences of the given character. The file pointer stops before at the first mismatch. This method leaves no pushback buffer.
See Also:
pushBack()

traverse

public final CharNode traverse(CharNode n)
                        throws java.io.IOException,
                               FastInput.EndException
The file pointer stops before the first character which not in the tree. This method leaves no pushback buffer!
See Also:
pushBack()

toString

public final java.lang.String toString()
Return a string showing the file pointer as a pipeline character in the context of the characters in the stream. Useful for debugging.
Overrides:
toString in class java.lang.Object