public class FileLineReader
extends java.lang.Object
This FileReader class is intended as a generic file instance class for reading text files.
This class represents the most basic reader functionality. It will simply read a line of text for each call to readLine(). It uses a java.io.BufferedReader as the underlying IO mechanism. The file to be read is expected to be ANSI or a supported Charset encoding.
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
charset |
static int |
DEFAULT_BUFFER_SIZE |
protected boolean |
eof |
protected java.io.File |
file |
protected java.lang.String |
filename |
protected boolean |
firstline |
protected java.lang.String |
fullpath |
protected java.lang.String |
linetext |
protected java.io.BufferedReader |
reader |
protected java.io.InputStream |
stream |
Constructor and Description |
---|
FileLineReader()
This constructor will create an inoperable (Closed) file object.
|
FileLineReader(java.io.File file)
The constructor used by the FileReader if the input is a File.
|
FileLineReader(java.io.File file,
java.lang.String encoding)
The constructor used by the FileReader if the input is a File.
|
FileLineReader(java.io.InputStream stream)
The constructor used by the FileReader if the input is an InputStream.
|
FileLineReader(java.io.InputStream stream,
java.lang.String encoding)
The constructor used by the FileReader if the input is an InputStream.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
A call to this routine is essentially telling the object that its useful life is over.
|
protected void |
closeReader()
Shutdown (close) the file reader if it exists.
|
java.lang.String |
getFilename()
Subclasses should not need to override this function.
|
java.lang.String |
getFullpath()
Subclasses should not need to override this function.
|
boolean |
isClosed()
Subclasses should not need to override this function.
|
boolean |
isEOF()
Subclasses should not need to override this function.
|
void |
open()
Subclasses should not need to override this function unless some very interesting things
need to be done before or after the file is opened.
|
protected void |
openFile()
Called internally by open().
|
protected void |
openStream()
Called internally by open().
|
java.lang.String |
readLine()
This routine is the most basic readLine function.
|
protected void |
resetpointers()
Resets important fields during Close and other operations.
|
protected void |
setFile(java.io.File newfile)
Allows us to set (and change) the file that will be read.
|
protected void |
setStream(java.io.InputStream stream)
Allows us to set (and change) the data that will be read.
|
public static int DEFAULT_BUFFER_SIZE
protected java.lang.String fullpath
protected java.lang.String filename
protected java.io.InputStream stream
protected java.io.File file
protected java.io.BufferedReader reader
protected boolean eof
protected boolean firstline
protected java.lang.String charset
protected java.lang.String linetext
public FileLineReader()
public FileLineReader(java.io.File file)
super(file);
file
- A File object that references the file to be opened.public FileLineReader(java.io.File file, java.lang.String encoding)
super(file);
file
- File, A File object that references the file to be opened.encoding
- String, a valid Charset encoding like "UTF-16", etc...public FileLineReader(java.io.InputStream stream)
super(stream);
stream
- an InputStream object that references the data to be opened.ClassLoader.getSystemResourceAsStream(java.lang.String)
public FileLineReader(java.io.InputStream stream, java.lang.String encoding)
super(stream);
stream
- InputStream, an InputStream object that references the data to be opened.encoding
- String, a valid Charset encoding like "UTF-16", etc...ClassLoader.getSystemResourceAsStream(java.lang.String)
protected void setFile(java.io.File newfile)
protected void setStream(java.io.InputStream stream)
public java.lang.String getFilename()
public java.lang.String getFullpath()
public boolean isClosed()
public boolean isEOF()
public java.lang.String readLine()
Subclasses that intend to maintain any kind of pointers MUST override this method in order to maintain their pointer counts but should still call this method with super.readLine() to retain the Unicode character removal on the retrieved text.
It is still desirable to maintain the basic functionality of returning the text value unmodified in each subclass intending to return lines of text. A subclass wishing to embellish or otherwise process the line of text before returning it should do so in a different method specific to that subclass.
protected void resetpointers()
super.resetpointers();
protected void openFile()
protected void openStream()
public void open()
protected void closeReader()
public void close()
Subclasses should not need to override this function unless there is additional cleanup needed prior to getting whacked. If the method is overridden, the subclass should still call this routine with:
super.close();
closeReader()
,
resetpointers()
Copyright © SAS Institute. All Rights Reserved.