Class UnicodeOutputStreamWriter

  • All Implemented Interfaces:
    Closeable, Flushable, Appendable, AutoCloseable
    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:
    • As a standard output stream writer that uses the default JVM charset.
    • A writer that uses a specific charset and (optionally) injects a specific signature in the header of the output stream.
    • A writer that uses the signature/charset which a supplied reader had used to decode a byte stream. This is useful when a file is modified, and the original signature/charset must be preserved.
    Since:
    0.6.0
    Version:
    $Id: UnicodeOutputStreamWriter.java 16154 2012-07-14 16:34:05Z colin $
    Author:
    tlerios@marketcetera.com
    • 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.