Package net.authorize.util
Class BOMStripperInputStream
- java.lang.Object
-
- java.io.InputStream
-
- net.authorize.util.BOMStripperInputStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class BOMStripperInputStream 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 10646The 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
http://stackoverflow.com/questions/1835430/byte-order-mark-screws-up-file-reading-in-java/1835529#1835529skipBOM()method to remove the detected BOM from the wrappedInputStreamobject.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBOMStripperInputStream.BOMType safe enumeration class that describes the different types of Unicode BOMs.
-
Constructor Summary
Constructors Constructor Description BOMStripperInputStream(InputStream inputStream)Constructs a newUnicodeBOMInputStreamthat wraps the specifiedInputStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()BOMStripperInputStream.BOMgetBOM()Returns theBOMthat was detected in the wrappedInputStreamobject.voidmark(int readlimit)booleanmarkSupported()intread()intread(byte[] b)intread(byte[] b, int off, int len)voidreset()longskip(long n)BOMStripperInputStreamskipBOM()Skips theBOMthat was found in the wrappedInputStreamobject.-
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Constructor Detail
-
BOMStripperInputStream
public BOMStripperInputStream(InputStream inputStream) throws NullPointerException, IOException
Constructs a newUnicodeBOMInputStreamthat wraps the specifiedInputStream.- Parameters:
inputStream- anInputStream.- Throws:
NullPointerException- wheninputStreamisnull.IOException- on reading from the specifiedInputStreamwhen trying to detect the Unicode BOM.
-
-
Method Detail
-
getBOM
public final BOMStripperInputStream.BOM getBOM()
Returns theBOMthat was detected in the wrappedInputStreamobject.- Returns:
- a
BOMvalue.
-
skipBOM
public final BOMStripperInputStream 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, NullPointerException- Overrides:
readin classInputStream- Throws:
IOExceptionNullPointerException
-
read
public int read(byte[] b, int off, int len) throws IOException, NullPointerException- Overrides:
readin classInputStream- Throws:
IOExceptionNullPointerException
-
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
-
-