public final class BomInput
extends java.io.InputStream
InputStream
that attempts to detect a Byte Order Mark (BOM) in the input
and derive the character encoding that should be used to decode the incoming content.Modifier and Type | Class and Description |
---|---|
static class |
BomInput.BytesProcessedNotification
Internal notification exception used to re-wrap the original
InputStream into a Reader . |
Modifier and Type | Field and Description |
---|---|
private int[] |
bytes |
private int |
bytesRead |
private int |
consumed |
private java.lang.String |
encoding |
private java.io.IOException |
exception |
private java.io.InputStream |
input |
static byte[] |
UTF_16BE_BOM |
static byte[] |
UTF_16LE_BOM |
static byte[] |
UTF_32BE_BOM |
static byte[] |
UTF_32LE_BOM |
static byte[] |
UTF_8_BOM |
Constructor and Description |
---|
BomInput(java.io.InputStream input)
Wraps an
InputStream and reads the first bytes found on it to attempt to read a BOM. |
Modifier and Type | Method and Description |
---|---|
java.nio.charset.Charset |
getCharset()
Returns the detected
Charset determined by the Byte Order Mark (BOM) available in the
input provided in the constructor of this class. |
java.lang.String |
getEncoding()
Returns the detected encoding name determined by the Byte Order Mark (BOM) available in the
input provided in the constructor of this class.
|
boolean |
hasBytesStored()
Returns a flag indicating whether or not all bytes read from the wrapped input stream have been consumed.
|
private int |
next() |
int |
read() |
private void |
setEncoding(java.lang.String encoding) |
public static final byte[] UTF_8_BOM
public static final byte[] UTF_16BE_BOM
public static final byte[] UTF_16LE_BOM
public static final byte[] UTF_32BE_BOM
public static final byte[] UTF_32LE_BOM
private int bytesRead
private int[] bytes
private java.lang.String encoding
private int consumed
private final java.io.InputStream input
private java.io.IOException exception
public BomInput(java.io.InputStream input)
InputStream
and reads the first bytes found on it to attempt to read a BOM.input
- the input whose first bytes should be analyzed.private void setEncoding(java.lang.String encoding)
private int next() throws java.io.IOException
java.io.IOException
public final int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public final boolean hasBytesStored()
BomInput
wrapper class should be used instead.
If there are stored bytes that need to be consumed before the wrapped input stream is consumed again,
this method will return true
.false
if there are no bytes stored and the original input stream can be used directly. If this wrapper
needs to be used to return stored bytes before, then true
will be returned.public final java.nio.charset.Charset getCharset()
Charset
determined by the Byte Order Mark (BOM) available in the
input provided in the constructor of this class.
If no BOM was detected, this method will return null
.Charset
or null
if a BOM could not be matched.public final java.lang.String getEncoding()
null
.null
if a BOM could not be matched.