Class DelimitedWordReader
- All Implemented Interfaces:
WordReader
,Closeable
,Serializable
,AutoCloseable
,Readable
This class is a simple subclass of FastBufferedReader
. It
overwrites isWordConstituent(char)
so that word constituents
are defined negatively by a set of delimiters defined at construction time.
There is a constructor
accepting the delimiter set as a string
. Note that LF and CR are always considered to be delimiters.
- See Also:
-
Field Summary
Fields inherited from class it.unimi.dsi.io.FastBufferedReader
avail, buffer, bufferSize, DEFAULT_BUFFER_SIZE, pos, reader, wordConstituents
-
Constructor Summary
ConstructorDescriptionDelimitedWordReader
(char[] array, int offset, int length, CharSet delimiters) Creates a new delimited word reader by wrapping a given fragment of a character array and using a set delimiters.DelimitedWordReader
(char[] array, CharSet delimiters) Creates a new delimited word reader by wrapping a given character array and using a set delimiters.DelimitedWordReader
(int bufferSize, CharSet delimiters) Creates a new delimited word reader with a given buffer size and set of delimiters.DelimitedWordReader
(CharSet delimiters) Creates a new delimited word reader with a buffer ofFastBufferedReader.DEFAULT_BUFFER_SIZE
characters.DelimitedWordReader
(MutableString s, CharSet delimiters) Creates a new delimited word reader by wrapping a given mutable string and using a set of delimiters.DelimitedWordReader
(Reader r, int bufferSize, CharSet delimiters) Creates a new delimited word reader by wrapping a given reader with a given buffer size and using a set of delimiters.DelimitedWordReader
(Reader r, CharSet delimiters) Creates a new delimited word reader by wrapping a given reader with a buffer ofFastBufferedReader.DEFAULT_BUFFER_SIZE
characters using a given set of delimiters.DelimitedWordReader
(String delimiters) Creates a new delimited word reader with a buffer ofFastBufferedReader.DEFAULT_BUFFER_SIZE
characters.DelimitedWordReader
(String bufferSize, String delimiters) Creates a new delimited word reader with a given buffer size and set of delimiters. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Returns a copy of this word reader.protected boolean
isWordConstituent
(char c) Returns whether the given character is a word constituent.toSpec()
toString()
Methods inherited from class it.unimi.dsi.io.FastBufferedReader
close, next, noMoreCharacters, read, read, readLine, setReader, skip
Methods inherited from class java.io.Reader
mark, markSupported, nullReader, read, read, ready, reset, transferTo
-
Constructor Details
-
DelimitedWordReader
Creates a new delimited word reader with a given buffer size and set of delimiters. The wrapped reader will have to be set later usingFastBufferedReader.setReader(Reader)
.- Parameters:
bufferSize
- the size in bytes of the internal buffer.delimiters
- a set of characters that will be considered word delimiters.
-
DelimitedWordReader
Creates a new delimited word reader with a buffer ofFastBufferedReader.DEFAULT_BUFFER_SIZE
characters. The wrapped reader will have to be set later usingFastBufferedReader.setReader(Reader)
.- Parameters:
delimiters
- a set of characters that will be considered word delimiters.
-
DelimitedWordReader
Creates a new delimited word reader with a buffer ofFastBufferedReader.DEFAULT_BUFFER_SIZE
characters. The wrapped reader will have to be set later usingFastBufferedReader.setReader(Reader)
.Warning: it is easy to mistake this method for one whose semantics is the same as
FastBufferedReader(MutableString)
, that is, wrapping the argument string in a reader.- Parameters:
delimiters
- a set of characters that will be considered word delimiters, specified as a string.
-
DelimitedWordReader
Creates a new delimited word reader with a given buffer size and set of delimiters. The wrapped reader will have to be set later usingFastBufferedReader.setReader(Reader)
.- Parameters:
bufferSize
- the size in bytes of the internal buffer, specified as a string.delimiters
- a set of characters that will be considered word delimiters, specified as a string.
-
DelimitedWordReader
Creates a new delimited word reader by wrapping a given reader with a given buffer size and using a set of delimiters.- Parameters:
r
- a reader to wrap.bufferSize
- the size in bytes of the internal buffer.delimiters
- a set of characters that will be considered word delimiters.
-
DelimitedWordReader
Creates a new delimited word reader by wrapping a given reader with a buffer ofFastBufferedReader.DEFAULT_BUFFER_SIZE
characters using a given set of delimiters.- Parameters:
r
- a reader to wrap.delimiters
- a set of characters that will be considered word delimiters.
-
DelimitedWordReader
Creates a new delimited word reader by wrapping a given fragment of a character array and using a set delimiters.The effect of
FastBufferedReader.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.delimiters
- a set of characters that will be considered word delimiters.
-
DelimitedWordReader
Creates a new delimited word reader by wrapping a given character array and using a set delimiters.The effect of
FastBufferedReader.setReader(Reader)
on a buffer created with this constructor is undefined.- Parameters:
array
- the array that will be wrapped by the reader.delimiters
- a set of characters that will be considered word delimiters.
-
DelimitedWordReader
Creates a new delimited word reader by wrapping a given mutable string and using a set of delimiters.The effect of
FastBufferedReader.setReader(Reader)
on a buffer created with this constructor is undefined.- Parameters:
s
- the mutable string that will be wrapped by the reader.delimiters
- a set of characters that will be considered word delimiters.
-
-
Method Details
-
isWordConstituent
protected boolean isWordConstituent(char c) Description copied from class:FastBufferedReader
Returns whether the given character is a word constituent.The behaviour of this
FastBufferedReader
as aWordReader
can be radically changed by overwriting this method.- Overrides:
isWordConstituent
in classFastBufferedReader
- Parameters:
c
- a character.- Returns:
- whether
c
should be considered a word constituent.
-
copy
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 interfaceWordReader
- Overrides:
copy
in classFastBufferedReader
- Returns:
- a copy of this word reader.
-
toSpec
- Overrides:
toSpec
in classFastBufferedReader
-
toString
- Overrides:
toString
in classFastBufferedReader
-