All pastes #595459 Raw Edit

Something

public java v1 · immutable
#595459 ·published 2007-06-29 15:04 UTC
rendered paste body
package net.st0rm.ss.loghandlers;import java.io.*;import java.util.ArrayList;import java.util.Calendar;import java.util.Timer;import java.util.TimerTask;import net.st0rm.ss.Log;import net.st0rm.ss.gamecmdhandlers.GameCommandHandler;import net.st0rm.ss.irc.IRC;public abstract class LogHandler {	public static ArrayList<GameCommandHandler> gameCmdHandlers = new ArrayList<GameCommandHandler>();		private BufferedReader reader = null;	private File directory = null;	private LogReadThread thread = null;	private String thisLine = null;	private boolean skip = true;		/**	 * Time to wait between reads	 */	private Long delay = 100L;	/**	 * Creates a new instance	 * @param directory Directory of the files used	 * @param skip Should the reader skip lines already existing?	 */	public LogHandler(File directory, boolean skip) {		this.directory = directory;		this.skip = skip;	}	public String getFileName() { return ""; };		private class LogReadThread extends Thread {		public boolean stop = false;		public void run() {			Calendar c = Calendar.getInstance();			c.set(Calendar.HOUR_OF_DAY, 23);			c.set(Calendar.MINUTE, 59);			c.set(Calendar.SECOND,59);			new Timer("Restart Timer").schedule(					new TimerTask() { 						public void run() {							try {								Thread.sleep(3000);							} catch (InterruptedException e) {								// TODO Auto-generated catch block								e.printStackTrace();							}							IRC.getInstance().msg("Restarting reader \"" + this.getClass().getName() + "\" for the new day.");							LogHandler.this.restartReader();						} 					}					,c.getTime(), 3600000*24);			try {				reader = new BufferedReader(new FileReader(directory.getAbsolutePath() + "/" + getFileName()));				if (skip) while ((reader.readLine()) != null);				while (!stop) {					try {						Thread.sleep(delay);					} catch (InterruptedException e) { }					while ((thisLine = reader.readLine()) != null) onNewLine(thisLine);				}			} catch (Exception e) {				Log.log(e);			}		}	}	/**	 * Call to re-start the file stream	 *	 */	public void restartReader() {		if (thread != null) thread.stop = true;		thread = new LogReadThread();		thread.start();	}	/**	 * Called when a new line is added to the file	 * @param line The line added	 */	public void onNewLine(String line) { }}