Class BomInput
java.lang.Object
java.io.InputStream
com.univocity.parsers.common.input.BomInput
- All Implemented Interfaces:
Closeable, AutoCloseable
A wrapper for an
InputStream that 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 ClassesModifier and TypeClassDescriptionstatic final classInternal notification exception used to re-wrap the originalInputStreaminto aReader. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byte[]static final byte[]static final byte[]static final byte[]static final byte[] -
Constructor Summary
ConstructorsConstructorDescriptionBomInput(InputStream input) Wraps anInputStreamand reads the first bytes found on it to attempt to read a BOM. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()final CharsetReturns the detectedCharsetdetermined by the Byte Order Mark (BOM) available in the input provided in the constructor of this class.final StringReturns the detected encoding name determined by the Byte Order Mark (BOM) available in the input provided in the constructor of this class.final booleanReturns a flag indicating whether or not all bytes read from the wrapped input stream have been consumed.final intread()Methods inherited from class InputStream
available, mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Field Details
-
UTF_8_BOM
public static final byte[] UTF_8_BOM -
UTF_16BE_BOM
public static final byte[] UTF_16BE_BOM -
UTF_16LE_BOM
public static final byte[] UTF_16LE_BOM -
UTF_32BE_BOM
public static final byte[] UTF_32BE_BOM -
UTF_32LE_BOM
public static final byte[] UTF_32LE_BOM
-
-
Constructor Details
-
BomInput
Wraps anInputStreamand reads the first bytes found on it to attempt to read a BOM.- Parameters:
input- the input whose first bytes should be analyzed.
-
-
Method Details
-
read
- Specified by:
readin classInputStream- Throws:
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
-
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
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-