org.marketcetera.util.unicode
Class UnicodeOutputStreamWriter

java.lang.Object
  extended by java.io.Writer
      extended by org.marketcetera.util.unicode.UnicodeOutputStreamWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable
Direct Known Subclasses:
UnicodeFileWriter

public class UnicodeOutputStreamWriter
extends Writer

A variation of OutputStreamWriter that is BOM-aware. It can operate in any of the following modes:

Since:
0.6.0
Version:
$Id: UnicodeOutputStreamWriter.java 16154 2012-07-14 16:34:05Z colin $
Author:
tlerios@marketcetera.com

Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
  UnicodeOutputStreamWriter(OutputStream stream)
          Creates a new writer over the given stream that uses the default JVM charset (and no signature is injected).
  UnicodeOutputStreamWriter(OutputStream stream, Reader reader)
          Creates a new writer over the given stream that uses the actual signature/charset of the given reader.
protected UnicodeOutputStreamWriter(OutputStream stream, Reader reader, boolean writeSignature)
          Creates a new writer over the given stream that uses the actual signature/charset of the given reader.
  UnicodeOutputStreamWriter(OutputStream stream, SignatureCharset requestedSignatureCharset)
          Creates a new writer over the given stream that normally injects the given signature, and uses its associated charset for encoding.
protected UnicodeOutputStreamWriter(OutputStream stream, SignatureCharset requestedSignatureCharset, boolean writeSignature)
          Creates a new writer over the given stream that normally injects the given signature, and uses its associated charset for encoding.
 
Method Summary
 Writer append(char c)
           
 Writer append(CharSequence csq)
           
 Writer append(CharSequence csq, int start, int end)
           
 void close()
           
 void flush()
           
 SignatureCharset getRequestedSignatureCharset()
          Returns the receiver's requested signature/charset.
 SignatureCharset getSignatureCharset()
          Returns the receiver's actual signature/charset (that is, the one in use to encode the stream).
 void write(char[] cbuf)
           
 void write(char[] cbuf, int off, int len)
           
 void write(int c)
           
 void write(String str)
           
 void write(String str, int off, int len)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnicodeOutputStreamWriter

public UnicodeOutputStreamWriter(OutputStream stream)
Creates a new writer over the given stream that uses the default JVM charset (and no signature is injected).

Parameters:
stream - The stream.

UnicodeOutputStreamWriter

protected UnicodeOutputStreamWriter(OutputStream stream,
                                    SignatureCharset requestedSignatureCharset,
                                    boolean writeSignature)
Creates a new writer over the given stream that normally injects the given signature, and uses its associated charset for encoding. However, if the charset in the given signature/charset pair is not supported by the JVM, the default JVM charset is used instead (and no signature is injected). Signature injection is also skipped if the given flag is set to false (even if the signature/charset pair has a signature).

Parameters:
stream - The stream.
requestedSignatureCharset - The signature/charset. It may be null to use the default JVM charset.
writeSignature - True if a signature (if any) should be written.

UnicodeOutputStreamWriter

public UnicodeOutputStreamWriter(OutputStream stream,
                                 SignatureCharset requestedSignatureCharset)
Creates a new writer over the given stream that normally injects the given signature, and uses its associated charset for encoding. However, if the charset in the given signature/charset pair is not supported by the JVM, the default JVM charset is used instead (and no signature is injected).

Parameters:
stream - The stream.
requestedSignatureCharset - The signature/charset. It may be null to use the default JVM charset.

UnicodeOutputStreamWriter

protected UnicodeOutputStreamWriter(OutputStream stream,
                                    Reader reader,
                                    boolean writeSignature)
                             throws IOException
Creates a new writer over the given stream that uses the actual signature/charset of the given reader. If the reader is not a valid instance of a UnicodeInputStreamReader, or if it used the default JVM charset, then the writer uses the default JVM charset (and no signature is injected). Signature injection is also skipped if the given flag is set to false (even if the given reader's signature/charset pair has a signature).

Parameters:
stream - The stream.
reader - The reader.
writeSignature - True if a signature (if any) should be written.
Throws:
IOException - Thrown if an I/O error occurs.

UnicodeOutputStreamWriter

public UnicodeOutputStreamWriter(OutputStream stream,
                                 Reader reader)
                          throws IOException
Creates a new writer over the given stream that uses the actual signature/charset of the given reader. If the reader is not a valid instance of a UnicodeInputStreamReader, or if it used the default JVM charset, then the writer uses the default JVM charset (and no signature is injected).

Parameters:
stream - The stream.
reader - The reader.
Throws:
IOException - Thrown if an I/O error occurs.
Method Detail

write

public void write(int c)
           throws IOException
Overrides:
write in class Writer
Throws:
IOException

write

public void write(char[] cbuf)
           throws IOException
Overrides:
write in class Writer
Throws:
IOException

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws IOException
Specified by:
write in class Writer
Throws:
IOException

write

public void write(String str)
           throws IOException
Overrides:
write in class Writer
Throws:
IOException

write

public void write(String str,
                  int off,
                  int len)
           throws IOException
Overrides:
write in class Writer
Throws:
IOException

append

public Writer append(CharSequence csq)
              throws IOException
Specified by:
append in interface Appendable
Overrides:
append in class Writer
Throws:
IOException

append

public Writer append(CharSequence csq,
                     int start,
                     int end)
              throws IOException
Specified by:
append in interface Appendable
Overrides:
append in class Writer
Throws:
IOException

append

public Writer append(char c)
              throws IOException
Specified by:
append in interface Appendable
Overrides:
append in class Writer
Throws:
IOException

flush

public void flush()
           throws IOException
Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException

getRequestedSignatureCharset

public SignatureCharset getRequestedSignatureCharset()
Returns the receiver's requested signature/charset. This pair may have either been requested directly or by requesting that a reader's actual signature/charset be matched.

Returns:
The requested signature/charset, which may be null if none was requested.

getSignatureCharset

public SignatureCharset getSignatureCharset()
                                     throws IOException
Returns the receiver's actual signature/charset (that is, the one in use to encode the stream).

Returns:
The signature/charset, which may be null if the default JVM charset is used.
Throws:
IOException - Thrown if an I/O error occurs.


Copyright © 2012. All Rights Reserved.