|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.InputStream
java.io.FilterInputStream
org.apache.commons.io.input.ProxyInputStream
org.apache.commons.io.input.BOMInputStream
public class BOMInputStream
This class is used to wrap a stream that includes an encoded
ByteOrderMark as its first bytes.
This class detects these bytes and, if required, can automatically skip them
and return the subsequent byte as the first byte in the stream.
The ByteOrderMark implementation has the following pre-defined BOMs:
ByteOrderMark.UTF_8ByteOrderMark.UTF_16LEByteOrderMark.UTF_16BE
BOMInputStream bomIn = new BOMInputStream(in);
if (bomIn.hasBOM()) {
// has a UTF-8 BOM
}
boolean include = true;
BOMInputStream bomIn = new BOMInputStream(in, include);
if (bomIn.hasBOM()) {
// has a UTF-8 BOM
}
BOMInputStream bomIn = new BOMInputStream(in, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE);
if (bomIn.hasBOM() == false) {
// No BOM found
} else if (bomIn.hasBOM(ByteOrderMark.UTF_16LE)) {
// has a UTF-16LE BOM
} else if (bomIn.hasBOM(ByteOrderMark.UTF_16BE)) {
// has a UTF-16BE BOM
}
ByteOrderMark,
Wikipedia - Byte Order Mark| Field Summary |
|---|
| Fields inherited from class java.io.FilterInputStream |
|---|
in |
| Constructor Summary | |
|---|---|
BOMInputStream(InputStream delegate)
Constructs a new BOM InputStream that excludes a ByteOrderMark.UTF_8 BOM. |
|
BOMInputStream(InputStream delegate,
boolean include)
Constructs a new BOM InputStream that detects a a ByteOrderMark.UTF_8 and optionally includes it. |
|
BOMInputStream(InputStream delegate,
boolean include,
ByteOrderMark... boms)
Constructs a new BOM InputStream that detects the specified BOMs and optionally includes them. |
|
BOMInputStream(InputStream delegate,
ByteOrderMark... boms)
Constructs a new BOM InputStream that excludes the specified BOMs. |
|
| Method Summary | |
|---|---|
ByteOrderMark |
getBOM()
Return the BOM (Byte Order Mark). |
String |
getBOMCharsetName()
Return the BOM charset Name - ByteOrderMark.getCharsetName(). |
boolean |
hasBOM()
Indicates whether the stream contains one of the specified BOMs. |
boolean |
hasBOM(ByteOrderMark bom)
Indicates whether the stream contains the specified BOM. |
void |
mark(int readlimit)
Invokes the delegate's mark(int) method. |
int |
read()
Invokes the delegate's read() method, detecting and
optionally skipping BOM. |
int |
read(byte[] buf)
Invokes the delegate's read(byte[]) method, detecting and
optionally skipping BOM. |
int |
read(byte[] buf,
int off,
int len)
Invokes the delegate's read(byte[], int, int) method, detecting
and optionally skipping BOM. |
void |
reset()
Invokes the delegate's reset() method. |
long |
skip(long n)
Invokes the delegate's skip(long) method, detecting
and optionallyskipping BOM. |
| Methods inherited from class org.apache.commons.io.input.ProxyInputStream |
|---|
afterRead, available, beforeRead, close, handleIOException, markSupported |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BOMInputStream(InputStream delegate)
ByteOrderMark.UTF_8 BOM.
delegate - the InputStream to delegate to
public BOMInputStream(InputStream delegate,
boolean include)
ByteOrderMark.UTF_8 and optionally includes it.
delegate - the InputStream to delegate toinclude - true to include the UTF-8 BOM or
false to exclude it
public BOMInputStream(InputStream delegate,
ByteOrderMark... boms)
delegate - the InputStream to delegate toboms - The BOMs to detect and exclude
public BOMInputStream(InputStream delegate,
boolean include,
ByteOrderMark... boms)
delegate - the InputStream to delegate toinclude - true to include the specified BOMs or
false to exclude themboms - The BOMs to detect and optionally exclude| Method Detail |
|---|
public boolean hasBOM()
throws IOException
IOException - if an error reading the first bytes of the stream occurs
public boolean hasBOM(ByteOrderMark bom)
throws IOException
bom - The BOM to check for
IllegalArgumentException - if the BOM is not one the stream
is configured to detect
IOException - if an error reading the first bytes of the stream occurs
public ByteOrderMark getBOM()
throws IOException
IOException - if an error reading the first bytes of the stream occurs
public String getBOMCharsetName()
throws IOException
ByteOrderMark.getCharsetName().
IOException - if an error reading the first bytes of the stream occurs
public int read()
throws IOException
read() method, detecting and
optionally skipping BOM.
read in class ProxyInputStreamIOException - if an I/O error occurs
public int read(byte[] buf,
int off,
int len)
throws IOException
read(byte[], int, int) method, detecting
and optionally skipping BOM.
read in class ProxyInputStreambuf - the buffer to read the bytes intooff - The start offsetlen - The number of bytes to read (excluding BOM)
IOException - if an I/O error occurs
public int read(byte[] buf)
throws IOException
read(byte[]) method, detecting and
optionally skipping BOM.
read in class ProxyInputStreambuf - the buffer to read the bytes into
IOException - if an I/O error occurspublic void mark(int readlimit)
mark(int) method.
mark in class ProxyInputStreamreadlimit - read ahead limit
public void reset()
throws IOException
reset() method.
reset in class ProxyInputStreamIOException - if an I/O error occurs
public long skip(long n)
throws IOException
skip(long) method, detecting
and optionallyskipping BOM.
skip in class ProxyInputStreamn - the number of bytes to skip
IOException - if an I/O error occurs
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||