org.jpop.io
Class ThreadedFileWriter

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.jpop.io.ThreadedFileWriter
All Implemented Interfaces:
java.lang.Runnable

public abstract class ThreadedFileWriter
extends java.lang.Thread

This class takes a BufferedReader and a File object, then opens the file for writing and reads whatever is interfacethe buffered reader until this is empty whilst writing to the file the contents. At the end it closes both the file and the reader and stops. To use this class, you must define methods for all the events:

  ThreadedFileWriter tfw = new ThreadedFileWriter(filename, reader){
      public void exceptionGenerated(Exception e){
          // stuff to do when an exception is fired
      }
      public void fileChanged(){
          //stuff to do when file changes
      }
      public void fileClosed(){
          // stuff to do when file is closed
      }
      public void fileOpened(){
          // stuff to do when file is opened
      }
  }.start();

Author:
ug57dsm

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ThreadedFileWriter(java.io.File f)
          Constructor for the ThreadedFileWriter object
ThreadedFileWriter(java.io.File f, LogWindow lw)
          Constructor for the ThreadedFileWriter object
ThreadedFileWriter(java.io.File f, java.lang.String name)
          Constructor for the ThreadedFileWriter object
 
Method Summary
 void append(java.lang.String s)
           
 void close()
          close the thread
abstract  void exceptionGenerated(java.lang.Exception e)
          This is fired when an exception gets generated interfacethe main loop
abstract  void fileChanged()
          This is fired when the file is changed
abstract  void fileClosed()
          This is fired when the file gets closed
abstract  void fileOpened()
          This is fired when the file is opened
 java.io.BufferedReader getReader()
          Gets the reader value of the ThreadedFileWriter object
 boolean isCanClose()
          Gets the can close value of the ThreadedFileWriter object
 void run()
          Main processing method for ThreadedFileWriter
 void setCanClose(boolean b)
          Sets the can close value of the ThreadedFileWriter object
 void setReader(java.io.BufferedReader br)
          Sets the reader value of the ThreadedFileWriter object
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ThreadedFileWriter

public ThreadedFileWriter(java.io.File f)
                   throws java.io.FileNotFoundException,
                          java.io.IOException
Constructor for the ThreadedFileWriter object

Parameters:
f - The file this object is to write to
Throws:
java.io.FileNotFoundException - When the file can't be found by java
java.io.IOException - When the file can't be written to

ThreadedFileWriter

public ThreadedFileWriter(java.io.File f,
                          LogWindow lw)
                   throws java.io.FileNotFoundException,
                          java.io.IOException
Constructor for the ThreadedFileWriter object

Parameters:
f - The file this object is to write to
lw -
Throws:
java.io.FileNotFoundException - When the file can't be found by java
java.io.IOException - When the file can't be written to

ThreadedFileWriter

public ThreadedFileWriter(java.io.File f,
                          java.lang.String name)
                   throws java.io.FileNotFoundException,
                          java.io.IOException
Constructor for the ThreadedFileWriter object

Parameters:
f - The file this object is to write to
name -
Throws:
java.io.FileNotFoundException - When the file can't be found by java
java.io.IOException - When the file can't be written to
Method Detail

run

public final void run()
Main processing method for ThreadedFileWriter


setCanClose

public void setCanClose(boolean b)
Sets the can close value of the ThreadedFileWriter object

Parameters:
b - The new canClose value

setReader

public void setReader(java.io.BufferedReader br)
Sets the reader value of the ThreadedFileWriter object

Parameters:
br - The new reader value

getReader

public java.io.BufferedReader getReader()
Gets the reader value of the ThreadedFileWriter object

Returns:
The reader value

isCanClose

public boolean isCanClose()
Gets the can close value of the ThreadedFileWriter object

Returns:
The canClose value

append

public void append(java.lang.String s)
Parameters:
s -

close

public void close()
close the thread


exceptionGenerated

public abstract void exceptionGenerated(java.lang.Exception e)
This is fired when an exception gets generated interfacethe main loop

Parameters:
e - The exception

fileChanged

public abstract void fileChanged()
This is fired when the file is changed


fileClosed

public abstract void fileClosed()
This is fired when the file gets closed


fileOpened

public abstract void fileOpened()
This is fired when the file is opened