Class UnicodeInputStream

java.lang.Object
java.io.InputStream
org.apache.velocity.io.UnicodeInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class UnicodeInputStream extends InputStream
This is an input stream that is unicode BOM aware. This allows you to e.g. read Windows Notepad Unicode files as Velocity templates. It allows you to check the actual encoding of a file by calling getEncodingFromStream() on the input stream reader. This class is not thread safe! When more than one thread wants to use an instance of UnicodeInputStream, the caller must provide synchronization.
Since:
1.5
Version:
$Id$
Author:
Aki Nieminen, Henning P. Schmiedehausen
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.apache.velocity.io.UnicodeInputStream.UnicodeBOM
    BOM Marker for UTF 16, big endian.
    static final org.apache.velocity.io.UnicodeInputStream.UnicodeBOM
    BOM Marker for UTF 16, little endian.
    static final org.apache.velocity.io.UnicodeInputStream.UnicodeBOM
    BOM Marker for UTF 32, big endian.
    static final org.apache.velocity.io.UnicodeInputStream.UnicodeBOM
    BOM Marker for UTF 32, little endian.
    static final org.apache.velocity.io.UnicodeInputStream.UnicodeBOM
    BOM Marker for UTF 8.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new UnicodeInputStream object.
    UnicodeInputStream(InputStream inputStream, boolean skipBOM)
    Creates a new UnicodeInputStream object.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    void
     
    Read encoding based on BOM.
    boolean
    Returns true if the input stream discards the BOM.
    void
    mark(int readlimit)
     
    boolean
     
    int
     
    int
    read(byte[] b)
     
    int
    read(byte[] b, int off, int len)
     
    protected String
    This method gets the encoding from the stream contents if a BOM exists.
    void
     
    static boolean
    sameEncoding(String left, String right)
    Helper function to compare encodings
    long
    skip(long n)
     

    Methods inherited from class java.lang.Object

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

    • UTF8_BOM

      public static final org.apache.velocity.io.UnicodeInputStream.UnicodeBOM UTF8_BOM
      BOM Marker for UTF 8. See http://www.unicode.org/unicode/faq/utf_bom.html
    • UTF16LE_BOM

      public static final org.apache.velocity.io.UnicodeInputStream.UnicodeBOM UTF16LE_BOM
      BOM Marker for UTF 16, little endian. See http://www.unicode.org/unicode/faq/utf_bom.html
    • UTF16BE_BOM

      public static final org.apache.velocity.io.UnicodeInputStream.UnicodeBOM UTF16BE_BOM
      BOM Marker for UTF 16, big endian. See http://www.unicode.org/unicode/faq/utf_bom.html
    • UTF32LE_BOM

      public static final org.apache.velocity.io.UnicodeInputStream.UnicodeBOM UTF32LE_BOM
      BOM Marker for UTF 32, little endian. See http://www.unicode.org/unicode/faq/utf_bom.html
    • UTF32BE_BOM

      public static final org.apache.velocity.io.UnicodeInputStream.UnicodeBOM UTF32BE_BOM
      BOM Marker for UTF 32, big endian. See http://www.unicode.org/unicode/faq/utf_bom.html
  • Constructor Details

  • Method Details