Package org.fife.io

Class UnicodeWriter

  • All Implemented Interfaces:
    Closeable, Flushable, Appendable, AutoCloseable

    public class UnicodeWriter
    extends Writer
    Writes Unicode text to an output stream. If the specified encoding is a Unicode, then the text is preceded by the proper Unicode BOM. If it is any other encoding, this class behaves just like OutputStreamWriter. This class is here because Java's OutputStreamWriter apparently doesn't believe in writing BOMs.

    For optimum performance, it is recommended that you wrap all instances of UnicodeWriter with a java.io.BufferedWriter.

    • Field Detail

      • PROPERTY_WRITE_UTF8_BOM

        public static final String PROPERTY_WRITE_UTF8_BOM
        If this system property evaluates to "false", ignoring case, files written out as UTF-8 will not have a BOM written for them. Otherwise (even if the property is not set), UTF-8 files will have a BOM written.
        See Also:
        Constant Field Values
    • Method Detail

      • getEncoding

        public String getEncoding()
        Returns the encoding being used to write this output stream (i.e., the encoding of the file).
        Returns:
        The encoding of the stream.
      • getWriteUtf8BOM

        public static boolean getWriteUtf8BOM()
        Returns whether UTF-8 files should have a BOM in them when written.
        Returns:
        Whether to write a BOM for UTF-8 files.
        See Also:
        setWriteUtf8BOM(boolean), UnicodeWriter
      • setWriteUtf8BOM

        public static void setWriteUtf8BOM​(boolean write)
        Sets whether UTF-8 files should have a BOM written in them.
        Parameters:
        write - Whether to write a BOM.
        See Also:
        getWriteUtf8BOM(), UnicodeWriter
      • write

        public void write​(char[] cbuf,
                          int off,
                          int len)
                   throws IOException
        Writes a portion of an array of characters.
        Specified by:
        write in class Writer
        Parameters:
        cbuf - The buffer of characters.
        off - The offset from which to start writing characters.
        len - The number of characters to write.
        Throws:
        IOException - If an I/O error occurs.
      • write

        public void write​(int c)
                   throws IOException
        Writes a single character.
        Overrides:
        write in class Writer
        Parameters:
        c - An integer specifying the character to write.
        Throws:
        IOException - If an IO error occurs.
      • write

        public void write​(String str,
                          int off,
                          int len)
                   throws IOException
        Writes a portion of a string.
        Overrides:
        write in class Writer
        Parameters:
        str - The string from which to write.
        off - The offset from which to start writing characters.
        len - The number of characters to write.
        Throws:
        IOException - If an IO error occurs.