Interface Output

    • Method Detail

      • output

        static Output output​(Writer writer)
        Adapt a Writer to the Output interface.
        Parameters:
        writer - the Writer to adapt.
        Returns:
        an Output instance that writes to the supplied Writer.
      • output

        static Output output​(Path path)
        Create an Output that writes to the specified file.
        Parameters:
        path - the file to write to.
        Returns:
        an Output instance that writes to the specified file.
      • stringBuilder

        static Output stringBuilder​(int size)
        Create a new Output that writes to a new string builder of given capacity. The returned object can be used to retrieve the constructed string.
        Parameters:
        size - the initial capacity of the internal string builder.
        Returns:
        a new readable Output instance.
      • nowhere

        static Output.Readable nowhere()
        Get an 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.

        Returns:
        an Output instance that writes nowhere.
      • lineNumbers

        static Output lineNumbers​(Output output)
        Wrap an Output in another instance that prepends a line number to every line written.
        Parameters:
        output - the wrapped output, where numbered lines will be written to.
        Returns:
        an Output instance that prepends lines with line numbers.
      • multiplex

        static Output multiplex​(Output... output)
        Combine multiple Output instances to one instance that writes to all combined instances.
        Parameters:
        output - the output instances to combine and write all output to.
        Returns:
        an Output instance that writes to all the supplied instances.
      • and

        default Output and​(Output output)
        Fluent API for multiplexing multiple Output instances.
        Parameters:
        output - an Output instance to also write to.
        Returns:
        an Output instance that writes to both this and the supplied Output instance.
      • string

        static <T> String string​(T value,
                                 BiConsumer<T,​Output> writer)
        Convenience method for converting an object to a String through the means of a method that knows how to write such an object to an Output.
        Type Parameters:
        T - the type of the object to write.
        Parameters:
        value - the object to convert to a String.
        writer - the method that knows how to write the supplied object to an Output.
        Returns:
        the resulting String.
        See Also:
        append(Object, BiConsumer)
      • lines

        static String lines​(String... lines)
        Join several strings as lines into one string with a line separator in between.
        Parameters:
        lines - the lines to join.
        Returns:
        a string that consists of the supplied lines.
      • escape

        default Output escape​(CharSequence str,
                              IntFunction<String> replacement)
        Escape the code points of the given character sequence according to the given replacement function.

        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.

        Parameters:
        str - the character sequence to escape the contents of.
        replacement - the replacement function that defines how to escape the code points that need escaping.
        Returns:
        this Output instance to allow invocation chaining.
      • escape

        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.

        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.

        Parameters:
        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.
        Returns:
        this Output instance to allow invocation chaining.
      • append

        default <T> Output append​(T value,
                                  BiConsumer<T,​Output> writer)
        Append an arbitrary object, formatted by a supplied method for writing the object.

        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( ']' );
              }
         }
         
        Type Parameters:
        T - the type of the object to write.
        Parameters:
        value - the object to write.
        writer - the method that knows how to write the supplied object to an Output.
        Returns:
        this Output instance to allow invocation chaining.
      • append

        default Output append​(boolean x)
        Append a boolean value.
        Parameters:
        x - the boolean to append.
        Returns:
        this Output instance to allow invocation chaining.
      • append

        default Output append​(int x)
        Append an integer.
        Parameters:
        x - the int to append.
        Returns:
        this Output instance to allow invocation chaining.
      • append

        default Output append​(long x)
        Append a long integer.
        Parameters:
        x - the long to append.
        Returns:
        this Output instance to allow invocation chaining.
      • append

        default Output append​(float x)
        Append a floating-point number.
        Parameters:
        x - the float to append.
        Returns:
        this Output instance to allow invocation chaining.
      • append

        default Output append​(double x)
        Append a double-precision floating-point number.
        Parameters:
        x - the double to append.
        Returns:
        this Output instance to allow invocation chaining.
      • appendCodePoint

        default Output appendCodePoint​(int codePoint)
        Appends the string representation of the codePoint argument to this sequence.
        Parameters:
        codePoint - a Unicode code point
        Returns:
        this Output instance to allow invocation chaining.
        Throws:
        IllegalArgumentException - if the specified codePoint isn't a valid Unicode code point.
        See Also:
        the corresponding method of StringBuilder
      • append

        default Output append​(String str)
        Append a string.
        Parameters:
        str - the String to append.
        Returns:
        this Output instance to allow invocation chaining.
      • append

        default Output append​(char[] str)
        Append an array of characters.
        Parameters:
        str - the char[] to append.
        Returns:
        this Output instance to allow invocation chaining.
      • append

        default Output append​(char[] str,
                              int offset,
                              int len)
        Append a range from an array of characters.
        Parameters:
        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.
        Returns:
        this Output instance to allow invocation chaining.
      • printLines

        default Output printLines​(String text,
                                  String separator)
        Append a specified string, with a given separator inserted between each line in the string.
        Parameters:
        text - the String to append.
        separator - the String to insert between each line of the string.
        Returns:
        this Output instance to allow invocation chaining.
      • println

        default Output println()
        Append a line separator.
        Returns:
        this Output instance to allow invocation chaining.
        See Also:
        System.lineSeparator()
      • println

        default Output println​(boolean x)
        Append a boolean value and a line separator.
        Parameters:
        x - the boolean to append.
        Returns:
        this Output instance to allow invocation chaining.
      • println

        default Output println​(char x)
        Append the specified character and a line separator.
        Parameters:
        x - the char to append.
        Returns:
        this Output instance to allow invocation chaining.
      • println

        default Output println​(int x)
        Append an integer and a line separator.
        Parameters:
        x - the int to append.
        Returns:
        this Output instance to allow invocation chaining.
      • println

        default Output println​(long x)
        Append a long integer and a line separator.
        Parameters:
        x - the long to append.
        Returns:
        this Output instance to allow invocation chaining.
      • println

        default Output println​(float x)
        Append a floating-point number and a line separator.
        Parameters:
        x - the float to append.
        Returns:
        this Output instance to allow invocation chaining.
      • println

        default Output println​(double x)
        Append a double-precision floating-point number and a line separator.
        Parameters:
        x - the double to append.
        Returns:
        this Output instance to allow invocation chaining.
      • println

        default Output println​(char[] str)
        Append an array of characters and a line separator.
        Parameters:
        str - the char[] to append.
        Returns:
        this Output instance to allow invocation chaining.
      • println

        default Output println​(String str)
        Append a string and a line separator.
        Parameters:
        str - the String to append.
        Returns:
        this Output instance to allow invocation chaining.
      • format

        default Output format​(String format,
                              Object... args)
        Appends a formatted string to this output stream using the specified format string and arguments.
        Parameters:
        format - the format string.
        args - Arguments referenced by the format specifiers in the format string.
        Returns:
        this Output instance to allow invocation chaining.
        Throws:
        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.
        See Also:
        Formatter.format(String, Object...)
      • format

        default Output format​(Locale l,
                              String format,
                              Object... args)
        Appends a formatted string to this output stream using the specified format string and arguments.
        Parameters:
        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.
        Returns:
        this Output instance to allow invocation chaining.
        Throws:
        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.
        See Also:
        Formatter.format(Locale, String, Object...)
      • flush

        default void flush()
        Flushes the underlying output.
      • writer

        default Writer writer()
        Return a Writer that writes to this Output.
        Returns:
        a Writer that writes to this Output.
      • getChars

        static void getChars​(CharSequence source,
                             int begin,
                             int end,
                             char[] target,
                             int off)
        Copies characters from the source CharSequence into the destination character array.

        This method delegates to methods on specific CharSequence implementations if present.

        Parameters:
        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.
        Throws:
        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.length
        See Also:
        the corresponding method in String