public class UnicodeInputStream extends InputStream
This inputStream will recognize unicode BOM marks and will skip bytes if getEncoding() or skipBOM() method is called before any of the read(...) methods.
Usage pattern: String enc = "ISO-8859-1"; // or NULL to use systemDefault FileInputStream fis = new FileInputStream(file); UnicodeInputStream uin = new UnicodeInputStream(fis, enc); enc = uin.getEncoding(); // check and skip possible BOM bytes InputStreamReader in; if (enc == null) in = new InputStreamReader(uin); else in = new InputStreamReader(uin, enc); or: UnicodeInputStream uin = new UnicodeInputStream(fis, enc).skipBOM();
| 构造器和说明 |
|---|
UnicodeInputStream(InputStream in) |
UnicodeInputStream(InputStream in,
String defaultEnc) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
close() |
String |
getDefaultEncoding() |
String |
getEncoding() |
protected void |
init()
Read-ahead four bytes and check for BOM marks.
|
int |
read() |
UnicodeInputStream |
skipBOM() |
available, mark, markSupported, read, read, reset, skippublic UnicodeInputStream(InputStream in)
public UnicodeInputStream(InputStream in, String defaultEnc)
public UnicodeInputStream skipBOM()
public String getDefaultEncoding()
public String getEncoding()
protected void init()
throws IOException
IOExceptionpublic void close()
throws IOException
close 在接口中 Closeableclose 在接口中 AutoCloseableclose 在类中 InputStreamIOExceptionpublic int read()
throws IOException
read 在类中 InputStreamIOExceptionCopyright © 2015. All rights reserved.