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
TheUnicodeBOMInputStream
class wraps anyInputStream
and 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 wrappedInputStream
object.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BOMStripperInputStream.BOM
Type safe enumeration class that describes the different types of Unicode BOMs.
-
Constructor Summary
Constructors Constructor Description BOMStripperInputStream(InputStream inputStream)
Constructs a newUnicodeBOMInputStream
that wraps the specifiedInputStream
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
BOMStripperInputStream.BOM
getBOM()
Returns theBOM
that was detected in the wrappedInputStream
object.void
mark(int readlimit)
boolean
markSupported()
int
read()
int
read(byte[] b)
int
read(byte[] b, int off, int len)
void
reset()
long
skip(long n)
BOMStripperInputStream
skipBOM()
Skips theBOM
that was found in the wrappedInputStream
object.-
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Constructor Detail
-
BOMStripperInputStream
public BOMStripperInputStream(InputStream inputStream) throws NullPointerException, IOException
Constructs a newUnicodeBOMInputStream
that wraps the specifiedInputStream
.- Parameters:
inputStream
- anInputStream
.- Throws:
NullPointerException
- wheninputStream
isnull
.IOException
- on reading from the specifiedInputStream
when trying to detect the Unicode BOM.
-
-
Method Detail
-
getBOM
public final BOMStripperInputStream.BOM getBOM()
Returns theBOM
that was detected in the wrappedInputStream
object.- Returns:
- a
BOM
value.
-
skipBOM
public final BOMStripperInputStream skipBOM() throws IOException
Skips theBOM
that was found in the wrappedInputStream
object.- Returns:
- this
UnicodeBOMInputStream
. - Throws:
IOException
- when trying to skip the BOM from the wrappedInputStream
object.
-
read
public int read() throws IOException
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
public int read(byte[] b) throws IOException, NullPointerException
- Overrides:
read
in classInputStream
- Throws:
IOException
NullPointerException
-
read
public int read(byte[] b, int off, int len) throws IOException, NullPointerException
- Overrides:
read
in classInputStream
- Throws:
IOException
NullPointerException
-
skip
public long skip(long n) throws IOException
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
available
public int available() throws IOException
- Overrides:
available
in classInputStream
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
mark
public void mark(int readlimit)
- Overrides:
mark
in classInputStream
-
reset
public void reset() throws IOException
- Overrides:
reset
in classInputStream
- Throws:
IOException
-
markSupported
public boolean markSupported()
- Overrides:
markSupported
in classInputStream
-
-