it.unimi.dsi.mg4j.io
Class FastBufferedReader

java.lang.Object
  extended by java.io.Reader
      extended by it.unimi.dsi.mg4j.io.FastBufferedReader
All Implemented Interfaces:
WordReader, Closeable, Serializable, Readable

Deprecated. Moved to dsiutils.

@Deprecated
public class FastBufferedReader
extends Reader
implements WordReader

A lightweight, unsynchronised buffered reader based on mutable strings.

This class provides buffering for readers, but it does so with purposes and an internal logic that are radically different from the ones adopted in BufferedReader.

There is no support for marking. All methods are unsychronised. All methods returning strings do so by writing in a given MutableString.

Note that instances of this class can wrap an array or a mutable string. In this case, instances of this class may be used as a lightweight, unsynchronised alternative to CharArrayReader providing additional services such as word and line breaking.

As any WordReader, this class is serialisable. The only field kept is the current buffer size, which will be used to rebuild a fast buffered reader with the same buffer size. All other fields will be reset.

See Also:
Serialized Form

Field Summary
protected  int avail
          Deprecated. The number of buffer bytes available starting from pos.
protected  char[] buffer
          Deprecated. The internal buffer.
protected  int bufferSize
          Deprecated. The buffer size (must be equal to buffer.length).
static int DEFAULT_BUFFER_SIZE
          Deprecated. The default size of the internal buffer in bytes (16Ki).
protected  int pos
          Deprecated. The current position in the buffer.
protected  Reader reader
          Deprecated. The underlying reader.
static long serialVersionUID
          Deprecated.  
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
FastBufferedReader()
          Deprecated. Creates a new fast buffered reader with a buffer of DEFAULT_BUFFER_SIZE characters.
FastBufferedReader(char[] array)
          Deprecated. Creates a new fast buffered reader by wrapping a given character array.
FastBufferedReader(char[] array, int offset, int length)
          Deprecated. Creates a new fast buffered reader by wrapping a given fragment of a character array.
FastBufferedReader(int bufferSize)
          Deprecated. Creates a new fast buffered reader with a given buffer size.
FastBufferedReader(MutableString s)
          Deprecated. Creates a new fast buffered reader by wrapping a given mutable string.
FastBufferedReader(Reader r)
          Deprecated. Creates a new fast buffered reader by wrapping a given reader with a buffer of DEFAULT_BUFFER_SIZE characters.
FastBufferedReader(Reader r, int bufferSize)
          Deprecated. Creates a new fast buffered reder by wrapping a given reder with a given buffer size.
 
Method Summary
 void close()
          Deprecated.  
 FastBufferedReader copy()
          Deprecated. Returns a copy of this word reader.
 boolean next(MutableString word, MutableString nonWord)
          Deprecated. Extracts the next word and non-word.
protected  boolean noMoreCharacters()
          Deprecated. Checks whether no more characters will be returned.
 int read()
          Deprecated.  
 int read(char[] b, int offset, int length)
          Deprecated.  
 MutableString readLine(MutableString s)
          Deprecated. Reads a line into the given mutable string.
 FastBufferedReader setReader(Reader reader)
          Deprecated. Resets the internal state of this word reader, which will start again reading from the given reader.
 long skip(long n)
          Deprecated.  
 
Methods inherited from class java.io.Reader
mark, markSupported, read, read, ready, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
Deprecated. 
See Also:
Constant Field Values

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
Deprecated. 
The default size of the internal buffer in bytes (16Ki).

See Also:
Constant Field Values

bufferSize

protected final int bufferSize
Deprecated. 
The buffer size (must be equal to buffer.length).


buffer

protected transient char[] buffer
Deprecated. 
The internal buffer.


pos

protected transient int pos
Deprecated. 
The current position in the buffer.


avail

protected transient int avail
Deprecated. 
The number of buffer bytes available starting from pos.


reader

protected transient Reader reader
Deprecated. 
The underlying reader.

Constructor Detail

FastBufferedReader

public FastBufferedReader(int bufferSize)
Deprecated. 
Creates a new fast buffered reader with a given buffer size. The wrapped reader will have to be set later using setReader(Reader).

Parameters:
bufferSize - the size in bytes of the internal buffer.

FastBufferedReader

public FastBufferedReader()
Deprecated. 
Creates a new fast buffered reader with a buffer of DEFAULT_BUFFER_SIZE characters. The wrapped reader will have to be set later using setReader(Reader).


FastBufferedReader

public FastBufferedReader(Reader r,
                          int bufferSize)
Deprecated. 
Creates a new fast buffered reder by wrapping a given reder with a given buffer size.

Parameters:
r - a reader to wrap.
bufferSize - the size in bytes of the internal buffer.

FastBufferedReader

public FastBufferedReader(Reader r)
Deprecated. 
Creates a new fast buffered reader by wrapping a given reader with a buffer of DEFAULT_BUFFER_SIZE characters.

Parameters:
r - a reader to wrap.

FastBufferedReader

public FastBufferedReader(char[] array,
                          int offset,
                          int length)
Deprecated. 
Creates a new fast buffered reader by wrapping a given fragment of a character array.

The effect of setReader(Reader) on a buffer created with this constructor is undefined.

Parameters:
array - the array that will be wrapped by the reader.
offset - the first character to be used.
length - the number of character to be used.

FastBufferedReader

public FastBufferedReader(char[] array)
Deprecated. 
Creates a new fast buffered reader by wrapping a given character array.

The effect of setReader(Reader) on a buffer created with this constructor is undefined.

Parameters:
array - the array that will be wrapped by the reader.

FastBufferedReader

public FastBufferedReader(MutableString s)
Deprecated. 
Creates a new fast buffered reader by wrapping a given mutable string.

The effect of setReader(Reader) on a buffer created with this constructor is undefined.

Parameters:
s - the mutable string that will be wrapped by the reader.
Method Detail

copy

public FastBufferedReader copy()
Deprecated. 
Description copied from interface: WordReader
Returns a copy of this word reader.

This method must return a word reader with a behaviour that matches exactly that of this word reader.

Specified by:
copy in interface WordReader
Returns:
a copy of this word reader.

noMoreCharacters

protected boolean noMoreCharacters()
                            throws IOException
Deprecated. 
Checks whether no more characters will be returned.

Returns:
true if there are no characters in the internal buffer and the underlying reader is exhausted.
Throws:
IOException

read

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

read

public int read(char[] b,
                int offset,
                int length)
         throws IOException
Deprecated. 
Specified by:
read in class Reader
Throws:
IOException

readLine

public MutableString readLine(MutableString s)
                       throws IOException
Deprecated. 
Reads a line into the given mutable string.

The next line of input (defined as in BufferedReader.readLine()) will be stored into s. Note that if s is not loose this method will be quite inefficient.

Parameters:
s - a mutable string that will be used to store the next line (which could be empty).
Returns:
s, or null if the end of file was found, in which case s is unchanged.
Throws:
IOException

next

public boolean next(MutableString word,
                    MutableString nonWord)
             throws IOException
Deprecated. 
Description copied from interface: WordReader
Extracts the next word and non-word.

If this method returns true, a new non-empty word, and possibly a new non-word, have been extracted. It is acceptable that the first call to this method after creation or after a call to WordReader.setReader(Reader) returns an empty word. In other words both word and nonWord are maximal.

Specified by:
next in interface WordReader
Parameters:
word - the next word returned by the underlying reader.
nonWord - the nonword following the next word returned by the underlying reader.
Returns:
true if a new word was processed, false otherwise (in which case both word and nonWord are unchanged).
Throws:
IOException

setReader

public FastBufferedReader setReader(Reader reader)
Deprecated. 
Description copied from interface: WordReader
Resets the internal state of this word reader, which will start again reading from the given reader.

Specified by:
setReader in interface WordReader
Parameters:
reader - the new reader providing characters.
Returns:
this word reader.

skip

public long skip(long n)
          throws IOException
Deprecated. 
Overrides:
skip in class Reader
Throws:
IOException

close

public void close()
           throws IOException
Deprecated. 
Specified by:
close in interface Closeable
Specified by:
close in class Reader
Throws:
IOException