Package elki.logging
Class OutputStreamLogger
- java.lang.Object
-
- java.io.Writer
-
- java.io.OutputStreamWriter
-
- elki.logging.OutputStreamLogger
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.Appendable
,java.lang.AutoCloseable
public class OutputStreamLogger extends java.io.OutputStreamWriter
Class to write to Output Streams, IGNORINGclose()
, with a special newline handling and always flushing. This is meant to wrap logging output to the console.- Since:
- 0.2
- Author:
- Erich Schubert
-
-
Field Summary
Fields Modifier and Type Field Description protected static char
CARRIAGE_RETURN
Carriage return character.private int
charsSinceNewline
Flag to signal if we have had a newline recently.static java.lang.String
NEWLINE
Newline string.static char[]
NEWLINEC
Newline as char array.static char
UNIX_NEWLINE
Unix newlinestatic java.lang.String
WHITESPACE
Whitespace.
-
Constructor Summary
Constructors Constructor Description OutputStreamLogger(java.io.OutputStream out)
Constructor.OutputStreamLogger(java.io.OutputStream out, java.lang.String charsetName)
Constructor.OutputStreamLogger(java.io.OutputStream out, java.nio.charset.Charset cs)
Constructor.OutputStreamLogger(java.io.OutputStream out, java.nio.charset.CharsetEncoder enc)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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(java.lang.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(java.lang.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(java.lang.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.
-
-
-
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 java.lang.String NEWLINE
Newline string.
-
NEWLINEC
public static final char[] NEWLINEC
Newline as char array.
-
WHITESPACE
public static final java.lang.String WHITESPACE
Whitespace.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
OutputStreamLogger
public OutputStreamLogger(java.io.OutputStream out)
Constructor.- Parameters:
out
- Output stream
-
OutputStreamLogger
public OutputStreamLogger(java.io.OutputStream out, java.lang.String charsetName) throws java.io.UnsupportedEncodingException
Constructor.- Parameters:
out
- Output streamcharsetName
- Character set name- Throws:
java.io.UnsupportedEncodingException
- thrown on unknown character sets
-
OutputStreamLogger
public OutputStreamLogger(java.io.OutputStream out, java.nio.charset.Charset cs)
Constructor.- Parameters:
out
- Output Streamcs
- Character set to use
-
OutputStreamLogger
public OutputStreamLogger(java.io.OutputStream out, java.nio.charset.CharsetEncoder enc)
Constructor.- Parameters:
out
- Output Streamenc
- Charset encoder
-
-
Method Detail
-
close
public void close()
Close command - will be IGNORED.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStreamWriter
-
tailingNonNewline
private int tailingNonNewline(char[] cbuf, int off, int len)
Count the tailing non-newline characters.- Parameters:
cbuf
- Character bufferoff
- Offsetlen
- Range- Returns:
- number of tailing non-newline character
-
tailingNonNewline
private int tailingNonNewline(java.lang.String str, int off, int len)
Count the tailing non-newline characters.- Parameters:
str
- Stringoff
- Offsetlen
- 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 bufferoff
- offsetlen
- length- Returns:
- number of non-newline characters
-
countNonNewline
private int countNonNewline(java.lang.String str, int off, int len)
Count the number of non-newline characters before first newline in the string.- Parameters:
str
- Stringoff
- offsetlen
- length- Returns:
- number of non-newline characters
-
write
public void write(char[] cbuf, int off, int len) throws java.io.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 classjava.io.OutputStreamWriter
- Throws:
java.io.IOException
-
write
public void write(java.lang.String str, int off, int len) throws java.io.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 classjava.io.OutputStreamWriter
- Throws:
java.io.IOException
-
-