Package org.aoju.bus.core.io.stream
Class BOMInputStream
java.lang.Object
java.io.InputStream
org.aoju.bus.core.io.stream.BOMInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
读取带BOM头的流内容,
getCharset()方法调用后会得到BOM头的编码,且会去除BOM头
- 00 00 FE FF = UTF-32, big-endian
- FF FE 00 00 = UTF-32, little-endian
- EF BB BF = UTF-8
- FE FF = UTF-16, big-endian
- FF FE = UTF-16, little-endian
String enc = "UTF-8"; // or NULL to use systemdefault
FileInputStream fis = new FileInputStream(file);
BOMInputStream uin = new BOMInputStream(fis, enc);
enc = uin.getCharset(); // check and skip possible BOM bytes
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Constructor Details
-
BOMInputStream
-
BOMInputStream
构造- Parameters:
in- 流defaultCharset- 默认编码
-
-
Method Details
-
getDefaultCharset
-
getCharset
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
init
预读四个字节并检查BOM标记 额外的字节未读回流,只有BOM字节被跳过- Throws:
IOException- 读取引起的异常
-