com.univocity.parsers.common.input
Class BomInput

java.lang.Object
  extended by java.io.InputStream
      extended by com.univocity.parsers.common.input.BomInput
All Implemented Interfaces:
Closeable

public final class BomInput
extends InputStream

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
static class BomInput.BytesProcessedNotification
          Internal notification exception used to re-wrap the original InputStream into a Reader.
 
Field Summary
static byte[] UTF_16BE_BOM
           
static byte[] UTF_16LE_BOM
           
static byte[] UTF_32BE_BOM
           
static byte[] UTF_32LE_BOM
           
static byte[] UTF_8_BOM
           
 
Constructor Summary
BomInput(InputStream input)
          Wraps an InputStream and reads the first bytes found on it to attempt to read a BOM.
 
Method Summary
 Charset getCharset()
          Returns the detected Charset determined by the Byte Order Mark (BOM) available in the input provided in the constructor of this class.
 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.
 boolean hasBytesStored()
          Returns a flag indicating whether or not all bytes read from the wrapped input stream have been consumed.
 int read()
           
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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 Detail

BomInput

public BomInput(InputStream input)
Wraps an InputStream and reads the first bytes found on it to attempt to read a BOM.

Parameters:
input - the input whose first bytes should be analyzed.
Method Detail

read

public final int read()
               throws IOException
Specified by:
read in class InputStream
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 this BomInput wrapper 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 return true.

Returns:
false if 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, then true will be returned.

getCharset

public final Charset getCharset()
Returns the detected Charset 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 return null.

Returns:
the detected Charset or null if a BOM could not be matched.

getEncoding

public final 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 return null.

Returns:
the detected encoding name or null if a BOM could not be matched.


Copyright © 2018 uniVocity Software Pty Ltd. All rights reserved.