Package de.hybris.bootstrap.xml
Class UnicodeInputStream
- java.lang.Object
-
- java.io.InputStream
-
- de.hybris.bootstrap.xml.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)
-
-
-
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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException
- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException
- Overrides:
available
in classjava.io.InputStream
- Throws:
java.io.IOException
-
-