public class OutputStreamLogger
extends java.io.OutputStreamWriter
close()
, with a special
newline handling and always flushing.
This is meant to wrap logging output to the console.Modifier and Type | Field and 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 newline
|
static java.lang.String |
WHITESPACE
Whitespace.
|
Constructor and Description |
---|
OutputStreamLogger(java.io.OutputStream out)
Constructor.
|
OutputStreamLogger(java.io.OutputStream out,
java.nio.charset.Charset cs)
Constructor.
|
OutputStreamLogger(java.io.OutputStream out,
java.nio.charset.CharsetEncoder enc)
Constructor.
|
OutputStreamLogger(java.io.OutputStream out,
java.lang.String charsetName)
Constructor.
|
Modifier and Type | Method and 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.
|
private int charsSinceNewline
protected static final char CARRIAGE_RETURN
public static final char UNIX_NEWLINE
public static final java.lang.String NEWLINE
public static final char[] NEWLINEC
public static final java.lang.String WHITESPACE
public OutputStreamLogger(java.io.OutputStream out)
out
- Output streampublic OutputStreamLogger(java.io.OutputStream out, java.lang.String charsetName) throws java.io.UnsupportedEncodingException
out
- Output streamcharsetName
- Character set namejava.io.UnsupportedEncodingException
- thrown on unknown character setspublic OutputStreamLogger(java.io.OutputStream out, java.nio.charset.Charset cs)
out
- Output Streamcs
- Character set to usepublic OutputStreamLogger(java.io.OutputStream out, java.nio.charset.CharsetEncoder enc)
out
- Output Streamenc
- Charset encoderpublic void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStreamWriter
private int tailingNonNewline(char[] cbuf, int off, int len)
cbuf
- Character bufferoff
- Offsetlen
- Rangeprivate int tailingNonNewline(java.lang.String str, int off, int len)
str
- Stringoff
- Offsetlen
- Rangeprivate int countNonNewline(char[] cbuf, int off, int len)
cbuf
- character bufferoff
- offsetlen
- lengthprivate int countNonNewline(java.lang.String str, int off, int len)
str
- Stringoff
- offsetlen
- lengthpublic void write(char[] cbuf, int off, int len) throws java.io.IOException
write
in class java.io.OutputStreamWriter
java.io.IOException
public void write(java.lang.String str, int off, int len) throws java.io.IOException
write
in class java.io.OutputStreamWriter
java.io.IOException
Copyright © 2019 ELKI Development Team. License information.