org.marketcetera.util.unicode
Class UnicodeInputStreamReader

java.lang.Object
  extended by java.io.Reader
      extended by org.marketcetera.util.unicode.UnicodeInputStreamReader
All Implemented Interfaces:
Closeable, Readable
Direct Known Subclasses:
UnicodeFileReader

public class UnicodeInputStreamReader
extends Reader

A variation of InputStreamReader that is BOM-aware. It can operate in any of the following modes:

Since:
0.6.0
Version:
$Id: UnicodeInputStreamReader.java 16154 2012-07-14 16:34:05Z colin $
Author:
tlerios@marketcetera.com

Field Summary
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
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
 void close()
           
 DecodingStrategy getDecodingStrategy()
          Returns the receiver's decoding strategy.
 SignatureCharset getRequestedSignatureCharset()
          Returns the receiver's requested signature/charset.
 SignatureCharset getSignatureCharset()
          Returns the receiver's actual signature/charset (that is, the one in use to decode the stream).
 void mark(int readAheadLimit)
           
 boolean markSupported()
           
 int read()
           
 int read(char[] cbuf)
           
 int read(char[] cbuf, int off, int len)
           
 int read(CharBuffer target)
           
 boolean ready()
           
 long skip(long n)
           
 
Methods inherited from class java.io.Reader
reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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:
read in interface Readable
Overrides:
read in class Reader
Throws:
IOException

read

public int read()
         throws IOException
Overrides:
read in class Reader
Throws:
IOException

read

public int read(char[] cbuf)
         throws IOException
Overrides:
read in class Reader
Throws:
IOException

read

public int read(char[] cbuf,
                int off,
                int len)
         throws IOException
Specified by:
read in class Reader
Throws:
IOException

skip

public long skip(long n)
          throws IOException
Overrides:
skip in class Reader
Throws:
IOException

ready

public boolean ready()
              throws IOException
Overrides:
ready in class Reader
Throws:
IOException

markSupported

public boolean markSupported()
Overrides:
markSupported in class Reader

mark

public void mark(int readAheadLimit)
          throws IOException
Overrides:
mark in class Reader
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in class Reader
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.


Copyright © 2012. All Rights Reserved.