Class BomInput
- java.lang.Object
-
- java.io.InputStream
-
- com.univocity.parsers.common.input.BomInput
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public final class BomInput extends java.io.InputStreamA wrapper for anInputStreamthat attempts to detect a Byte Order Mark (BOM) in the input and derive the character encoding that should be used to decode the incoming content.- Author:
- Univocity Software Pty Ltd - dev@univocity.com
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBomInput.BytesProcessedNotificationInternal notification exception used to re-wrap the originalInputStreaminto aReader.
-
Field Summary
Fields Modifier and Type Field Description static byte[]UTF_16BE_BOMstatic byte[]UTF_16LE_BOMstatic byte[]UTF_32BE_BOMstatic byte[]UTF_32LE_BOMstatic byte[]UTF_8_BOM
-
Constructor Summary
Constructors Constructor Description BomInput(java.io.InputStream input)Wraps anInputStreamand reads the first bytes found on it to attempt to read a BOM.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()java.nio.charset.CharsetgetCharset()Returns the detectedCharsetdetermined by the Byte Order Mark (BOM) available in the input provided in the constructor of this class.java.lang.StringgetEncoding()Returns the detected encoding name determined by the Byte Order Mark (BOM) available in the input provided in the constructor of this class.booleanhasBytesStored()Returns a flag indicating whether or not all bytes read from the wrapped input stream have been consumed.intread()
-
-
-
Method Detail
-
read
public final int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
hasBytesStored
public final boolean hasBytesStored()
Returns a flag indicating whether or not all bytes read from the wrapped input stream have been consumed. This allows client code to determine if the original input stream can be used directly and safely, or if thisBomInputwrapper class should be used instead. If there are stored bytes that need to be consumed before the wrapped input stream is consumed again, this method will returntrue.- Returns:
falseif there are no bytes stored and the original input stream can be used directly. If this wrapper needs to be used to return stored bytes before, thentruewill be returned.
-
getCharset
public final java.nio.charset.Charset getCharset()
Returns the detectedCharsetdetermined by the Byte Order Mark (BOM) available in the input provided in the constructor of this class. If no BOM was detected, this method will returnnull.- Returns:
- the detected
Charsetornullif a BOM could not be matched.
-
getEncoding
public final java.lang.String getEncoding()
Returns the detected encoding name determined by the Byte Order Mark (BOM) available in the input provided in the constructor of this class. If no BOM was detected, this method will returnnull.- Returns:
- the detected encoding name or
nullif a BOM could not be matched.
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.InputStream- Throws:
java.io.IOException
-
-