|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectghm.follow.FileFollower
public class FileFollower
Instances of this class 'follow' a particular text file, assmebling that
file's characters into Strings and sending them to instances of
OutputDestination
. The name and behavior of this class are inspired
by the '-f' (follow) flag of the UNIX command 'tail'.
OutputDestination
Field Summary | |
---|---|
protected int |
bufferSize
|
protected boolean |
continueRunning
|
protected java.io.File |
file
|
protected int |
latency
|
protected static java.lang.String |
lineSeparator
Line separator, retrieved from System properties & stored statically. |
protected boolean |
needsRestart
|
protected java.util.List<OutputDestination> |
outputDestinations
|
protected boolean |
paused
|
protected java.lang.Thread |
runnerThread
|
Constructor Summary | |
---|---|
FileFollower(java.io.File file,
int bufferSize,
int latency,
OutputDestination[] initialOutputDestinations)
Constructs a new FileFollower; invoking this constructor does not cause the new object to begin following the supplied file. |
|
FileFollower(java.io.File file,
OutputDestination[] initialOutputDestinations)
Identical to FileFollower(File, int, int, OutputDestination[]) ,
except that a default buffer size (32,768 characters) and latency (1000
milliseconds) are used. |
Method Summary | |
---|---|
boolean |
addOutputDestination(OutputDestination outputDestination)
Add another OutputDestination to which the followed file's contents should be printed. |
int |
getBufferSize()
Returns the size of the character buffer used to read characters from the followed file. |
java.io.File |
getFollowedFile()
Returns the file which is being followed by this FileFollower |
int |
getLatency()
Returns the time (in milliseconds) which a FileFollower spends sleeping each time it encounters the end of the followed file. |
java.util.List<OutputDestination> |
getOutputDestinations()
Returns the List which maintains all OutputDestinations for this FileFollower. |
boolean |
isBeingFollowed()
Returns the following state of a file |
boolean |
isPaused()
Returns the pause state of the follower. |
void |
pause()
|
boolean |
removeOutputDestination(OutputDestination outputDestination)
Remove the supplied OutputDestination from the list of OutputDestinations to which the followed file's contents should be printed. |
void |
restart()
|
void |
setBufferSize(int bufferSize)
Sets the size of the character buffer used to read characters from the followed file. |
void |
setLatency(int latency)
Sets the time (in milliseconds) which a FileFollower spends sleeping each time it encounters the end of the followed file. |
void |
start()
Cause this FileFollower to spawn a thread which will follow the file supplied in the constructor and send its contents to all of the FileFollower's OutputDestinations. If this FileFollower is running but paused, this method equates to calling unpause(). |
void |
stop()
Cause this FileFollower to stop following the file supplied in the constructor after it flushes the characters it's currently reading to all its OutputDestinations. |
void |
stopAndWait()
Like stop() , but this method will not exit until the thread
which is following the file has finished executing (i.e., stop
synchronously). |
void |
unpause()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int bufferSize
protected int latency
protected java.io.File file
protected java.util.List<OutputDestination> outputDestinations
protected boolean continueRunning
protected boolean needsRestart
protected java.lang.Thread runnerThread
protected boolean paused
protected static final java.lang.String lineSeparator
Constructor Detail |
---|
public FileFollower(java.io.File file, int bufferSize, int latency, OutputDestination[] initialOutputDestinations)
start()
.
file
- file to be followedbufferSize
- number of chars to be read each time the file is accessedlatency
- each time a FileFollower's running thread encounters the end
of the file in its stream, it will rest for this many
milliseconds before checking to see if there are any more
bytes in the fileinitialOutputDestinations
- an initial array of OutputDestinations which will be used when
printing the contents of the file (this array may be
null)public FileFollower(java.io.File file, OutputDestination[] initialOutputDestinations)
FileFollower(File, int, int, OutputDestination[])
,
except that a default buffer size (32,768 characters) and latency (1000
milliseconds) are used.
FileFollower(File, int, int, OutputDestination[])
Method Detail |
---|
public void start()
public void pause()
public void unpause()
public void restart()
public void stop()
public void stopAndWait() throws java.lang.InterruptedException
stop()
, but this method will not exit until the thread
which is following the file has finished executing (i.e., stop
synchronously).
java.lang.InterruptedException
public boolean addOutputDestination(OutputDestination outputDestination)
outputDestination
- OutputDestination to be addedpublic boolean removeOutputDestination(OutputDestination outputDestination)
outputDestination
- OutputDestination to be removedpublic java.util.List<OutputDestination> getOutputDestinations()
public java.io.File getFollowedFile()
public boolean isBeingFollowed()
public boolean isPaused()
public int getBufferSize()
public void setBufferSize(int bufferSize)
bufferSize
- size of the character bufferpublic int getLatency()
public void setLatency(int latency)
latency
- latency, in milliseconds
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |