Package org.mozilla.universalchardet
Class UnicodeBOMInputStream
java.lang.Object
java.io.InputStream
org.mozilla.universalchardet.UnicodeBOMInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
The
UnicodeBOMInputStream
class wraps any
InputStream
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 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
wrapped InputStream
object.
- Version:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Type safe enumeration class that describes the different types of Unicode BOMs. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final UnicodeBOMInputStream.BOM
private final PushbackInputStream
private boolean
-
Constructor Summary
ConstructorsConstructorDescriptionUnicodeBOMInputStream
(InputStream inputStream) Constructs a newUnicodeBOMInputStream
that wraps the specifiedInputStream
.UnicodeBOMInputStream
(InputStream inputStream, boolean skipIfFound) Constructs a newUnicodeBOMInputStream
that wraps the specifiedInputStream
. -
Method Summary
Modifier and TypeMethodDescriptionint
void
close()
getBOM()
Returns theBOM
that was detected in the wrappedInputStream
object.void
mark
(int readlimit) boolean
int
read()
int
read
(byte[] b) int
read
(byte[] b, int off, int len) void
reset()
long
skip
(long n) final UnicodeBOMInputStream
skipBOM()
Skips theBOM
that was found in the wrappedInputStream
object.Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
in
-
bom
-
skipped
private boolean skipped
-
-
Constructor Details
-
UnicodeBOMInputStream
Constructs a newUnicodeBOMInputStream
that wraps the specifiedInputStream
. By default skip BOM bytes- Parameters:
inputStream
- anInputStream
.- Throws:
NullPointerException
- wheninputStream
isnull
.IOException
- on reading from the specifiedInputStream
when trying to detect the Unicode BOM.
-
UnicodeBOMInputStream
Constructs a newUnicodeBOMInputStream
that wraps the specifiedInputStream
.- Parameters:
inputStream
- anInputStream
.skipIfFound
- to automatically skip BOM bytes if found- Throws:
NullPointerException
- wheninputStream
isnull
.IOException
- on reading from the specifiedInputStream
when trying to detect the Unicode BOM.
-
-
Method Details
-
getBOM
Returns theBOM
that was detected in the wrappedInputStream
object.- Returns:
- a
BOM
value.
-
skipBOM
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
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
available
- Overrides:
available
in classInputStream
- Throws:
IOException
-
close
- 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
- Overrides:
reset
in classInputStream
- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classInputStream
-