liquibase.resource
Class UtfBomAwareReader

java.lang.Object
  extended by java.io.Reader
      extended by liquibase.resource.UtfBomAwareReader
All Implemented Interfaces:
Closeable, Readable

public class UtfBomAwareReader
extends Reader

Reader that tries to identify the encoding by looking at the BOM. If no BOM is found it defaults to the encoding givent at initialization. Original ideas from Thomas Weidenfeller, Aki Nieminen.

Author:
Dominique Broeglin

Field Summary
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
UtfBomAwareReader(InputStream in)
           
UtfBomAwareReader(InputStream in, String defaultCharsetName)
           
 
Method Summary
 void close()
           
 String getDefaultEncoding()
           
 String getEncoding()
           
protected  void init()
          Read up to 4 bytes to determine the BOM.
 int read(char[] cbuf, int off, int len)
           
 
Methods inherited from class java.io.Reader
mark, markSupported, read, read, read, ready, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UtfBomAwareReader

public UtfBomAwareReader(InputStream in)

UtfBomAwareReader

public UtfBomAwareReader(InputStream in,
                         String defaultCharsetName)
Method Detail

getDefaultEncoding

public String getDefaultEncoding()

getEncoding

public String getEncoding()

init

protected void init()
             throws IOException
Read up to 4 bytes to determine the BOM. Extra bytes, of if no BOM is found are pushed back to the input stream. If no BOM is found, the defaultCharsetName is used to initialize the reader.

Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in class Reader
Throws:
IOException

read

public int read(char[] cbuf,
                int off,
                int len)
         throws IOException
Specified by:
read in class Reader
Throws:
IOException


Copyright © 2016 Liquibase.org. All rights reserved.