public class UnicodeReader
extends java.io.Reader
For optimum performance, it is recommended that you wrap all instances of
UnicodeReader
with a java.io.BufferedReader
.
This class is mostly ripped off from the workaround in the description of Java Bug 4508058.
Constructor and Description |
---|
UnicodeReader(java.io.File file)
This utility constructor is here because you will usually use a
UnicodeReader on files. |
UnicodeReader(java.io.File file,
java.lang.String defaultEncoding)
This utility constructor is here because you will usually use a
UnicodeReader on files. |
UnicodeReader(java.io.InputStream in)
Creates a reader using the encoding specified by the BOM in the file;
if there is no recognized BOM, then a system default encoding is used.
|
UnicodeReader(java.io.InputStream in,
java.lang.String defaultEncoding)
Creates a reader using the encoding specified by the BOM in the file;
if there is no recognized BOM, then
defaultEncoding is
used. |
UnicodeReader(java.lang.String file)
This utility constructor is here because you will usually use a
UnicodeReader on files. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this reader.
|
java.lang.String |
getEncoding()
Returns the encoding being used to read this input stream (i.e., the
encoding of the file).
|
protected void |
init(java.io.InputStream in,
java.lang.String defaultEncoding)
Read-ahead four bytes and check for BOM marks.
|
int |
read(char[] cbuf,
int off,
int len)
Read characters into a portion of an array.
|
public UnicodeReader(java.lang.String file) throws java.io.IOException, java.io.FileNotFoundException, java.lang.SecurityException
UnicodeReader
on files.Creates a reader using the encoding specified by the BOM in the file; if there is no recognized BOM, then a system default encoding is used.
file
- The file from which you want to read.java.io.IOException
- If an error occurs when checking for/reading the
BOM.java.io.FileNotFoundException
- If the file does not exist, is a
directory, or cannot be opened for reading.java.lang.SecurityException
- If a security manager exists and its
checkRead method denies read access to the file.public UnicodeReader(java.io.File file) throws java.io.IOException, java.io.FileNotFoundException, java.lang.SecurityException
UnicodeReader
on files.Creates a reader using the encoding specified by the BOM in the file; if there is no recognized BOM, then a system default encoding is used.
file
- The file from which you want to read.java.io.IOException
- If an error occurs when checking for/reading the
BOM.java.io.FileNotFoundException
- If the file does not exist, is a
directory, or cannot be opened for reading.java.lang.SecurityException
- If a security manager exists and its
checkRead method denies read access to the file.public UnicodeReader(java.io.File file, java.lang.String defaultEncoding) throws java.io.IOException, java.io.FileNotFoundException, java.lang.SecurityException
UnicodeReader
on files.Creates a reader using the encoding specified by the BOM in the file; if there is no recognized BOM, then a specified default encoding is used.
file
- The file from which you want to read.defaultEncoding
- The encoding to use if no BOM is found. If
this value is null
, a system default is used.java.io.IOException
- If an error occurs when checking for/reading the
BOM.java.io.FileNotFoundException
- If the file does not exist, is a
directory, or cannot be opened for reading.java.lang.SecurityException
- If a security manager exists and its
checkRead method denies read access to the file.public UnicodeReader(java.io.InputStream in) throws java.io.IOException
in
- The input stream from which to read.java.io.IOException
- If an error occurs when checking for/reading the
BOM.public UnicodeReader(java.io.InputStream in, java.lang.String defaultEncoding) throws java.io.IOException
defaultEncoding
is
used.in
- The input stream from which to read.defaultEncoding
- The encoding to use if no recognized BOM is
found. If this value is null
, a system default
is used.java.io.IOException
- If an error occurs when checking for/reading the
BOM.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.Reader
java.io.IOException
public java.lang.String getEncoding()
protected void init(java.io.InputStream in, java.lang.String defaultEncoding) throws java.io.IOException
defaultEncoding
- The encoding to use if no BOM was recognized. If
this value is null
, then a system default is used.java.io.IOException
- If an error occurs when trying to read a BOM.public int read(char[] cbuf, int off, int len) throws java.io.IOException
read
in class java.io.Reader
cbuf
- The buffer into which to read.off
- The offset at which to start storing characters.len
- The maximum number of characters to read.-1
if the end
of the stream has been reached.java.io.IOException