public class CharArrayWriter
extends java.io.Writer
Modifier and Type | Field and Description |
---|---|
protected char[] |
buf
The buffer where data is stored.
|
protected int |
count
The number of chars in the buffer.
|
Constructor and Description |
---|
CharArrayWriter()
Creates a new CharArrayWriter.
|
CharArrayWriter(int initialSize)
Creates a new CharArrayWriter with the specified initial size.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the stream.
|
void |
flush()
Flush the stream.
|
void |
reset()
Resets the buffer so that you can use it again without
throwing away the already allocated buffer.
|
int |
size()
Returns the current size of the buffer.
|
char[] |
toCharArray()
Returns a copy of the input data.
|
java.lang.String |
toString()
Converts input data to a string.
|
void |
write(char[] c,
int off,
int len)
Writes characters to the buffer.
|
void |
write(int c)
Writes a character to the buffer.
|
void |
write(java.lang.String str,
int off,
int len)
Write a portion of a string to the buffer.
|
void |
writeTo(java.io.Writer out)
Writes the contents of the buffer to another character stream.
|
protected char[] buf
protected int count
public CharArrayWriter()
public CharArrayWriter(int initialSize)
initialSize
- an int specifying the initial buffer size.java.lang.IllegalArgumentException
- if initialSize is negativepublic void write(int c)
write
in class java.io.Writer
public void write(char[] c, int off, int len)
write
in class java.io.Writer
c
- the data to be writtenoff
- the start offset in the datalen
- the number of chars that are writtenpublic void write(java.lang.String str, int off, int len)
write
in class java.io.Writer
str
- String to be written fromoff
- Offset from which to start reading characterslen
- Number of characters to be writtenpublic void writeTo(java.io.Writer out) throws java.io.IOException
out
- the output stream to write tojava.io.IOException
- If an I/O error occurs.public void reset()
public char[] toCharArray()
public int size()
public java.lang.String toString()
toString
in class java.lang.Object
public void flush()
flush
in interface java.io.Flushable
flush
in class java.io.Writer
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.Writer