jodd.io
Class UnicodeInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by jodd.io.UnicodeInputStream
All Implemented Interfaces:
java.io.Closeable

public class UnicodeInputStream
extends java.io.InputStream

Unicode input stream detects and decodes BOM character. Detects following BOMs: UTF-8, UTF-16BE, UTF-16LE, UTF-32BE, UTF-32LE.


Field Summary
static int MAX_BOM_SIZE
           
 
Constructor Summary
UnicodeInputStream(java.io.InputStream in)
          Creates new unicode stream with default UTF-8 encoding.
UnicodeInputStream(java.io.InputStream in, java.lang.String defaultEncoding)
          Creates new unicode stream with provided default encoding.
 
Method Summary
 void close()
          Closes input stream.
 int getBOMSize()
          Returns BOM size in bytes.
 java.lang.String getDefaultEncoding()
          Returns default encoding.
 java.lang.String getEncoding()
          Returns detected encoding.
protected  void init()
          Detects and decodes encoding from BOM character.
 int read()
          Reads byte from the stream.
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_BOM_SIZE

public static final int MAX_BOM_SIZE
See Also:
Constant Field Values
Constructor Detail

UnicodeInputStream

public UnicodeInputStream(java.io.InputStream in)
Creates new unicode stream with default UTF-8 encoding.


UnicodeInputStream

public UnicodeInputStream(java.io.InputStream in,
                          java.lang.String defaultEncoding)
Creates new unicode stream with provided default encoding. Default encoding is the one used if BOM is missing or not recognized.

Method Detail

getDefaultEncoding

public java.lang.String getDefaultEncoding()
Returns default encoding.


getEncoding

public java.lang.String getEncoding()
Returns detected encoding. If stream is not read yet, it will be initalized first.


init

protected void init()
             throws java.io.IOException
Detects and decodes encoding from BOM character. Reads ahead four bytes and check for BOM marks. Extra bytes are unread back to the stream, so only BOM bytes are skipped.

Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Closes input stream. If stream was not used, encoding will be unavailable.

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
Reads byte from the stream.

Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

getBOMSize

public int getBOMSize()
Returns BOM size in bytes.



Copyright © 2003-2012 Jodd Team