net.sf.mmm.util.io.base
Class EncodingUtilImpl.UtfDetectionReader

java.lang.Object
  extended by java.io.Reader
      extended by net.sf.mmm.util.io.api.EncodingDetectionReader
          extended by net.sf.mmm.util.io.base.EncodingUtilImpl.UtfDetectionReader
All Implemented Interfaces:
Closeable, Readable
Enclosing class:
EncodingUtilImpl

protected class EncodingUtilImpl.UtfDetectionReader
extends EncodingDetectionReader

See Also:
EncodingUtilImpl.createUtfDetectionReader(InputStream, String)

Field Summary
private  int asciiBytesAvailable
          The number of ASCII bytes available to read from inputStream.
private  EncodingUtilImpl.AsciiProcessor asciiProcessor
          The processor for ASCII-mode.
private static int BUFFER_SIZE
          The used buffer size.
private  ProcessableByteArrayBuffer detectionBuffer
          The lookahead buffer used to detect encoding.
private  EncodingUtilImpl.UtfDetectionProcessor detectionProcessor
          The processor to detect encoding by lookahead.
private  String encoding
           
private  boolean eos
          true if end of stream is reached.
private  BufferInputStream inputStream
          The input-stream to read.
private  Reader reader
          The Reader to delegate to.
private static int REQUIRED_LOOKAHEAD
          The required lookahead size.
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
EncodingUtilImpl.UtfDetectionReader(InputStream inputStream, String nonUtfEncoding)
          The constructor.
 
Method Summary
 void close()
          
 String getEncoding()
          This method gets the encoding if already detected.
 int read(char[] buffer, int offset, int length)
          
 
Methods inherited from class java.io.Reader
mark, markSupported, read, read, read, ready, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REQUIRED_LOOKAHEAD

private static final int REQUIRED_LOOKAHEAD
The required lookahead size.

See Also:
Constant Field Values

BUFFER_SIZE

private static final int BUFFER_SIZE
The used buffer size.

See Also:
Constant Field Values

inputStream

private final BufferInputStream inputStream
The input-stream to read.


asciiProcessor

private final EncodingUtilImpl.AsciiProcessor asciiProcessor
The processor for ASCII-mode.


detectionProcessor

private final EncodingUtilImpl.UtfDetectionProcessor detectionProcessor
The processor to detect encoding by lookahead.


detectionBuffer

private final ProcessableByteArrayBuffer detectionBuffer
The lookahead buffer used to detect encoding.


encoding

private String encoding
See Also:
getEncoding()

reader

private Reader reader
The Reader to delegate to. Will be null until the first non ASCII-Character is detected.


asciiBytesAvailable

private int asciiBytesAvailable
The number of ASCII bytes available to read from inputStream.


eos

private boolean eos
true if end of stream is reached.

Constructor Detail

EncodingUtilImpl.UtfDetectionReader

public EncodingUtilImpl.UtfDetectionReader(InputStream inputStream,
                                           String nonUtfEncoding)
The constructor.

Parameters:
inputStream - is the InputStream to read.
nonUtfEncoding - is the encoding to use as fallback if non-ASCII characters are detected that are NOT encoded in UTF.
Method Detail

getEncoding

public String getEncoding()
This method gets the encoding if already detected. The detection may last until the end of this Reader has been reached.

Specified by:
getEncoding in class EncodingDetectionReader
Returns:
the encoding or null if NOT yet detected (then typically ASCII is assumed so far).

close

public void close()
           throws IOException

Specified by:
close in interface Closeable
Specified by:
close in class Reader
Throws:
IOException

read

public int read(char[] buffer,
                int offset,
                int length)
         throws IOException

Specified by:
read in class Reader
Throws:
IOException


Copyright © 2001-2010 mmm-Team. All Rights Reserved.