de.lmu.ifi.dbs.elki.logging
Class OutputStreamLogger

java.lang.Object
  extended by java.io.Writer
      extended by java.io.OutputStreamWriter
          extended by de.lmu.ifi.dbs.elki.logging.OutputStreamLogger
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class OutputStreamLogger
extends OutputStreamWriter

Class to write to Output Streams, IGNORING close(), with a special newline handling and always flushing. This is meant to wrap logging output to the console.


Field Summary
protected static char CARRIAGE_RETURN
          Carriage return character.
private  int charsSinceNewline
          Flag to signal if we have had a newline recently.
static String NEWLINE
          Newline string.
static char[] NEWLINEC
          Newline as char array.
static char UNIX_NEWLINE
          Unix newline
static String WHITESPACE
          Whitespace.
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
OutputStreamLogger(OutputStream out)
          Constructor.
OutputStreamLogger(OutputStream out, Charset cs)
          Constructor.
OutputStreamLogger(OutputStream out, CharsetEncoder enc)
          Constructor.
OutputStreamLogger(OutputStream out, String charsetName)
          Constructor.
 
Method Summary
 void close()
          Close command - will be IGNORED.
private  int countNonNewline(char[] cbuf, int off, int len)
          Count the number of non-newline characters before first newline in the string.
private  int countNonNewline(String str, int off, int len)
          Count the number of non-newline characters before first newline in the string.
private  int tailingNonNewline(char[] cbuf, int off, int len)
          Count the tailing non-newline characters.
private  int tailingNonNewline(String str, int off, int len)
          Count the tailing non-newline characters.
 void write(char[] cbuf, int off, int len)
          Writer that keeps track of when it hasn't seen a newline yet, will auto-insert newlines except when lines start with a carriage return.
 void write(String str, int off, int len)
          Writer that keeps track of when it hasn't seen a newline yet, will auto-insert newlines except when lines start with a carriage return.
 
Methods inherited from class java.io.OutputStreamWriter
flush, getEncoding, write
 
Methods inherited from class java.io.Writer
append, append, append, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

charsSinceNewline

private int charsSinceNewline
Flag to signal if we have had a newline recently.


CARRIAGE_RETURN

protected static final char CARRIAGE_RETURN
Carriage return character.

See Also:
Constant Field Values

UNIX_NEWLINE

public static final char UNIX_NEWLINE
Unix newline

See Also:
Constant Field Values

NEWLINE

public static final String NEWLINE
Newline string.


NEWLINEC

public static final char[] NEWLINEC
Newline as char array.


WHITESPACE

public static final String WHITESPACE
Whitespace.

See Also:
Constant Field Values
Constructor Detail

OutputStreamLogger

public OutputStreamLogger(OutputStream out)
Constructor.

Parameters:
out - Output stream

OutputStreamLogger

public OutputStreamLogger(OutputStream out,
                          String charsetName)
                   throws UnsupportedEncodingException
Constructor.

Parameters:
out - Output stream
charsetName - Character set name
Throws:
UnsupportedEncodingException - thrown on unknown character sets

OutputStreamLogger

public OutputStreamLogger(OutputStream out,
                          Charset cs)
Constructor.

Parameters:
out - Output Stream
cs - Character set to use

OutputStreamLogger

public OutputStreamLogger(OutputStream out,
                          CharsetEncoder enc)
Constructor.

Parameters:
out - Output Stream
enc - Charset encoder
Method Detail

close

public void close()
Close command - will be IGNORED.

Specified by:
close in interface Closeable
Overrides:
close in class OutputStreamWriter

tailingNonNewline

private int tailingNonNewline(char[] cbuf,
                              int off,
                              int len)
Count the tailing non-newline characters.

Parameters:
cbuf - Character buffer
off - Offset
len - Range
Returns:
number of tailing non-newline character

tailingNonNewline

private int tailingNonNewline(String str,
                              int off,
                              int len)
Count the tailing non-newline characters.

Parameters:
str - String
off - Offset
len - Range
Returns:
number of tailing non-newline character

countNonNewline

private int countNonNewline(char[] cbuf,
                            int off,
                            int len)
Count the number of non-newline characters before first newline in the string.

Parameters:
cbuf - character buffer
off - offset
len - length
Returns:
number of non-newline characters

countNonNewline

private int countNonNewline(String str,
                            int off,
                            int len)
Count the number of non-newline characters before first newline in the string.

Parameters:
str - String
off - offset
len - length
Returns:
number of non-newline characters

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws IOException
Writer that keeps track of when it hasn't seen a newline yet, will auto-insert newlines except when lines start with a carriage return.

Overrides:
write in class OutputStreamWriter
Throws:
IOException

write

public void write(String str,
                  int off,
                  int len)
           throws IOException
Writer that keeps track of when it hasn't seen a newline yet, will auto-insert newlines except when lines start with a carriage return.

Overrides:
write in class OutputStreamWriter
Throws:
IOException

Release 0.4.0 (2011-09-20_1324)