public class UnicodeInputStream
extends java.io.InputStream
getEncodingFromStream()
on
the input stream reader.
This class is not thread safe! When more than one thread wants to use an instance of UnicodeInputStream,
the caller must provide synchronization.Modifier and Type | Class and Description |
---|---|
(package private) static class |
UnicodeInputStream.UnicodeBOM
Helper class to bundle encoding and BOM marker.
|
Modifier and Type | Field and Description |
---|---|
private byte[] |
buf
Buffer for BOM reading
|
private java.lang.String |
encoding
The stream encoding as read from the BOM or null.
|
private java.io.PushbackInputStream |
inputStream |
private static int |
MAX_BOM_SIZE
The maximum amount of bytes to read for a BOM
|
private int |
pos
Buffer pointer.
|
private boolean |
skipBOM
True if the BOM itself should be skipped and not read.
|
static UnicodeInputStream.UnicodeBOM |
UTF16BE_BOM
BOM Marker for UTF 16, big endian.
|
static UnicodeInputStream.UnicodeBOM |
UTF16LE_BOM
BOM Marker for UTF 16, little endian.
|
static UnicodeInputStream.UnicodeBOM |
UTF32BE_BOM
BOM Marker for UTF 32, big endian.
|
static UnicodeInputStream.UnicodeBOM |
UTF32LE_BOM
BOM Marker for UTF 32, little endian.
|
static UnicodeInputStream.UnicodeBOM |
UTF8_BOM
BOM Marker for UTF 8.
|
Constructor and Description |
---|
UnicodeInputStream(java.io.InputStream inputStream)
Creates a new UnicodeInputStream object.
|
UnicodeInputStream(java.io.InputStream inputStream,
boolean skipBOM)
Creates a new UnicodeInputStream object.
|
Modifier and Type | Method and Description |
---|---|
int |
available() |
void |
close() |
java.lang.String |
getEncodingFromStream()
Read encoding based on BOM.
|
boolean |
isSkipBOM()
Returns true if the input stream discards the BOM.
|
void |
mark(int readlimit) |
boolean |
markSupported() |
private UnicodeInputStream.UnicodeBOM |
match(UnicodeInputStream.UnicodeBOM matchEncoding,
UnicodeInputStream.UnicodeBOM noMatchEncoding) |
private void |
pushback(UnicodeInputStream.UnicodeBOM matchBOM) |
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
private boolean |
readByte() |
protected java.lang.String |
readEncoding()
This method gets the encoding from the stream contents if a BOM exists.
|
void |
reset() |
static boolean |
sameEncoding(java.lang.String left,
java.lang.String right)
Helper function to compare encodings
|
long |
skip(long n) |
public static final UnicodeInputStream.UnicodeBOM UTF8_BOM
public static final UnicodeInputStream.UnicodeBOM UTF16LE_BOM
public static final UnicodeInputStream.UnicodeBOM UTF16BE_BOM
public static final UnicodeInputStream.UnicodeBOM UTF32LE_BOM
public static final UnicodeInputStream.UnicodeBOM UTF32BE_BOM
private static final int MAX_BOM_SIZE
private byte[] buf
private int pos
private final java.lang.String encoding
private final boolean skipBOM
private final java.io.PushbackInputStream inputStream
public UnicodeInputStream(java.io.InputStream inputStream) throws java.lang.IllegalStateException, java.io.IOException
inputStream
- The input stream to use for reading.java.lang.IllegalStateException
java.io.IOException
public UnicodeInputStream(java.io.InputStream inputStream, boolean skipBOM) throws java.lang.IllegalStateException, java.io.IOException
inputStream
- The input stream to use for reading.skipBOM
- If this is set to true, a BOM read from the stream is discarded. This parameter should normally be true.java.lang.IllegalStateException
java.io.IOException
public boolean isSkipBOM()
public java.lang.String getEncodingFromStream()
java.lang.IllegalStateException
- When a problem reading the BOM occured.protected java.lang.String readEncoding() throws java.io.IOException
java.io.IOException
private UnicodeInputStream.UnicodeBOM match(UnicodeInputStream.UnicodeBOM matchEncoding, UnicodeInputStream.UnicodeBOM noMatchEncoding) throws java.io.IOException
java.io.IOException
private boolean readByte() throws java.io.IOException
java.io.IOException
private void pushback(UnicodeInputStream.UnicodeBOM matchBOM) throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
java.io.IOException
InputStream.close()
public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
InputStream.available()
public void mark(int readlimit)
mark
in class java.io.InputStream
readlimit
- InputStream.mark(int)
public boolean markSupported()
markSupported
in class java.io.InputStream
InputStream.markSupported()
public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
InputStream.read()
public int read(byte[] b) throws java.io.IOException
read
in class java.io.InputStream
b
- bufferjava.io.IOException
InputStream.read(byte[])
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.InputStream
b
- bufferoff
- offsetlen
- lengthjava.io.IOException
InputStream.read(byte[], int, int)
public void reset() throws java.io.IOException
reset
in class java.io.InputStream
java.io.IOException
InputStream.reset()
public long skip(long n) throws java.io.IOException
skip
in class java.io.InputStream
n
- java.io.IOException
InputStream.skip(long)
public static boolean sameEncoding(java.lang.String left, java.lang.String right)
left
- right
-