public interface Output extends Appendable, Closeable
PrintStream, PrintWriter, and StringBuilder.
The methods in this interface are defined to return the Output instance itself (this), in order to
allow chaining method calls in a "fluent" style.
| Modifier and Type | Interface and Description |
|---|---|
static interface |
Output.Readable
An extension of
Output that signals that what was written can be read back. |
| Modifier and Type | Method and Description |
|---|---|
default Output |
and(Output output)
Fluent API for multiplexing multiple
Output instances. |
default Output |
append(boolean x)
Append a boolean value.
|
Output |
append(char x) |
default Output |
append(char[] str)
Append an array of characters.
|
default Output |
append(char[] str,
int offset,
int len)
Append a range from an array of characters.
|
default Output |
append(CharSequence str) |
default Output |
append(CharSequence str,
int start,
int end) |
default Output |
append(double x)
Append a double-precision floating-point number.
|
default Output |
append(float x)
Append a floating-point number.
|
default Output |
append(int x)
Append an integer.
|
default Output |
append(long x)
Append a long integer.
|
default Output |
append(String str)
Append a string.
|
default <T> Output |
append(T value,
BiConsumer<T,Output> writer)
Append an arbitrary object, formatted by a supplied method for writing the object.
|
default Output |
appendCodePoint(int codePoint)
Appends the string representation of the
codePoint argument to this sequence. |
default void |
close() |
static int |
codePointAt(CharSequence str,
int index)
Get the Unicode code point of the specified character sequence at the specified index.
|
default Output |
escape(CharSequence str,
IntFunction<String> replacement)
Escape the code points of the given character sequence according to the given replacement function.
|
default Output |
escape(CharSequence str,
int start,
int end,
IntFunction<String> replacement)
Escape the code points of the given character sequence according to the given replacement function.
|
default void |
flush()
Flushes the underlying output.
|
default Output |
format(Locale l,
String format,
Object... args)
Appends a formatted string to this output stream using the specified format string and arguments.
|
default Output |
format(String format,
Object... args)
Appends a formatted string to this output stream using the specified format string and arguments.
|
static void |
getChars(CharSequence source,
int begin,
int end,
char[] target,
int off)
Copies characters from the source
CharSequence into the destination character array. |
static Output |
lineNumbers(Output output)
Wrap an
Output in another instance that prepends a line number to every line written. |
static String |
lines(String... lines)
Join several strings as lines into one string with a line separator in between.
|
static Output |
multiplex(Output... output)
Combine multiple
Output instances to one instance that writes to all combined instances. |
static Output.Readable |
nowhere()
Get an
Output instance that writes nowhere. |
static Output |
output(CharBuffer buffer)
Adapt a
CharBuffer to the Output interface. |
static Output |
output(OutputStream stream)
Adapt an
OutputStream to the Output interface. |
static Output |
output(Path path)
Create an
Output that writes to the specified file. |
static Output.Readable |
output(StringBuffer buffer)
Adapt a
StringBuffer to the Output interface. |
static Output.Readable |
output(StringBuilder builder)
Adapt a
StringBuilder to the Output interface. |
static Output |
output(Writer writer)
Adapt a
Writer to the Output interface. |
default Output |
printLines(String text,
String separator)
Append a specified string, with a given separator inserted between each line in the string.
|
default Output |
println()
Append a line separator.
|
default Output |
println(boolean x)
Append a boolean value and a line separator.
|
default Output |
println(char x)
Append the specified character and a line separator.
|
default Output |
println(char[] str)
Append an array of characters and a line separator.
|
default Output |
println(double x)
Append a double-precision floating-point number and a line separator.
|
default Output |
println(float x)
Append a floating-point number and a line separator.
|
default Output |
println(int x)
Append an integer and a line separator.
|
default Output |
println(long x)
Append a long integer and a line separator.
|
default Output |
println(String str)
Append a string and a line separator.
|
static Output |
stdErr()
Get an
Output instance that writes to the standard error output stream. |
static Output |
stdOut()
Get an
Output instance that writes to the standard output stream. |
static <T> String |
string(T value,
BiConsumer<T,Output> writer)
|
static Output.Readable |
stringBuilder()
Create a new
Output that writes to a new string builder. |
static Output |
stringBuilder(int size)
Create a new
Output that writes to a new string builder of given capacity. |
default Writer |
writer()
Return a
Writer that writes to this Output. |
static Output output(OutputStream stream)
OutputStream to the Output interface.stream - the OutputStream to adapt.Output instance that writes to the supplied OutputStream.static Output.Readable output(StringBuilder builder)
StringBuilder to the Output interface.builder - the StringBuilder to adapt.Output instance that writes to the supplied StringBuilder.static Output.Readable output(StringBuffer buffer)
StringBuffer to the Output interface.buffer - the StringBuffer to adapt.Output instance that writes to the supplied StringBuffer.static Output output(CharBuffer buffer)
CharBuffer to the Output interface.buffer - the CharBuffer to adapt.Output instance that writes to the supplied CharBuffer.static Output output(Path path)
Output that writes to the specified file.path - the file to write to.Output instance that writes to the specified file.static Output.Readable stringBuilder()
Output that writes to a new string builder. The returned object can be used to retrieve the constructed string.Output instance.static Output stringBuilder(int size)
Output that writes to a new string builder of given capacity. The returned object can be
used to retrieve the constructed string.size - the initial capacity of the internal string builder.Output instance.static Output stdOut()
Output instance that writes to the standard output stream.Output instance that writes to standard out.static Output stdErr()
Output instance that writes to the standard error output stream.Output instance that writes to standard error.static Output.Readable nowhere()
Output instance that writes nowhere.
The returned instance is readable in order to be usable in places where a readable output is required, although the result of reading from this instance is always as if nothing was written.
Output instance that writes nowhere.static Output lineNumbers(Output output)
Output in another instance that prepends a line number to every line written.output - the wrapped output, where numbered lines will be written to.Output instance that prepends lines with line numbers.static Output multiplex(Output... output)
Output instances to one instance that writes to all combined instances.output - the output instances to combine and write all output to.Output instance that writes to all the supplied instances.default Output and(Output output)
Output instances.output - an Output instance to also write to.Output instance that writes to both this and the supplied Output instance.static <T> String string(T value, BiConsumer<T,Output> writer)
String through the means of a method that knows how to
write such an object to an Output.T - the type of the object to write.value - the object to convert to a String.writer - the method that knows how to write the supplied object to an Output.String.append(Object, BiConsumer)static String lines(String... lines)
lines - the lines to join.default Output escape(CharSequence str, IntFunction<String> replacement)
The replacement function can (and is recommended to) be a partial function, only returning replacements
for the code points that are to be escaped and returning null for other code points.
str - the character sequence to escape the contents of.replacement - the replacement function that defines how to escape the code points that need escaping.Output instance to allow invocation chaining.default Output escape(CharSequence str, int start, int end, IntFunction<String> replacement)
The replacement function can (and is recommended to) be a partial function, only returning replacements
for the code points that are to be escaped and returning null for other code points.
str - the character sequence to escape the contents of.start - the position in the given character sequence to start at.end - the position in the given character sequence to end at.replacement - the replacement function that defines how to escape the code points that need escaping.Output instance to allow invocation chaining.default <T> Output append(T value, BiConsumer<T,Output> writer)
Sample usage of this method:
class Container {
private Contained one, other;
public @Override String toString() {
return Output.stringBuilder().append( this, Container::write ).toString();
}
public void write( Output output ) {
output.append( "Container[one=" ).append( one, Contained::write )
.append( ", other=" ).append( other, Contained::write ).append( ']' );
}
}
T - the type of the object to write.value - the object to write.writer - the method that knows how to write the supplied object to an Output.Output instance to allow invocation chaining.Output append(char x)
append in interface Appendabledefault Output append(CharSequence str)
append in interface Appendabledefault Output append(CharSequence str, int start, int end)
append in interface Appendabledefault Output append(boolean x)
x - the boolean to append.Output instance to allow invocation chaining.default Output append(int x)
x - the int to append.Output instance to allow invocation chaining.default Output append(long x)
x - the long to append.Output instance to allow invocation chaining.default Output append(float x)
x - the float to append.Output instance to allow invocation chaining.default Output append(double x)
x - the double to append.Output instance to allow invocation chaining.default Output appendCodePoint(int codePoint)
codePoint argument to this sequence.codePoint - a Unicode code pointOutput instance to allow invocation chaining.IllegalArgumentException - if the specified codePoint isn't a valid Unicode code point.the corresponding method of StringBuilderdefault Output append(String str)
str - the String to append.Output instance to allow invocation chaining.default Output append(char[] str)
str - the char[] to append.Output instance to allow invocation chaining.default Output append(char[] str, int offset, int len)
str - the char[] to append.offset - the position in the supplied array to start from.len - the number of characters from the supplied array to append.Output instance to allow invocation chaining.default Output printLines(String text, String separator)
text - the String to append.separator - the String to insert between each line of the string.Output instance to allow invocation chaining.default Output println()
Output instance to allow invocation chaining.System.lineSeparator()default Output println(boolean x)
x - the boolean to append.Output instance to allow invocation chaining.default Output println(char x)
x - the char to append.Output instance to allow invocation chaining.default Output println(int x)
x - the int to append.Output instance to allow invocation chaining.default Output println(long x)
x - the long to append.Output instance to allow invocation chaining.default Output println(float x)
x - the float to append.Output instance to allow invocation chaining.default Output println(double x)
x - the double to append.Output instance to allow invocation chaining.default Output println(char[] str)
str - the char[] to append.Output instance to allow invocation chaining.default Output println(String str)
str - the String to append.Output instance to allow invocation chaining.default Output format(String format, Object... args)
format - the format string.args - Arguments referenced by the format specifiers in the format string.Output instance to allow invocation chaining.IllegalFormatException - If a format string contains an illegal syntax, a format specifier that
is incompatible with the given arguments, insufficient arguments given
the format string, or other illegal conditions.Formatter.format(String, Object...)default Output format(Locale l, String format, Object... args)
l - The locale to apply during
formatting. If l is null then no localization
is applied.format - the format string.args - Arguments referenced by the format specifiers in the format string.Output instance to allow invocation chaining.IllegalFormatException - If a format string contains an illegal syntax, a format specifier that
is incompatible with the given arguments, insufficient arguments given
the format string, or other illegal conditions.Formatter.format(Locale, String, Object...)default void flush()
default void close()
close in interface AutoCloseableclose in interface Closeabledefault Writer writer()
Writer that writes to this Output.Writer that writes to this Output.static int codePointAt(CharSequence str, int index)
This method improves the corresponding method in
Character by delegating to methods on specific CharSequence implementations if present.
str - the character sequence to get the code point from.index - the index in the character sequnce the get the code point at.index of the character sequence.IndexOutOfBoundsException - if the index argument is negative or not less than the length of the contents of the character sequence.Character.codePointAt(CharSequence, int)static void getChars(CharSequence source, int begin, int end, char[] target, int off)
CharSequence into the destination character array.
This method delegates to methods on specific CharSequence implementations if present.
source - the character sequence to copy characters from.begin - the index of the first character in the sequence to copy.end - the index after the last character in the sequence to copy.target - the destination array.off - the start offset in the destination array.IndexOutOfBoundsException - If any of the following is true:
srcBegin is negative.
srcBegin is greater than srcEnd
srcEnd is greater than the length of the character sequence
dstBegin is negative
dstBegin+(srcEnd-srcBegin) is larger than dst.lengththe corresponding method in StringCopyright © 2019. All rights reserved.