Class UnicodeEscapeWriter

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.Appendable, java.lang.AutoCloseable

    public class UnicodeEscapeWriter
    extends java.io.FilterWriter
    The UnicodeEscapeWriter is a filter for translating unicode characters above the ANSI (8-bit) region into unicode escape sequences as specific by the Java specification (\ uxxxx). Any backslashes will also be escaped with a second backslash. These escapes can be decoded with the UnicodeEscapeReader.

    Here's an example of how to set up a Writer stream to use this filter:

     BufferedWriter out = new BufferedWriter(new UnicodeEscapeWriter(new FileWriter(filename)));
     

    See Also:
    UnicodeEscapeReader
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean escapeSlashes  
      protected java.io.Writer out  
      • Fields inherited from class java.io.Writer

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      UnicodeEscapeWriter​(java.io.Writer out)
      Create a Writer for filtering unicode characters into escape sequences
      UnicodeEscapeWriter​(java.io.Writer out, boolean escapeSlashes)
      Create a Writer for filtering unicode characters into escape sequences
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean getEscapeSlashes()
      Determine whehter backslashes are being escaped or not
      void setEscapeSlashes​(boolean escapeSlashes)
      Set whether to escape backslashes passed through this writer or not.
      void write​(char[] cbuff, int off, int len)
      Write characters from a buffer into a stream.
      void write​(int c)
      Writes a character into a stream.
      void write​(java.lang.String str, int off, int len)
      Write characters from a buffer into a stream.
      • Methods inherited from class java.io.FilterWriter

        close, flush
      • Methods inherited from class java.io.Writer

        append, append, append, nullWriter, write, write
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • out

        protected java.io.Writer out
      • escapeSlashes

        protected boolean escapeSlashes
    • Constructor Detail

      • UnicodeEscapeWriter

        public UnicodeEscapeWriter​(java.io.Writer out)
        Create a Writer for filtering unicode characters into escape sequences
        Parameters:
        out - The stream which is to be filtered
      • UnicodeEscapeWriter

        public UnicodeEscapeWriter​(java.io.Writer out,
                                   boolean escapeSlashes)
        Create a Writer for filtering unicode characters into escape sequences
        Parameters:
        out - The stream which is to be filtered
        escapeSlashes - If false, then only unicode characters will be escape and not backslashes. Default is true.
    • Method Detail

      • write

        public void write​(char[] cbuff,
                          int off,
                          int len)
                   throws java.io.IOException
        Write characters from a buffer into a stream. This version of write will write out data to the stream and convert any unicode characters above the ANSI region into unicode escape sequences. Backslashes will also be escaped with a second backslash so that unicode escape sequences can be distinguished from a backslash-u character sequence.
        Overrides:
        write in class java.io.FilterWriter
        Parameters:
        cbuff - Buffer of characters to be copied to the output stream
        off - Offset into the cbuff from which to start copying characters into the stream.
        len - The number of characters to copy into the stream.
        Throws:
        java.io.IOException
      • write

        public void write​(java.lang.String str,
                          int off,
                          int len)
                   throws java.io.IOException
        Write characters from a buffer into a stream. This version of write will write out data to the stream and convert any unicode characters above the ANSI region into unicode escape sequences. Backslashes will also be escaped with a second backslash so that unicode escape sequences can be distinguished from a backslash-u character sequence.
        Overrides:
        write in class java.io.FilterWriter
        Parameters:
        str - Buffer of characters to be copied to the output stream
        off - Offset into the cbuff from which to start copying characters into the stream.
        len - The number of characters to copy into the stream.
        Throws:
        java.io.IOException
      • write

        public void write​(int c)
                   throws java.io.IOException
        Writes a character into a stream. This version of write will write out data to the stream and convert any unicode characters above the ANSI region into unicode escape sequences. Backslashes will also be escaped with a second backslash so that unicode escape sequences can be distinguished from a backslash-u character sequence.
        Overrides:
        write in class java.io.FilterWriter
        Parameters:
        c - Character to be copied to the output stream
        Throws:
        java.io.IOException
      • setEscapeSlashes

        public void setEscapeSlashes​(boolean escapeSlashes)
        Set whether to escape backslashes passed through this writer or not.
        Parameters:
        escapeSlashes - True to have backslashes escaped in this stream
      • getEscapeSlashes

        public boolean getEscapeSlashes()
        Determine whehter backslashes are being escaped or not
        Returns:
        True if backslashes are being escaped in this stream