Build 1.1_r1 (from source)

java.io
Class OutputStreamWriter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.OutputStreamWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable
Direct Known Subclasses:
FileWriter

public class OutputStreamWriter
extends Writer

A class for turning a character stream into a byte stream. Data written to the target input stream is converted into bytes by either a default or a provided character converter. The default encoding is taken from the "file.encoding" system property. OutputStreamWriter contains a buffer of bytes to be written to target stream and converts these into characters as needed. The buffer size is 8K.

Since:
Android 1.0
See Also:
InputStreamReader

Field Summary
 
Fields inherited from class java.io.Writer
lock, TOKEN_NULL
 
Constructor Summary
OutputStreamWriter(OutputStream out)
          Constructs a new OutputStreamWriter using out as the target stream to write converted characters to.
OutputStreamWriter(OutputStream out, Charset cs)
          Constructs a new OutputStreamWriter using out as the target stream to write converted characters to and cs as the character encoding.
OutputStreamWriter(OutputStream out, CharsetEncoder enc)
          Constructs a new OutputStreamWriter using out as the target stream to write converted characters to and enc as the character encoder.
OutputStreamWriter(OutputStream out, String enc)
          Constructs a new OutputStreamWriter using out as the target stream to write converted characters to and enc as the character encoding.
 
Method Summary
 void close()
          Closes this writer.
 void flush()
          Flushes this writer.
 String getEncoding()
          Gets the name of the encoding that is used to convert characters to bytes.
 void write(char[] buf, int offset, int count)
          Writes count characters starting at offset in buf to this writer.
 void write(int oneChar)
          Writes the character oneChar to this writer.
 void write(String str, int offset, int count)
          Writes count characters starting at offset in str to this writer.
 
Methods inherited from class java.io.Writer
append, append, append, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OutputStreamWriter

public OutputStreamWriter(OutputStream out)
Constructs a new OutputStreamWriter using out as the target stream to write converted characters to. The default character encoding is used.

Parameters:
out - the non-null target stream to write converted bytes to.
Since:
Android 1.0

OutputStreamWriter

public OutputStreamWriter(OutputStream out,
                          String enc)
                   throws UnsupportedEncodingException
Constructs a new OutputStreamWriter using out as the target stream to write converted characters to and enc as the character encoding. If the encoding cannot be found, an UnsupportedEncodingException error is thrown.

Parameters:
out - the target stream to write converted bytes to.
enc - the string describing the desired character encoding.
Throws:
NullPointerException - if enc is null.
UnsupportedEncodingException - if the encoding specified by enc cannot be found.
Since:
Android 1.0

OutputStreamWriter

public OutputStreamWriter(OutputStream out,
                          Charset cs)
Constructs a new OutputStreamWriter using out as the target stream to write converted characters to and cs as the character encoding.

Parameters:
out - the target stream to write converted bytes to.
cs - the Charset that specifies the character encoding.
Since:
Android 1.0

OutputStreamWriter

public OutputStreamWriter(OutputStream out,
                          CharsetEncoder enc)
Constructs a new OutputStreamWriter using out as the target stream to write converted characters to and enc as the character encoder.

Parameters:
out - the target stream to write converted bytes to.
enc - the character encoder used for character conversion.
Since:
Android 1.0
Method Detail

close

public void close()
           throws IOException
Closes this writer. This implementation flushes the buffer as well as the target stream. The target stream is then closed and the resources for the buffer and converter are released.

Only the first invocation of this method has any effect. Subsequent calls do nothing.

Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException - if an error occurs while closing this writer.
Since:
Android 1.0

flush

public void flush()
           throws IOException
Flushes this writer. This implementation ensures that all buffered bytes are written to the target stream. After writing the bytes, the target stream is flushed as well.

Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
IOException - if an error occurs while flushing this writer.
Since:
Android 1.0

getEncoding

public String getEncoding()
Gets the name of the encoding that is used to convert characters to bytes.

Returns:
the string describing the converter or null if this writer is closed.
Since:
Android 1.0

write

public void write(char[] buf,
                  int offset,
                  int count)
           throws IOException
Writes count characters starting at offset in buf to this writer. The characters are immediately converted to bytes by the character converter and stored in a local buffer. If the buffer gets full as a result of the conversion, this writer is flushed.

Specified by:
write in class Writer
Parameters:
buf - the array containing characters to write.
offset - the index of the first character in buf to write.
count - the maximum number of characters to write.
Throws:
IndexOutOfBoundsException - if offset < 0 or count < 0, or if offset + count is greater than the size of buf.
IOException - if this writer has already been closed or another I/O error occurs.
Since:
Android 1.0

write

public void write(int oneChar)
           throws IOException
Writes the character oneChar to this writer. The lowest two bytes of the integer oneChar are immediately converted to bytes by the character converter and stored in a local buffer. If the buffer gets full by converting this character, this writer is flushed.

Overrides:
write in class Writer
Parameters:
oneChar - the character to write.
Throws:
IOException - if this writer is closed or another I/O error occurs.
Since:
Android 1.0

write

public void write(String str,
                  int offset,
                  int count)
           throws IOException
Writes count characters starting at offset in str to this writer. The characters are immediately converted to bytes by the character converter and stored in a local buffer. If the buffer gets full as a result of the conversion, this writer is flushed.

Overrides:
write in class Writer
Parameters:
str - the string containing characters to write.
offset - the start position in str for retrieving characters.
count - the maximum number of characters to write.
Throws:
IOException - if this writer has already been closed or another I/O error occurs.
IndexOutOfBoundsException - if offset < 0 or count < 0, or if offset + count is bigger than the length of str.
Since:
Android 1.0

Build 1.1_r1 (from source)

Please submit a feedback, bug or feature