net.sf.mmm.util.xml.base
Class XmlInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by net.sf.mmm.util.xml.base.XmlInputStream
All Implemented Interfaces:
Closeable

final class XmlInputStream
extends InputStream

This class is an input-stream that detects the encoding from the potential XML-header of a stream.

Since:
1.0.2
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Field Summary
private  byte[] buffer
          The buffer read to lookahead the encoding from the XML header.
private  Charset charset
          The encoding detected from the XML header or null if it was NOT specified.
private  InputStream delegate
          The original input-stream to adapt.
private  int index
          The current index position in the buffer.
private  int length
          the length of the buffered data (may be less than the array length).
private static byte[] XML_ENCODING_ATRIBUTE
          the start of the XML encoding attribute ("encoding=").
private static byte[] XML_HEADER_START
          the start of the XML header ("
 
Constructor Summary
XmlInputStream(InputStream delegate, Charset defaultCharset)
          The constructor.
 
Method Summary
 void close()
          
 Charset getCharset()
          This method gets the Charset that was detected.
 int read()
          
 int read(byte[] b, int off, int len)
          
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML_HEADER_START

private static final byte[] XML_HEADER_START
the start of the XML header (").


XML_ENCODING_ATRIBUTE

private static final byte[] XML_ENCODING_ATRIBUTE
the start of the XML encoding attribute ("encoding=").


delegate

private final InputStream delegate
The original input-stream to adapt.


buffer

private final byte[] buffer
The buffer read to lookahead the encoding from the XML header.


length

private final int length
the length of the buffered data (may be less than the array length).


index

private int index
The current index position in the buffer.


charset

private Charset charset
The encoding detected from the XML header or null if it was NOT specified.

Constructor Detail

XmlInputStream

public XmlInputStream(InputStream delegate,
                      Charset defaultCharset)
               throws IOException
The constructor.

Parameters:
delegate - is the input-stream to adapt.
defaultCharset - is the Charset used if NO encoding was specified via an XML header.
Throws:
IOException - if an I/O error was caused by delegate when trying to read the XML header.
Method Detail

getCharset

public Charset getCharset()
This method gets the Charset that was detected.

Returns:
the charset.

read

public int read()
         throws IOException

Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException

Overrides:
read in class InputStream
Throws:
IOException

close

public void close()
           throws IOException

Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException


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