- 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
Modifier and TypeMethodDescriptiondefault 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
Gets the number of characters represented by this Writable.boolean
Checks if the writable will be able to be converted toString in an extremely efficient manner.toString()
Anything writable must have atoString
consistent with what would be written by thewriteTo
andappendTo
methods.trim()
Trims the contents of this writable, as per rules ofStrings.isWhitespace(int)
, returning the instance that represents this writable trimmed.void
Writes a streamed version of the object's String representation using the given encoder.void
Writes a streamed version of the object's String representation using the given encoder.void
Writes a streamed version of the object's String representation.void
Writes a streamed version of the object's String representation.
-
Method Details
-
getLength
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 prefertoString
overwriteTo
orappendTo
whenisFastToString
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 atoString
consistent with what would be written by thewriteTo
andappendTo
methods. For larger amounts of data, it is likely much more efficient to call the most appropriatewriteTo
orappendTo
method. -
writeTo
Writes a streamed version of the object's String representation. What is written must be the same as ifout.write(this.toString())
were called, but may be a much more efficient implementation.- Throws:
IOException
-
writeTo
Writes a streamed version of the object's String representation. What is written must be the same as ifout.write(this.toString(), off, len)
were called, but may be a much more efficient implementation.- Throws:
IOException
-
writeTo
Writes a streamed version of the object's String representation using the given encoder. What is written must be the same as ifencoder.write(this.toString(), out)
were called, but may be a much more efficient implementation.- Parameters:
encoder
- ifnull
, no encoding is performed and will be the same as a call towriteTo(java.io.Writer)
- Throws:
IOException
-
writeTo
Writes a streamed version of the object's String representation using the given encoder. What is written must be the same as ifencoder.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 towriteTo(java.io.Writer, long, long)
- Throws:
IOException
-
appendTo
Appends a streamed version of the object's String representation. What is appended must be the same as ifout.append(this.toString())
were called, but may be a much more efficient implementation.- Throws:
IOException
-
appendTo
Appends a streamed version of the object's String representation. What is appended must be the same as ifout.append(this.toString(), start, end)
were called, but may be a much more efficient implementation.- Throws:
IOException
-
appendTo
Appends a streamed version of the object's String representation using the given encoder. What is appended must be the same as ifencoder.append(this.toString(), out)
were called, but may be a much more efficient implementation.- Parameters:
encoder
- ifnull
, no encoding is performed and will be the same as a call toappendTo(java.lang.Appendable)
- Throws:
IOException
-
appendTo
Appends a streamed version of the object's String representation using the given encoder. What is appended must be the same as ifencoder.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 toappendTo(java.lang.Appendable, long, long)
- Throws:
IOException
-
trim
Trims the contents of this writable, as per rules ofStrings.isWhitespace(int)
, returning the instance that represents this writable trimmed.It will most likely be faster to check
isFastToString()
and then trim the result oftoString()
. However, for non-fast-toString writables, this trim will be more efficient.- Throws:
IOException
-