java.io
Class CharArrayWriter

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.io.Writer sample code for java.io.Writer definition code for java.io.Writer 
      extended by java.io.CharArrayWriter
All Implemented Interfaces:
Closeable sample code for java.io.Closeable definition code for java.io.Closeable , Flushable sample code for java.io.Flushable definition code for java.io.Flushable , Appendable sample code for java.lang.Appendable definition code for java.lang.Appendable

public class CharArrayWriter
extends Writer sample code for java.io.Writer definition code for java.io.Writer

This class implements a character buffer that can be used as an Writer. The buffer automatically grows when data is written to the stream. The data can be retrieved using toCharArray() and toString().

Note: Invoking close() on this class has no effect, and methods of this class can be called after the stream has closed without generating an IOException.

Since:
JDK1.1

Field Summary
protected  char[] buf sample code for java.io.CharArrayWriter.buf definition code for java.io.CharArrayWriter.buf
          The buffer where data is stored.
protected  int count sample code for java.io.CharArrayWriter.count definition code for java.io.CharArrayWriter.count
          The number of chars in the buffer.
 
Fields inherited from class java.io.Writer sample code for java.io.Writer definition code for java.io.Writer
lock sample code for java.io.Writer.lock definition code for java.io.Writer.lock
 
Constructor Summary
CharArrayWriter sample code for java.io.CharArrayWriter.CharArrayWriter() definition code for java.io.CharArrayWriter.CharArrayWriter() ()
          Creates a new CharArrayWriter.
CharArrayWriter sample code for java.io.CharArrayWriter.CharArrayWriter(int) definition code for java.io.CharArrayWriter.CharArrayWriter(int) (int initialSize)
          Creates a new CharArrayWriter with the specified initial size.
 
Method Summary
 CharArrayWriter sample code for java.io.CharArrayWriter definition code for java.io.CharArrayWriter append sample code for java.io.CharArrayWriter.append(char) definition code for java.io.CharArrayWriter.append(char) (char c)
          Appends the specified character to this writer.
 CharArrayWriter sample code for java.io.CharArrayWriter definition code for java.io.CharArrayWriter append sample code for java.io.CharArrayWriter.append(java.lang.CharSequence) definition code for java.io.CharArrayWriter.append(java.lang.CharSequence) (CharSequence sample code for java.lang.CharSequence definition code for java.lang.CharSequence  csq)
          Appends the specified character sequence to this writer.
 CharArrayWriter sample code for java.io.CharArrayWriter definition code for java.io.CharArrayWriter append sample code for java.io.CharArrayWriter.append(java.lang.CharSequence, int, int) definition code for java.io.CharArrayWriter.append(java.lang.CharSequence, int, int) (CharSequence sample code for java.lang.CharSequence definition code for java.lang.CharSequence  csq, int start, int end)
          Appends a subsequence of the specified character sequence to this writer.
 void close sample code for java.io.CharArrayWriter.close() definition code for java.io.CharArrayWriter.close() ()
          Close the stream.
 void flush sample code for java.io.CharArrayWriter.flush() definition code for java.io.CharArrayWriter.flush() ()
          Flush the stream.
 void reset sample code for java.io.CharArrayWriter.reset() definition code for java.io.CharArrayWriter.reset() ()
          Resets the buffer so that you can use it again without throwing away the already allocated buffer.
 int size sample code for java.io.CharArrayWriter.size() definition code for java.io.CharArrayWriter.size() ()
          Returns the current size of the buffer.
 char[] toCharArray sample code for java.io.CharArrayWriter.toCharArray() definition code for java.io.CharArrayWriter.toCharArray() ()
          Returns a copy of the input data.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.io.CharArrayWriter.toString() definition code for java.io.CharArrayWriter.toString() ()
          Converts input data to a string.
 void write sample code for java.io.CharArrayWriter.write(char[], int, int) definition code for java.io.CharArrayWriter.write(char[], int, int) (char[] c, int off, int len)
          Writes characters to the buffer.
 void write sample code for java.io.CharArrayWriter.write(int) definition code for java.io.CharArrayWriter.write(int) (int c)
          Writes a character to the buffer.
 void write sample code for java.io.CharArrayWriter.write(java.lang.String, int, int) definition code for java.io.CharArrayWriter.write(java.lang.String, int, int) (String sample code for java.lang.String definition code for java.lang.String  str, int off, int len)
          Write a portion of a string to the buffer.
 void writeTo sample code for java.io.CharArrayWriter.writeTo(java.io.Writer) definition code for java.io.CharArrayWriter.writeTo(java.io.Writer) (Writer sample code for java.io.Writer definition code for java.io.Writer  out)
          Writes the contents of the buffer to another character stream.
 
Methods inherited from class java.io.Writer sample code for java.io.Writer definition code for java.io.Writer
write sample code for java.io.Writer.write(char[]) definition code for java.io.Writer.write(char[]) , write sample code for java.io.Writer.write(java.lang.String) definition code for java.io.Writer.write(java.lang.String)
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

buf sample code for java.io.CharArrayWriter.buf

protected char[] buf
The buffer where data is stored.


count sample code for java.io.CharArrayWriter.count

protected int count
The number of chars in the buffer.

Constructor Detail

CharArrayWriter sample code for java.io.CharArrayWriter() definition code for java.io.CharArrayWriter()

public CharArrayWriter()
Creates a new CharArrayWriter.


CharArrayWriter sample code for java.io.CharArrayWriter(int) definition code for java.io.CharArrayWriter(int)

public CharArrayWriter(int initialSize)
Creates a new CharArrayWriter with the specified initial size.

Parameters:
initialSize - an int specifying the initial buffer size.
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if initialSize is negative
Method Detail

write sample code for java.io.CharArrayWriter.write(int) definition code for java.io.CharArrayWriter.write(int)

public void write(int c)
Writes a character to the buffer.

Overrides:
write sample code for java.io.Writer.write(int) definition code for java.io.Writer.write(int) in class Writer sample code for java.io.Writer definition code for java.io.Writer
Parameters:
c - int specifying a character to be written.

write sample code for java.io.CharArrayWriter.write(char[], int, int) definition code for java.io.CharArrayWriter.write(char[], int, int)

public void write(char[] c,
                  int off,
                  int len)
Writes characters to the buffer.

Specified by:
write sample code for java.io.Writer.write(char[], int, int) definition code for java.io.Writer.write(char[], int, int) in class Writer sample code for java.io.Writer definition code for java.io.Writer
Parameters:
c - the data to be written
off - the start offset in the data
len - the number of chars that are written

write sample code for java.io.CharArrayWriter.write(java.lang.String, int, int) definition code for java.io.CharArrayWriter.write(java.lang.String, int, int)

public void write(String sample code for java.lang.String definition code for java.lang.String  str,
                  int off,
                  int len)
Write a portion of a string to the buffer.

Overrides:
write sample code for java.io.Writer.write(java.lang.String, int, int) definition code for java.io.Writer.write(java.lang.String, int, int) in class Writer sample code for java.io.Writer definition code for java.io.Writer
Parameters:
str - String to be written from
off - Offset from which to start reading characters
len - Number of characters to be written

writeTo sample code for java.io.CharArrayWriter.writeTo(java.io.Writer) definition code for java.io.CharArrayWriter.writeTo(java.io.Writer)

public void writeTo(Writer sample code for java.io.Writer definition code for java.io.Writer  out)
             throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Writes the contents of the buffer to another character stream.

Parameters:
out - the output stream to write to
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - If an I/O error occurs.

append sample code for java.io.CharArrayWriter.append(java.lang.CharSequence) definition code for java.io.CharArrayWriter.append(java.lang.CharSequence)

public CharArrayWriter sample code for java.io.CharArrayWriter definition code for java.io.CharArrayWriter  append(CharSequence sample code for java.lang.CharSequence definition code for java.lang.CharSequence  csq)
Appends the specified character sequence to this writer.

An invocation of this method of the form out.append(csq) behaves in exactly the same way as the invocation

     out.write(csq.toString()) 

Depending on the specification of toString for the character sequence csq, the entire sequence may not be appended. For instance, invoking the toString method of a character buffer will return a subsequence whose content depends upon the buffer's position and limit.

Specified by:
append sample code for java.lang.Appendable.append(java.lang.CharSequence) definition code for java.lang.Appendable.append(java.lang.CharSequence) in interface Appendable sample code for java.lang.Appendable definition code for java.lang.Appendable
Overrides:
append sample code for java.io.Writer.append(java.lang.CharSequence) definition code for java.io.Writer.append(java.lang.CharSequence) in class Writer sample code for java.io.Writer definition code for java.io.Writer
Parameters:
csq - The character sequence to append. If csq is null, then the four characters "null" are appended to this writer.
Returns:
This writer
Since:
1.5

append sample code for java.io.CharArrayWriter.append(java.lang.CharSequence, int, int) definition code for java.io.CharArrayWriter.append(java.lang.CharSequence, int, int)

public CharArrayWriter sample code for java.io.CharArrayWriter definition code for java.io.CharArrayWriter  append(CharSequence sample code for java.lang.CharSequence definition code for java.lang.CharSequence  csq,
                              int start,
                              int end)
Appends a subsequence of the specified character sequence to this writer.

An invocation of this method of the form out.append(csq, start, end) when csq is not null, behaves in exactly the same way as the invocation

     out.write(csq.subSequence(start, end).toString()) 

Specified by:
append sample code for java.lang.Appendable.append(java.lang.CharSequence, int, int) definition code for java.lang.Appendable.append(java.lang.CharSequence, int, int) in interface Appendable sample code for java.lang.Appendable definition code for java.lang.Appendable
Overrides:
append sample code for java.io.Writer.append(java.lang.CharSequence, int, int) definition code for java.io.Writer.append(java.lang.CharSequence, int, int) in class Writer sample code for java.io.Writer definition code for java.io.Writer
Parameters:
csq - The character sequence from which a subsequence will be appended. If csq is null, then characters will be appended as if csq contained the four characters "null".
start - The index of the first character in the subsequence
end - The index of the character following the last character in the subsequence
Returns:
This writer
Throws:
IndexOutOfBoundsException sample code for java.lang.IndexOutOfBoundsException definition code for java.lang.IndexOutOfBoundsException - If start or end are negative, start is greater than end, or end is greater than csq.length()
Since:
1.5

append sample code for java.io.CharArrayWriter.append(char) definition code for java.io.CharArrayWriter.append(char)

public CharArrayWriter sample code for java.io.CharArrayWriter definition code for java.io.CharArrayWriter  append(char c)
Appends the specified character to this writer.

An invocation of this method of the form out.append(c) behaves in exactly the same way as the invocation

     out.write(c) 

Specified by:
append sample code for java.lang.Appendable.append(char) definition code for java.lang.Appendable.append(char) in interface Appendable sample code for java.lang.Appendable definition code for java.lang.Appendable
Overrides:
append sample code for java.io.Writer.append(char) definition code for java.io.Writer.append(char) in class Writer sample code for java.io.Writer definition code for java.io.Writer
Parameters:
c - The 16-bit character to append
Returns:
This writer
Since:
1.5

reset sample code for java.io.CharArrayWriter.reset() definition code for java.io.CharArrayWriter.reset()

public void reset()
Resets the buffer so that you can use it again without throwing away the already allocated buffer.


toCharArray sample code for java.io.CharArrayWriter.toCharArray() definition code for java.io.CharArrayWriter.toCharArray()

public char[] toCharArray()
Returns a copy of the input data.

Returns:
an array of chars copied from the input data.

size sample code for java.io.CharArrayWriter.size() definition code for java.io.CharArrayWriter.size()

public int size()
Returns the current size of the buffer.

Returns:
an int representing the current size of the buffer.

toString sample code for java.io.CharArrayWriter.toString() definition code for java.io.CharArrayWriter.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Converts input data to a string.

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
the string.

flush sample code for java.io.CharArrayWriter.flush() definition code for java.io.CharArrayWriter.flush()

public void flush()
Flush the stream.

Specified by:
flush sample code for java.io.Flushable.flush() definition code for java.io.Flushable.flush() in interface Flushable sample code for java.io.Flushable definition code for java.io.Flushable
Specified by:
flush sample code for java.io.Writer.flush() definition code for java.io.Writer.flush() in class Writer sample code for java.io.Writer definition code for java.io.Writer

close sample code for java.io.CharArrayWriter.close() definition code for java.io.CharArrayWriter.close()

public void close()
Close the stream. This method does not release the buffer, since its contents might still be required. Note: Invoking this method in this class will have no effect.

Specified by:
close sample code for java.io.Closeable.close() definition code for java.io.Closeable.close() in interface Closeable sample code for java.io.Closeable definition code for java.io.Closeable
Specified by:
close sample code for java.io.Writer.close() definition code for java.io.Writer.close() in class Writer sample code for java.io.Writer definition code for java.io.Writer