Class UnicodeInputStream

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

    public class UnicodeInputStream
    extends java.io.InputStream
    This inputstream will recognize unicode BOM marks and will skip bytes if getEncoding() method is called before any of the read(...) methods. Invoking read methods without first calling getEncoding will not skip BOM mark.

    Usage pattern: String enc = "ISO-8859-1"; // or put NULL to use systemdefault FileInputStream fis = new FileInputStream(file); UnicodeInputStream uin = new UnicodeInputStream(fis, enc); enc = uin.getEncoding(); // check for BOM mark and skip bytes InputStreamReader in; if (enc == null) in = new InputStreamReader(uin); else in = new InputStreamReader(uin, enc);

    • Constructor Summary

      Constructors 
      Constructor Description
      UnicodeInputStream​(java.io.InputStream in, java.lang.String defaultEnc)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      void close()  
      java.lang.String getDefaultEncoding()  
      java.lang.String getEncoding()
      Read encoding based on BOM mark and skip bytes.
      protected void init()
      Read-ahead four bytes and check for BOM marks.
      boolean isBOMSkipped()  
      int read()  
      void setSkipBOM​(boolean b)  
      • Methods inherited from class java.io.InputStream

        mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

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

      • UnicodeInputStream

        public UnicodeInputStream​(java.io.InputStream in,
                                  java.lang.String defaultEnc)
    • Method Detail

      • isBOMSkipped

        public boolean isBOMSkipped()
      • setSkipBOM

        public void setSkipBOM​(boolean b)
      • getDefaultEncoding

        public java.lang.String getDefaultEncoding()
      • getEncoding

        public java.lang.String getEncoding()
        Read encoding based on BOM mark and skip bytes. All non-mark bytes are unread back to the stream.
      • init

        protected void init()
                     throws java.io.IOException
        Read-ahead four bytes and check for BOM marks. Extra bytes are unread back to the stream, only BOM bytes are skipped.
        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
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        Overrides:
        available in class java.io.InputStream
        Throws:
        java.io.IOException