com.mucommander.io.bom
Class BOMInputStream
java.lang.Object
java.io.InputStream
com.mucommander.io.bom.BOMInputStream
- All Implemented Interfaces:
- BOMConstants, java.io.Closeable
public class BOMInputStream
- extends java.io.InputStream
- implements BOMConstants
BOMInputStream is an InputStream which provides support for Byte-Order Marks (BOM).
A BOM is a byte sequence found at the beginning of a Unicode text stream which indicates the encoding of the text
that follows.
This class serves a dual purpose:
1) it allows to detect a BOM in the underlying stream and determine the encoding used by the stream:
the BOM instance returned by getBOM() provides that information.
2) it allows to discard the BOM from a Unicode stream: the leading bytes corresponding to the BOM are swallowed by
the stream and never returned by the read methods.
The following BOMs are supported by this class:
Note that UTF-32 encodings (both Little and Big Endians) are usually not supported by Java runtimes
out of the box.
- Author:
- Maxence Bernard
- See Also:
BOMReader
|
Constructor Summary |
BOMInputStream(java.io.InputStream in)
Creates a new BOMInputStream and looks for a BOM at the beginning of the stream. |
|
Method Summary |
void |
close()
|
BOM |
getBOM()
Returns the BOM that was found at the beginning of the stream if there was one,
null otherwise. |
int |
read()
|
int |
read(byte[] b)
|
int |
read(byte[] b,
int off,
int len)
|
| Methods inherited from class java.io.InputStream |
available, mark, markSupported, reset, skip |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
BOMInputStream
public BOMInputStream(java.io.InputStream in)
throws java.io.IOException
- Creates a new
BOMInputStream and looks for a BOM at the beginning of the stream.
- Parameters:
in - the underlying stream
- Throws:
java.io.IOException - if an error occurred while reading the given InputStream
getBOM
public BOM getBOM()
- Returns the
BOM that was found at the beginning of the stream if there was one,
null otherwise.
- Returns:
- the BOM that was found at the beginning of the stream
read
public int read()
throws java.io.IOException
- Specified by:
read in class java.io.InputStream
- Throws:
java.io.IOException
read
public int read(byte[] b)
throws java.io.IOException
- Overrides:
read in class java.io.InputStream
- Throws:
java.io.IOException
read
public int read(byte[] b,
int off,
int len)
throws java.io.IOException
- Overrides:
read in class java.io.InputStream
- Throws:
java.io.IOException
close
public void close()
throws java.io.IOException
- Specified by:
close in interface java.io.Closeable- Overrides:
close in class java.io.InputStream
- Throws:
java.io.IOException
This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard