Interface Writable

  • All Known Implementing Classes:
    AoCharArrayWriter

    public interface Writable
    Something that may be written to a Writer output instead of being converted toString and then having the String written.
    Author:
    AO Industries, Inc.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default void appendTo​(Encoder encoder, Appendable out)
      Appends a streamed version of the object's String representation using the given encoder.
      default void appendTo​(Encoder encoder, Appendable out, long start, long end)
      Appends a streamed version of the object's String representation using the given encoder.
      default void appendTo​(Appendable out)
      Appends a streamed version of the object's String representation.
      default void appendTo​(Appendable out, long start, long end)
      Appends a streamed version of the object's String representation.
      long getLength()
      Gets the number of characters represented by this Writable.
      boolean isFastToString()
      Checks if the writable will be able to be converted toString in an extremely efficient manner.
      String toString()
      Anything writable must have a toString consistent with what would be written by the writeTo and appendTo methods.
      Writable trim()
      Trims the contents of this writable, as per rules of Strings.isWhitespace(int), returning the instance that represents this writable trimmed.
      void writeTo​(Encoder encoder, Writer out)
      Writes a streamed version of the object's String representation using the given encoder.
      void writeTo​(Encoder encoder, Writer out, long off, long len)
      Writes a streamed version of the object's String representation using the given encoder.
      void writeTo​(Writer out)
      Writes a streamed version of the object's String representation.
      void writeTo​(Writer out, long off, long len)
      Writes a streamed version of the object's String representation.
    • Method Detail

      • getLength

        long getLength()
                throws IOException
        Gets the number of characters represented by this Writable.
        Throws:
        IOException
      • isFastToString

        boolean isFastToString()
        Checks if the writable will be able to be converted toString in an extremely efficient manner. This means without allocating any new buffer space or string copies. Callers should prefer toString over writeTo or appendTo when isFastToString returns true.

        Note: As of Java 1.7.0_06, String.substring(int, int) and related operations now copy underlying buffers.

      • toString

        String toString()
        Anything writable must have a toString consistent with what would be written by the writeTo and appendTo methods. For larger amounts of data, it is likely much more efficient to call the most appropriate writeTo or appendTo method.
        Overrides:
        toString in class Object
      • writeTo

        void writeTo​(Writer out)
              throws IOException
        Writes a streamed version of the object's String representation. What is written must be the same as if out.write(this.toString()) were called, but may be a much more efficient implementation.
        Throws:
        IOException
      • writeTo

        void writeTo​(Writer out,
                     long off,
                     long len)
              throws IOException
        Writes a streamed version of the object's String representation. What is written must be the same as if out.write(this.toString(), off, len) were called, but may be a much more efficient implementation.
        Throws:
        IOException
      • writeTo

        void writeTo​(Encoder encoder,
                     Writer out)
              throws IOException
        Writes a streamed version of the object's String representation using the given encoder. What is written must be the same as if encoder.write(this.toString(), out) were called, but may be a much more efficient implementation.
        Parameters:
        encoder - if null, no encoding is performed and will be the same as a call to writeTo(java.io.Writer)
        Throws:
        IOException
      • writeTo

        void writeTo​(Encoder encoder,
                     Writer out,
                     long off,
                     long len)
              throws IOException
        Writes a streamed version of the object's String representation using the given encoder. What is written must be the same as if encoder.write(this.toString(), off, len, out) were called, but may be a much more efficient implementation.
        Parameters:
        encoder - if null, no encoding is performed and will be the same as a call to writeTo(java.io.Writer, long, long)
        Throws:
        IOException
      • appendTo

        default void appendTo​(Appendable out)
                       throws IOException
        Appends a streamed version of the object's String representation. What is appended must be the same as if out.append(this.toString()) were called, but may be a much more efficient implementation.
        Throws:
        IOException
      • appendTo

        default void appendTo​(Appendable out,
                              long start,
                              long end)
                       throws IOException
        Appends a streamed version of the object's String representation. What is appended must be the same as if out.append(this.toString(), start, end) were called, but may be a much more efficient implementation.
        Throws:
        IOException
      • appendTo

        default void appendTo​(Encoder encoder,
                              Appendable out)
                       throws IOException
        Appends a streamed version of the object's String representation using the given encoder. What is appended must be the same as if encoder.append(this.toString(), out) were called, but may be a much more efficient implementation.
        Parameters:
        encoder - if null, no encoding is performed and will be the same as a call to appendTo(java.lang.Appendable)
        Throws:
        IOException
      • appendTo

        default void appendTo​(Encoder encoder,
                              Appendable out,
                              long start,
                              long end)
                       throws IOException
        Appends a streamed version of the object's String representation using the given encoder. What is appended must be the same as if encoder.append(this.toString(), start, end, out) were called, but may be a much more efficient implementation.
        Parameters:
        encoder - if null, no encoding is performed and will be the same as a call to appendTo(java.lang.Appendable, long, long)
        Throws:
        IOException