Package org.daisy.dotify.common.text
Class TextFileReader
- java.lang.Object
-
- org.daisy.dotify.common.text.TextFileReader
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class TextFileReader extends Object implements Closeable
Provides a simple tool to read text files with multiple fields on each row, such as csv-files.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TextFileReader.Builder
Provides a builder for a text file reader.class
TextFileReader.LineData
Provides the data about a single line.
-
Constructor Summary
Constructors Constructor Description TextFileReader(InputStream is)
Creates a new TextFileReader with the default encoding and field separator.TextFileReader(InputStream is, Charset cs)
Creates a new TextFileReader with the default field separator.TextFileReader(InputStream is, Charset cs, String regex, int limit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
TextFileReader.LineData
nextLine()
Gets the next line in the stream.
-
-
-
Constructor Detail
-
TextFileReader
public TextFileReader(InputStream is)
Creates a new TextFileReader with the default encoding and field separator.- Parameters:
is
- the input stream to read.
-
TextFileReader
public TextFileReader(InputStream is, Charset cs)
Creates a new TextFileReader with the default field separator.- Parameters:
is
- the input stream to read.cs
- the charset to use
-
TextFileReader
public TextFileReader(InputStream is, Charset cs, String regex, int limit)
- Parameters:
is
- the input streamcs
- the encodingregex
- field delimiter expressionlimit
- the maximum number of times the regex is matched
-
-
Method Detail
-
nextLine
public TextFileReader.LineData nextLine() throws IOException
Gets the next line in the stream.- Returns:
- returns next line, or null if there are no more lines
- Throws:
IOException
- if an IO-problem occurs
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
-