Package elki.result.textwriter
Class TextWriterStream
- java.lang.Object
-
- elki.result.textwriter.TextWriterStream
-
public class TextWriterStream extends java.lang.ObjectRepresentation of an output stream to a text file.- Since:
- 0.2
- Author:
- Erich Schubert
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringBuildercommentBuffer for comment data to output.static java.lang.StringCOMMENTSEPComment separator line.private TextWriterWriterInterface<?>fallbackwriterFallback writer, using toString.private java.lang.StringBuilderinlineBuffer for inline data to output.private static java.lang.StringNEWLINESystem newline character(s)private java.io.PrintStreamoutStreamActual stream to write to.static java.lang.StringQUOTEString to separate different entries while printing.static java.lang.StringSEPARATORString to separate different entries while printing.static java.lang.StringSER_MARKERMarker used in text serialization (and re-parsing)private HandlerList<TextWriterWriterInterface<?>>writersHandlers for various object types.
-
Constructor Summary
Constructors Constructor Description TextWriterStream(java.io.PrintStream out, HandlerList<TextWriterWriterInterface<?>> writers, TextWriterWriterInterface<?> fallback)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcommentPrint(java.lang.CharSequence line)Print an object into the comments sectionvoidcommentPrint(java.lang.Object line)Print an object into the comments sectionvoidcommentPrintLn()Print a newline into the comments section.voidcommentPrintLn(java.lang.CharSequence line)Print an object into the comments section with trailing newline.voidcommentPrintLn(java.lang.Object line)Print an object into the comments section with trailing newline.voidcommentPrintSeparator()Print a separator line in the comments section.voidflush()Flush output: write inline data, then write comment section.TextWriterWriterInterface<?>getWriterFor(java.lang.Object o)Retrieve an appropriate writer from the handler list.voidinlinePrint(java.lang.Object o)Print data into the inline part of the file.voidinlinePrintNoQuotes(java.lang.Object o)Print data into the inline part of the file WITHOUT checking for separators (and thus quoting).private voidquotePrintln(java.io.PrintStream outStream, java.lang.String data)Quoted println.
-
-
-
Field Detail
-
outStream
private java.io.PrintStream outStream
Actual stream to write to.
-
inline
private java.lang.StringBuilder inline
Buffer for inline data to output.
-
comment
private java.lang.StringBuilder comment
Buffer for comment data to output.
-
writers
private HandlerList<TextWriterWriterInterface<?>> writers
Handlers for various object types.
-
SEPARATOR
public static final java.lang.String SEPARATOR
String to separate different entries while printing.- See Also:
- Constant Field Values
-
QUOTE
public static final java.lang.String QUOTE
String to separate different entries while printing.- See Also:
- Constant Field Values
-
COMMENTSEP
public static final java.lang.String COMMENTSEP
Comment separator line. Since this will be printed withoutQUOTEinfront, it should be quoted string itself.- See Also:
- Constant Field Values
-
NEWLINE
private static final java.lang.String NEWLINE
System newline character(s)
-
SER_MARKER
public static final java.lang.String SER_MARKER
Marker used in text serialization (and re-parsing)- See Also:
- Constant Field Values
-
fallbackwriter
private TextWriterWriterInterface<?> fallbackwriter
Fallback writer, using toString.
-
-
Constructor Detail
-
TextWriterStream
public TextWriterStream(java.io.PrintStream out, HandlerList<TextWriterWriterInterface<?>> writers, TextWriterWriterInterface<?> fallback)Constructor.- Parameters:
out- Actual stream to write towriters- Handlers for various data typesfallback- Fallback writer
-
-
Method Detail
-
commentPrint
public void commentPrint(java.lang.Object line)
Print an object into the comments section- Parameters:
line- object to print into commments
-
commentPrint
public void commentPrint(java.lang.CharSequence line)
Print an object into the comments section- Parameters:
line- object to print into commments
-
commentPrintLn
public void commentPrintLn(java.lang.CharSequence line)
Print an object into the comments section with trailing newline.- Parameters:
line- object to print into comments
-
commentPrintLn
public void commentPrintLn(java.lang.Object line)
Print an object into the comments section with trailing newline.- Parameters:
line- object to print into comments
-
commentPrintLn
public void commentPrintLn()
Print a newline into the comments section.
-
commentPrintSeparator
public void commentPrintSeparator()
Print a separator line in the comments section.
-
inlinePrint
public void inlinePrint(java.lang.Object o)
Print data into the inline part of the file. Data is sanitized: newlines are replaced with spaces, and text containing separators is put in quotes. Quotes and escape characters are escaped.- Parameters:
o- object to print
-
inlinePrintNoQuotes
public void inlinePrintNoQuotes(java.lang.Object o)
Print data into the inline part of the file WITHOUT checking for separators (and thus quoting).- Parameters:
o- object to print.
-
flush
public void flush()
Flush output: write inline data, then write comment section. Reset streams.
-
quotePrintln
private void quotePrintln(java.io.PrintStream outStream, java.lang.String data)Quoted println. All lines written will be prefixed withQUOTE- Parameters:
outStream- output stream to write todata- data to print
-
getWriterFor
public TextWriterWriterInterface<?> getWriterFor(java.lang.Object o)
Retrieve an appropriate writer from the handler list.- Parameters:
o- query object- Returns:
- appropriate write, if available
-
-