- java.lang.Object
-
- java.io.Writer
-
- java.io.CharArrayWriter
-
- com.aoapps.lang.io.AoCharArrayWriter
-
- All Implemented Interfaces:
Writable,Closeable,Flushable,Appendable,AutoCloseable
public class AoCharArrayWriter extends CharArrayWriter implements Writable
Provides direct access to the internalchar[].- Author:
- AO Industries, Inc.
-
-
Field Summary
-
Fields inherited from class java.io.CharArrayWriter
buf, count
-
-
Constructor Summary
Constructors Constructor Description AoCharArrayWriter()AoCharArrayWriter(int initialSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description char[]getInternalCharArray()longgetLength()Gets the number of characters represented by this Writable.booleanisFastToString()Checks if the writable will be able to be converted toString in an extremely efficient manner.StringtoString(int off, int len)Converts a portion of the input data to a string.Writabletrim()Trims the contents of this writable, as per rules ofStrings.isWhitespace(int), returning the instance that represents this writable trimmed.voidwriteTo(Encoder encoder, Writer out)Writes a streamed version of the object's String representation using the given encoder.voidwriteTo(Encoder encoder, Writer out, long off, long len)Writes a streamed version of the object's String representation using the given encoder.voidwriteTo(Writer out, long off, long len)Writes a portion of the contents of the buffer to another character stream.-
Methods inherited from class java.io.CharArrayWriter
append, append, append, close, flush, reset, size, toCharArray, toString, write, write, write, writeTo
-
Methods inherited from class java.io.Writer
nullWriter, write, write
-
-
-
-
Method Detail
-
getInternalCharArray
public char[] getInternalCharArray()
-
getLength
public long getLength()
Description copied from interface:WritableGets the number of characters represented by this Writable.
-
isFastToString
public boolean isFastToString()
Description copied from interface:WritableChecks 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 prefertoStringoverwriteToorappendTowhenisFastToStringreturns true.Note: As of Java 1.7.0_06,
String.substring(int, int)and related operations now copy underlying buffers.- Specified by:
isFastToStringin interfaceWritable
-
toString
public String toString(int off, int len)
Converts a portion of the input data to a string.- Returns:
- the string.
-
writeTo
public void writeTo(Writer out, long off, long len) throws IOException
Writes a portion of the contents of the buffer to another character stream.- Specified by:
writeToin interfaceWritable- Throws:
IOException
-
writeTo
public void writeTo(Encoder encoder, Writer out) throws IOException
Description copied from interface:WritableWrites 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.- Specified by:
writeToin interfaceWritable- Parameters:
encoder- ifnull, no encoding is performed and will be the same as a call toWritable.writeTo(java.io.Writer)- Throws:
IOException
-
writeTo
public void writeTo(Encoder encoder, Writer out, long off, long len) throws IOException
Description copied from interface:WritableWrites 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.- Specified by:
writeToin interfaceWritable- Parameters:
encoder- if null, no encoding is performed and will be the same as a call toWritable.writeTo(java.io.Writer, long, long)- Throws:
IOException
-
trim
public Writable trim() throws IOException
Description copied from interface:WritableTrims 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
Writable.isFastToString()and then trim the result ofWritable.toString(). However, for non-fast-toString writables, this trim will be more efficient.- Specified by:
trimin interfaceWritable- Throws:
IOException
-
-