Package com.globalmentor.io
Class BOMInputStreamReader
- java.lang.Object
-
- java.io.Reader
-
- java.io.InputStreamReader
-
- com.globalmentor.io.BOMInputStreamReader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Readable
public class BOMInputStreamReader extends java.io.InputStreamReader
A reader that attempts to auto-detect the charset of an input stream from the beginning byte order mark (BOM).The input stream must be at its beginning and must support marking and resetting.
By default the reader will be configured to report coding errors, although constructors are provided to override this. Note that
InputStreamReader
by default chooses to replace malformed input and unmappable characters rather than report them.- Author:
- Garret Wilson
- See Also:
ByteOrderMark
,CodingErrorAction.REPORT
-
-
Constructor Summary
Constructors Constructor Description BOMInputStreamReader(java.io.InputStream inputStream)
Constructs an input stream reader that uses UTF-8 as the default charset if the charset cannot be determined by the BOM.BOMInputStreamReader(java.io.InputStream inputStream, java.nio.charset.Charset defaultCharset)
Constructs an input stream reader that uses the given named charset as a default if the charset cannot be determined by the BOM.BOMInputStreamReader(java.io.InputStream inputStream, java.nio.charset.Charset defaultCharset, java.nio.charset.CodingErrorAction codingErrorAction)
Constructs an input stream reader that uses the given named charset as a default if the charset cannot be determined by the BOM.BOMInputStreamReader(java.io.InputStream inputStream, java.nio.charset.CodingErrorAction codingErrorAction)
Constructs an input stream reader that uses UTF-8 as the default charset if the charset cannot be determined by the BOM.
-
-
-
Constructor Detail
-
BOMInputStreamReader
public BOMInputStreamReader(java.io.InputStream inputStream) throws java.io.IOException, java.io.UnsupportedEncodingException
Constructs an input stream reader that uses UTF-8 as the default charset if the charset cannot be determined by the BOM.The reader will be configured to report coding errors.
- Parameters:
inputStream
- An input stream; must be at its beginning and must support marking and resetting.- Throws:
java.io.IOException
- if there is an error attempting to read the byte order mark from the input stream.java.io.UnsupportedEncodingException
- if the named charset is not supported.- See Also:
CodingErrorAction.REPORT
-
BOMInputStreamReader
public BOMInputStreamReader(java.io.InputStream inputStream, java.nio.charset.Charset defaultCharset) throws java.io.IOException, java.io.UnsupportedEncodingException
Constructs an input stream reader that uses the given named charset as a default if the charset cannot be determined by the BOM.The reader will be configured to report coding errors.
- Parameters:
inputStream
- An input stream; must be at its beginning and must support marking and resetting.defaultCharset
- The default charset to use if one cannot be determined by the BOM.- Throws:
java.io.IOException
- if there is an error attempting to read the byte order mark from the input stream.java.io.UnsupportedEncodingException
- if the named charset is not supported.- See Also:
CodingErrorAction.REPORT
-
BOMInputStreamReader
public BOMInputStreamReader(java.io.InputStream inputStream, @Nonnull java.nio.charset.CodingErrorAction codingErrorAction) throws java.io.IOException, java.io.UnsupportedEncodingException
Constructs an input stream reader that uses UTF-8 as the default charset if the charset cannot be determined by the BOM.- Parameters:
inputStream
- An input stream; must be at its beginning and must support marking and resetting.codingErrorAction
- The action to take if the data being decoded is invalid.- Throws:
java.io.IOException
- if there is an error attempting to read the byte order mark from the input stream.java.io.UnsupportedEncodingException
- if the named charset is not supported.
-
BOMInputStreamReader
public BOMInputStreamReader(java.io.InputStream inputStream, java.nio.charset.Charset defaultCharset, @Nonnull java.nio.charset.CodingErrorAction codingErrorAction) throws java.io.IOException, java.io.UnsupportedEncodingException
Constructs an input stream reader that uses the given named charset as a default if the charset cannot be determined by the BOM.- Parameters:
inputStream
- An input stream; must be at its beginning and must support marking and resetting.defaultCharset
- The default charset to use if one cannot be determined by the BOM.codingErrorAction
- The action to take if the data being decoded is invalid.- Throws:
java.io.IOException
- if there is an error attempting to read the byte order mark from the input stream.java.io.UnsupportedEncodingException
- if the named charset is not supported.
-
-