Class InvalidXmlCharacterFilter

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

    public class InvalidXmlCharacterFilter
    extends java.io.Reader
    FilterInputStream that gets rid of characters that are invalid in an XML 1.0 document. Although these characters are forbidden, in the real wold they still appear in XML files. Java's SAX parser throws an exception, so we have to filter at a lower level. Only handles control characters (<0x20). Invalid characters are replaced by space (0x20).
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static boolean firstWarning  
      private static boolean[] INVALID_CHARS  
      private java.io.Reader reader  
      • Fields inherited from class java.io.Reader

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      InvalidXmlCharacterFilter​(java.io.Reader reader)
      Constructs a new InvalidXmlCharacterFilter for the given Reader.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      private static char filter​(char in)  
      int read​(char[] b, int off, int len)  
      • Methods inherited from class java.io.Reader

        mark, markSupported, nullReader, read, read, read, ready, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

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

      • InvalidXmlCharacterFilter

        public InvalidXmlCharacterFilter​(java.io.Reader reader)
        Constructs a new InvalidXmlCharacterFilter for the given Reader.
        Parameters:
        reader - The reader to filter
    • Method Detail

      • read

        public int read​(char[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Specified by:
        read in class java.io.Reader
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class java.io.Reader
        Throws:
        java.io.IOException
      • filter

        private static char filter​(char in)