Class UnicodeBOMInputStream
- java.lang.Object
-
- java.io.InputStream
-
- com.github.dannil.scbjavaclient.utility.UnicodeBOMInputStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class UnicodeBOMInputStream extends InputStream
TheUnicodeBOMInputStreamclass wraps anyInputStreamand detects the presence of any Unicode BOM (Byte Order Mark) at its beginning, as defined by RFC 3629 - UTF-8, a transformation format of ISO 10646.The Unicode FAQ defines 5 types of BOMs:
-
00 00 FE FF = UTF-32, big-endian
-
FF FE 00 00 = UTF-32, little-endian
-
FE FF = UTF-16, big-endian
-
FF FE = UTF-16, little-endian
-
EF BB BF = UTF-8
Use the
getBOM()method to know whether a BOM has been detected or not.Use the
skipBOM()method to remove the detected BOM from the wrappedInputStreamobject.- Version:
- 1.0
- Author:
- Gregory Pakosz
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUnicodeBOMInputStream.BOMType safe enumeration class that describes the different types of Unicode BOMs.
-
Constructor Summary
Constructors Constructor Description UnicodeBOMInputStream(InputStream inputStream)Constructs a newUnicodeBOMInputStreamthat wraps the specifiedInputStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()UnicodeBOMInputStream.BOMgetBOM()Returns theBOMthat was detected in the wrappedInputStreamobject.UnicodeBOMInputStream.BOMgetUtf16Bom(byte[] bomRawBytes)Retrieves the UTF-16BOMfrom the specifiedbytearray.UnicodeBOMInputStream.BOMgetUtf32Bom(byte[] bomRawBytes)Retrieves the UTF-32BOMfrom the specifiedbytearray.UnicodeBOMInputStream.BOMgetUtf8Bom(byte[] bomRawBytes)Retrieves the UTF-8BOMfrom the specifiedbytearray.voidmark(int readlimit)booleanmarkSupported()intread()intread(byte[] b)intread(byte[] b, int off, int len)voidreset()longskip(long n)UnicodeBOMInputStreamskipBOM()Skips theBOMthat was found in the wrappedInputStreamobject.-
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Constructor Detail
-
UnicodeBOMInputStream
public UnicodeBOMInputStream(InputStream inputStream) throws IOException
Constructs a newUnicodeBOMInputStreamthat wraps the specifiedInputStream.- Parameters:
inputStream- anInputStream.- Throws:
IOException- on reading from the specifiedInputStreamwhen trying to detect the Unicode BOM.
-
-
Method Detail
-
getUtf32Bom
public final UnicodeBOMInputStream.BOM getUtf32Bom(byte[] bomRawBytes)
Retrieves the UTF-32BOMfrom the specifiedbytearray.- Parameters:
bomRawBytes- the bytes to read- Returns:
- an
BOM(if any) present in the specified array
-
getUtf8Bom
public final UnicodeBOMInputStream.BOM getUtf8Bom(byte[] bomRawBytes)
Retrieves the UTF-8BOMfrom the specifiedbytearray.- Parameters:
bomRawBytes- the bytes to read- Returns:
- an
BOM(if any) present in the specified array
-
getUtf16Bom
public final UnicodeBOMInputStream.BOM getUtf16Bom(byte[] bomRawBytes)
Retrieves the UTF-16BOMfrom the specifiedbytearray.- Parameters:
bomRawBytes- the bytes to read- Returns:
- an
BOM(if any) present in the specified array
-
getBOM
public final UnicodeBOMInputStream.BOM getBOM()
Returns theBOMthat was detected in the wrappedInputStreamobject.- Returns:
- a
BOMvalue.
-
skipBOM
public final UnicodeBOMInputStream skipBOM() throws IOException
Skips theBOMthat was found in the wrappedInputStreamobject.- Returns:
- this
UnicodeBOMInputStream. - Throws:
IOException- when trying to skip the BOM from the wrappedInputStreamobject.
-
read
public int read() throws IOException- Specified by:
readin classInputStream- Throws:
IOException
-
read
public int read(byte[] b) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
skip
public long skip(long n) throws IOException- Overrides:
skipin classInputStream- Throws:
IOException
-
available
public int available() throws IOException- Overrides:
availablein classInputStream- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
mark
public void mark(int readlimit)
- Overrides:
markin classInputStream
-
reset
public void reset() throws IOException- Overrides:
resetin classInputStream- Throws:
IOException
-
markSupported
public boolean markSupported()
- Overrides:
markSupportedin classInputStream
-
-