|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.Reader
java.io.InputStreamReader
org.pfsw.text.TextFileReader
public class TextFileReader
Convenience class for reading text files.
In contrary to FileReader the constructors of this class support defining
character encoding.
TextFileReader is meant for reading streams of characters.
For reading streams of raw bytes, consider using a FileInputStream.
InputStreamReader,
FileInputStream,
FileReader| Field Summary | |
|---|---|
static java.nio.charset.Charset |
DEFAULT_CHARSET
The default character encoding used by this class. |
| Fields inherited from class java.io.Reader |
|---|
lock |
| Constructor Summary | |
|---|---|
TextFileReader(java.io.File file)
Creates a new TextFileReader, given the File to read from with the default character encoding (UTF-8) of this class. |
|
TextFileReader(java.io.File file,
java.nio.charset.Charset charset)
Creates a new TextFileReader, given the File to read from with the encoding specified by the given charset. |
|
TextFileReader(java.lang.String filename)
Creates a new TextFileReader on the file with the given filename to read from with the default character encoding (UTF-8) of this class. |
|
TextFileReader(java.lang.String filename,
java.nio.charset.Charset charset)
Creates a new TextFileReader on the file with the given filename to read from with the encoding specified by the given charset. |
|
| Method Summary | |
|---|---|
void |
closeQuietly()
Closes this reader and swallows any IOException that might occur. |
void |
closeUnchecked()
Closes this reader and throws an IORuntimeException wrapping
any IOException that might occur. |
int |
processLines(org.pfsw.bif.text.ILineProcessor lineProcessor)
Processes all lines of the underlying text file by reading each line and sending it to the given line processor. |
| Methods inherited from class java.io.InputStreamReader |
|---|
close, getEncoding, read, read, ready |
| Methods inherited from class java.io.Reader |
|---|
mark, markSupported, read, read, reset, skip |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.nio.charset.Charset DEFAULT_CHARSET
| Constructor Detail |
|---|
public TextFileReader(java.io.File file,
java.nio.charset.Charset charset)
throws java.io.FileNotFoundException
file - the File to read from (must not be null).charset - The encoding to be used (must not be null).
java.io.FileNotFoundException - if the file does not exist,
is a directory rather than a regular file,
or for some other reason cannot be opened for
reading.
public TextFileReader(java.io.File file)
throws java.io.FileNotFoundException
If you want to have the platform encoding instead, use FileReader instead.
If you want to have another encoding instead, use TextFileReader(File, Charset).
file - the File to read from (must not be null).
java.io.FileNotFoundException - if the file does not exist,
is a directory rather than a regular file,
or for some other reason cannot be opened for
reading.
public TextFileReader(java.lang.String filename,
java.nio.charset.Charset charset)
throws java.io.FileNotFoundException
filename - The name of the file to read from (must not be null).charset - The encoding to be used (must not be null).
java.io.FileNotFoundException - if the file does not exist,
is a directory rather than a regular file,
or for some other reason cannot be opened for
reading.
public TextFileReader(java.lang.String filename)
throws java.io.FileNotFoundException
If you want to have the platform encoding instead, use FileReader instead.
If you want to have another encoding instead, use TextFileReader(String, Charset).
filename - The name of the file to read from (must not be null).
java.io.FileNotFoundException - if the file does not exist,
is a directory rather than a regular file,
or for some other reason cannot be opened for
reading.| Method Detail |
|---|
public int processLines(org.pfsw.bif.text.ILineProcessor lineProcessor)
lineProcessor - The processor to receive line by line (must not be null).
org.pfsw.bif.exceptions.IORuntimeException - In any case of IO problems.public void closeQuietly()
IOException that might occur.
public void closeUnchecked()
IORuntimeException wrapping
any IOException that might occur.
org.pfsw.bif.exceptions.IORuntimeException - A wrapped IOException.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||