Package org.marketcetera.util.unicode
Class UnicodeInputStreamReader
- java.lang.Object
-
- java.io.Reader
-
- org.marketcetera.util.unicode.UnicodeInputStreamReader
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Readable
- Direct Known Subclasses:
UnicodeFileReader
public class UnicodeInputStreamReader extends Reader
A variation ofInputStreamReaderthat is BOM-aware. It can operate in any of the following modes:- As a standard input stream reader that uses the default JVM charset.
- A reader that uses a specific charset and assumes a specific signature is present in the input stream (and skips it without confirming that it's actually present and valid).
- A reader that looks for a signature match among several candidates, and thus automatically determines the charset.
- Since:
- 0.6.0
- Version:
- $Id: UnicodeInputStreamReader.java 16154 2012-07-14 16:34:05Z colin $
- Author:
- tlerios@marketcetera.com
-
-
Field Summary
Fields Modifier and Type Field Description private DecodingStrategymDecodingStrategyprivate InputStreamReadermReaderprivate SignatureCharsetmRequestedSignatureCharsetprivate SignatureCharsetmSignatureCharsetprivate PushbackInputStreammStream
-
Constructor Summary
Constructors Constructor Description UnicodeInputStreamReader(InputStream stream)Creates a new reader over the given stream that uses the default JVM charset.UnicodeInputStreamReader(InputStream stream, DecodingStrategy decodingStrategy)Creates a new reader over the given stream that normally uses the charset associated with a matching signature among those of the given decoding strategy.UnicodeInputStreamReader(InputStream stream, SignatureCharset requestedSignatureCharset)Creates a new reader over the given stream that normally assumes the given signature is present and its associated charset should be used.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()DecodingStrategygetDecodingStrategy()Returns the receiver's decoding strategy.SignatureCharsetgetRequestedSignatureCharset()Returns the receiver's requested signature/charset.SignatureCharsetgetSignatureCharset()Returns the receiver's actual signature/charset (that is, the one in use to decode the stream).private voidinit()Initializes the receiver.voidmark(int readAheadLimit)booleanmarkSupported()intread()intread(char[] cbuf)intread(char[] cbuf, int off, int len)intread(CharBuffer target)booleanready()longskip(long n)-
Methods inherited from class java.io.Reader
nullReader, reset, transferTo
-
-
-
-
Field Detail
-
mStream
private PushbackInputStream mStream
-
mReader
private InputStreamReader mReader
-
mDecodingStrategy
private DecodingStrategy mDecodingStrategy
-
mRequestedSignatureCharset
private SignatureCharset mRequestedSignatureCharset
-
mSignatureCharset
private SignatureCharset mSignatureCharset
-
-
Constructor Detail
-
UnicodeInputStreamReader
public UnicodeInputStreamReader(InputStream stream)
Creates a new reader over the given stream that uses the default JVM charset.- Parameters:
stream- The stream.
-
UnicodeInputStreamReader
public UnicodeInputStreamReader(InputStream stream, SignatureCharset requestedSignatureCharset)
Creates a new reader over the given stream that normally assumes the given signature is present and its associated charset should be used. However, if the charset in the given signature/charset pair is not supported by the JVM, the default JVM charset is used instead.- Parameters:
stream- The stream.requestedSignatureCharset- The signature/charset. It may be null to use the default JVM charset.
-
UnicodeInputStreamReader
public UnicodeInputStreamReader(InputStream stream, DecodingStrategy decodingStrategy)
Creates a new reader over the given stream that normally uses the charset associated with a matching signature among those of the given decoding strategy. However, if no signature matches, or if the charset of the matching signature is not supported by the JVM, the default JVM charset is used instead.- Parameters:
stream- The stream.decodingStrategy- The decoding strategy. It may be null to use the default JVM charset.
-
-
Method Detail
-
read
public int read(CharBuffer target) throws IOException
- Specified by:
readin interfaceReadable- Overrides:
readin classReader- Throws:
IOException
-
read
public int read() throws IOException- Overrides:
readin classReader- Throws:
IOException
-
read
public int read(char[] cbuf) throws IOException- Overrides:
readin classReader- Throws:
IOException
-
read
public int read(char[] cbuf, int off, int len) throws IOException- Specified by:
readin classReader- Throws:
IOException
-
skip
public long skip(long n) throws IOException- Overrides:
skipin classReader- Throws:
IOException
-
ready
public boolean ready() throws IOException- Overrides:
readyin classReader- Throws:
IOException
-
markSupported
public boolean markSupported()
- Overrides:
markSupportedin classReader
-
mark
public void mark(int readAheadLimit) throws IOException- Overrides:
markin classReader- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classReader- Throws:
IOException
-
getDecodingStrategy
public DecodingStrategy getDecodingStrategy()
Returns the receiver's decoding strategy.- Returns:
- The strategy, which may be null if none was specified.
-
getRequestedSignatureCharset
public SignatureCharset getRequestedSignatureCharset()
Returns the receiver's requested signature/charset.- Returns:
- The requested signature/charset, which may be null if none was requested.
-
getSignatureCharset
public SignatureCharset getSignatureCharset() throws IOException
Returns the receiver's actual signature/charset (that is, the one in use to decode the stream).- Returns:
- The signature/charset, which may be null if the default JVM charset is used.
- Throws:
IOException- Thrown if an I/O error occurs.
-
init
private void init() throws IOExceptionInitializes the receiver.- Throws:
IOException- Thrown if an I/O error occurs.
-
-