Save This Page
Home » apache-harmony-6.0-src-r917296-snapshot » java » io » [javadoc | source]
java.io
public class: OutputStreamWriter [javadoc | source]
java.lang.Object
   java.io.Writer
      java.io.OutputStreamWriter

All Implemented Interfaces:
    Flushable, Closeable, Appendable

Direct Known Subclasses:
    FileWriter

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. {@code OutputStreamWriter} contains a buffer of bytes to be written to target stream and converts these into characters as needed. The buffer size is 8K.
Fields inherited from java.io.Writer:
TOKEN_NULL,  lock
Constructor:
 public OutputStreamWriter(OutputStream out) 
    Constructs a new OutputStreamWriter using {@code 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.
 public OutputStreamWriter(OutputStream out,
    String enc) throws UnsupportedEncodingException 
    Constructs a new OutputStreamWriter using {@code out} as the target stream to write converted characters to and {@code 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 {@code enc} is {@code null}.
    UnsupportedEncodingException - if the encoding specified by {@code enc} cannot be found.
 public OutputStreamWriter(OutputStream out,
    Charset cs) 
    Constructs a new OutputStreamWriter using {@code out} as the target stream to write converted characters to and {@code cs} as the character encoding.
    Parameters:
    out - the target stream to write converted bytes to.
    cs - the {@code Charset} that specifies the character encoding.
 public OutputStreamWriter(OutputStream out,
    CharsetEncoder enc) 
    Constructs a new OutputStreamWriter using {@code out} as the target stream to write converted characters to and {@code enc} as the character encoder.
    Parameters:
    out - the target stream to write converted bytes to.
    enc - the character encoder used for character conversion.
Method from java.io.OutputStreamWriter Summary:
checkError,   close,   flush,   getEncoding,   write,   write,   write
Methods from java.io.Writer:
append,   append,   append,   checkError,   close,   flush,   write,   write,   write,   write,   write
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.io.OutputStreamWriter Detail:
 boolean checkError() 
 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.

 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.
 public String getEncoding() 
    Gets the name of the encoding that is used to convert characters to bytes.
 public  void write(int oneChar) throws IOException 
    Writes the character {@code oneChar} to this writer. The lowest two bytes of the integer {@code 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.
 public  void write(char[] buf,
    int offset,
    int count) throws IOException 
    Writes {@code count} characters starting at {@code offset} in {@code 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.
 public  void write(String str,
    int offset,
    int count) throws IOException 
    Writes {@code count} characters starting at {@code offset} in {@code 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.