org.freehep.util.io
Class LineNumberWriter

java.lang.Object
  extended by java.io.Writer
      extended by org.freehep.util.io.LineNumberWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class LineNumberWriter
extends Writer

Counts line numbers, based on the first cr-lf, cr or lf it finds. Informs a listener when the linenumber exceeds a threshold. Listeners can only be informed from the second line only.

Version:
$Id: LineNumberWriter.java 8584 2006-08-10 23:06:37Z duns $
Author:
Mark Donszelmann

Nested Class Summary
static class LineNumberWriter.LineNumberEvent
          Event to be used by the LineNumberListener interface.
static interface LineNumberWriter.LineNumberListener
          LineNumberListener interface can inform a listener about changes in the line number, or when a linenumber limit has been reached.
 
Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
LineNumberWriter(Writer out)
          Creates a Line Number Writer
 
Method Summary
 void addLineNumberListener(LineNumberWriter.LineNumberListener listener, int lineNoLimit)
          Add a LineNumberListener
 void close()
           
 void flush()
           
 int getLineNumber()
          Returns the line number that is currently being written.
 void setLineNumber(int lineNo)
          Set the current line number
 void write(char[] cbuf)
           
 void write(char[] cbuf, int off, int len)
           
 void write(int c)
           
 void write(String str)
           
 void write(String str, int off, int len)
           
 
Methods inherited from class java.io.Writer
append, append, append, append, append, append
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LineNumberWriter

public LineNumberWriter(Writer out)
Creates a Line Number Writer

Parameters:
out - writer to write to
Method Detail

write

public void write(char[] cbuf)
           throws IOException
Overrides:
write in class Writer
Throws:
IOException

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws IOException
Specified by:
write in class Writer
Throws:
IOException

write

public void write(String str)
           throws IOException
Overrides:
write in class Writer
Throws:
IOException

write

public void write(String str,
                  int off,
                  int len)
           throws IOException
Overrides:
write in class Writer
Throws:
IOException

write

public void write(int c)
           throws IOException
Overrides:
write in class Writer
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException

flush

public void flush()
           throws IOException
Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
IOException

getLineNumber

public int getLineNumber()
Returns the line number that is currently being written.

Returns:
current line number

setLineNumber

public void setLineNumber(int lineNo)
Set the current line number

Parameters:
lineNo - new line number

addLineNumberListener

public void addLineNumberListener(LineNumberWriter.LineNumberListener listener,
                                  int lineNoLimit)
                           throws TooManyListenersException
Add a LineNumberListener

Parameters:
listener - new listener
lineNoLimit - line number for which to generate a LineNumberEvent
Throws:
TooManyListenersException - if there is more than one listener


Copyright © 2000-2007 FreeHEP. All Rights Reserved.