public class StringPrinter
extends java.lang.Object
Constructor and Description |
---|
StringPrinter(java.util.function.Consumer<java.lang.String> consumer)
StringPrinter will pass all the strings it receives to the given consumer.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
buildString(java.util.function.Consumer<StringPrinter> printer)
Easy way to create a String using a StringPrinter.
|
static java.lang.String |
buildStringFromLines(java.lang.String... lines)
Easy way to create a String from a bunch of lines.
|
void |
print(java.lang.String content)
Prints the string.
|
void |
println(java.lang.String line)
Prints the string and a newline (always '\n').
|
static java.util.function.Consumer<java.lang.String> |
stringsToLines(java.util.function.Consumer<java.lang.String> perLine)
Given a consumer of lines, creates a stateful consumer of strings
which will combine its input until it finds a newline, and
split its input when it contains multiple newlines.
|
java.io.OutputStream |
toOutputStream(java.nio.charset.Charset charset)
Creates an OutputStream which will print its content to the given StringPrinter, encoding bytes according to the given Charset.
|
java.io.PrintStream |
toPrintStream()
Creates a UTF-8 PrintStream which passes its content to this StringPrinter.
|
java.io.PrintStream |
toPrintStream(java.nio.charset.Charset charset)
Creates a PrintStream of the given charset, which passes its content to this StringPrinter.
|
java.io.PrintWriter |
toPrintWriter()
Creates a PrintWriter which passes its content to this StringPrinter.
|
java.io.Writer |
toWriter()
Creates a Writer which passes its content to this StringPrinter.
|
public StringPrinter(java.util.function.Consumer<java.lang.String> consumer)
public void println(java.lang.String line)
public void print(java.lang.String content)
public static java.lang.String buildString(java.util.function.Consumer<StringPrinter> printer)
public static java.lang.String buildStringFromLines(java.lang.String... lines)
public java.io.OutputStream toOutputStream(java.nio.charset.Charset charset)
public java.io.PrintStream toPrintStream()
public java.io.PrintStream toPrintStream(java.nio.charset.Charset charset)
public java.io.Writer toWriter()
public java.io.PrintWriter toPrintWriter()
public static java.util.function.Consumer<java.lang.String> stringsToLines(java.util.function.Consumer<java.lang.String> perLine)
perLine
- a Consumer