Class DelimitedWordReader
- java.lang.Object
-
- java.io.Reader
-
- it.unimi.dsi.io.FastBufferedReader
-
- it.unimi.dsi.io.DelimitedWordReader
-
- All Implemented Interfaces:
WordReader,Closeable,Serializable,AutoCloseable,Readable
public class DelimitedWordReader extends FastBufferedReader
A word reader that breaks words on a given set of characters.This class is a simple subclass of
FastBufferedReader. It overwritesisWordConstituent(char)so that word constituents are defined negatively by a set of delimiters defined at construction time. There is aconstructor accepting the delimiter set as a string. Note that LF and CR are always considered to be delimiters.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class it.unimi.dsi.io.FastBufferedReader
avail, buffer, bufferSize, DEFAULT_BUFFER_SIZE, pos, reader, wordConstituents
-
-
Constructor Summary
Constructors Constructor Description DelimitedWordReader(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_SIZEcharacters.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_SIZEcharacters using a given set of delimiters.DelimitedWordReader(String delimiters)Creates a new delimited word reader with a buffer ofFastBufferedReader.DEFAULT_BUFFER_SIZEcharacters.DelimitedWordReader(String bufferSize, String delimiters)Creates a new delimited word reader with a given buffer size and set of delimiters.
-
Method Summary
Modifier and Type Method Description DelimitedWordReadercopy()Returns a copy of this word reader.protected booleanisWordConstituent(char c)Returns whether the given character is a word constituent.StringtoSpec()StringtoString()-
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 Detail
-
DelimitedWordReader
public DelimitedWordReader(int bufferSize, CharSet delimiters)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
public DelimitedWordReader(CharSet delimiters)
Creates a new delimited word reader with a buffer ofFastBufferedReader.DEFAULT_BUFFER_SIZEcharacters. 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
public DelimitedWordReader(String delimiters)
Creates a new delimited word reader with a buffer ofFastBufferedReader.DEFAULT_BUFFER_SIZEcharacters. 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
public DelimitedWordReader(String bufferSize, String delimiters)
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
public 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.- 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
public DelimitedWordReader(Reader r, CharSet delimiters)
Creates a new delimited word reader by wrapping a given reader with a buffer ofFastBufferedReader.DEFAULT_BUFFER_SIZEcharacters using a given set of delimiters.- Parameters:
r- a reader to wrap.delimiters- a set of characters that will be considered word delimiters.
-
DelimitedWordReader
public DelimitedWordReader(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.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
public DelimitedWordReader(char[] array, CharSet delimiters)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
public DelimitedWordReader(MutableString s, CharSet delimiters)
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 Detail
-
isWordConstituent
protected boolean isWordConstituent(char c)
Description copied from class:FastBufferedReaderReturns whether the given character is a word constituent.The behaviour of this
FastBufferedReaderas aWordReadercan be radically changed by overwriting this method.- Overrides:
isWordConstituentin classFastBufferedReader- Parameters:
c- a character.- Returns:
- whether
cshould be considered a word constituent.
-
copy
public DelimitedWordReader copy()
Description copied from interface:WordReaderReturns 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:
copyin interfaceWordReader- Overrides:
copyin classFastBufferedReader- Returns:
- a copy of this word reader.
-
toSpec
public String toSpec()
- Overrides:
toSpecin classFastBufferedReader
-
toString
public String toString()
- Overrides:
toStringin classFastBufferedReader
-
-