Top Description Inners Fields Constructors Methods
com.univocity.parsers.common.input

public final Class BomInput

extends InputStream
Class Inheritance
Imports
java.io.*, java.nio.charset.*

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 - [email protected]

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
BomInput.BytesProcessedNotification

Internal notification exception used to re-wrap the original InputStream into a Reader.

Field Summary

Modifier and TypeField and Description
private int[]
private int
private int
private String
private IOException
private final InputStream
public static final byte[]
public static final byte[]
public static final byte[]
public static final byte[]
public static final byte[]

Constructor Summary

AccessConstructor and Description
public
BomInput(InputStream
the input whose first bytes should be analyzed.
input
)

Wraps an InputStream and reads the first bytes found on it to attempt to read a BOM.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.
public final Charset

Returns:

the detected Charset or null if a BOM could not be matched.
getCharset
()

Returns the detected Charset determined by the Byte Order Mark (BOM) available in the input provided in the constructor of this class.

public final String

Returns:

the detected encoding name or null if a BOM could not be matched.
getEncoding
()

Returns the detected encoding name determined by the Byte Order Mark (BOM) available in the input provided in the constructor of this class.

public final boolean

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.
hasBytesStored
()

Returns a flag indicating whether or not all bytes read from the wrapped input stream have been consumed.

private int
next()

public final int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.
private void
setEncoding(String encoding)

Inherited from java.io.InputStream:
availablemarkmarkSupportednullInputStreamreadreadreadAllBytesreadNBytesreadNBytesresetskipskipNBytestransferTo

Field Detail

bytesback to summary
private int[] bytes
bytesReadback to summary
private int bytesRead
consumedback to summary
private int consumed
encodingback to summary
private String encoding
exceptionback to summary
private IOException exception
inputback to summary
private final InputStream input
UTF_16BE_BOMback to summary
public static final byte[] UTF_16BE_BOM
UTF_16LE_BOMback to summary
public static final byte[] UTF_16LE_BOM
UTF_32BE_BOMback to summary
public static final byte[] UTF_32BE_BOM
UTF_32LE_BOMback to summary
public static final byte[] UTF_32LE_BOM
UTF_8_BOMback to summary
public static final byte[] UTF_8_BOM

Constructor Detail

BomInputback to summary
public BomInput(InputStream input)

Wraps an InputStream and reads the first bytes found on it to attempt to read a BOM.

Parameters
input:InputStream

the input whose first bytes should be analyzed.

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.InputStream.close.

Closes this input stream and releases any system resources associated with the stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
getCharsetback to summary
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:Charset

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

getEncodingback to summary
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:String

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

hasBytesStoredback to summary
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:boolean

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.

nextback to summary
private int next() throws IOException
readback to summary
public final int read() throws IOException

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
setEncodingback to summary
private void setEncoding(String encoding)
com.univocity.parsers.common.input back to summary

public final Class BomInput.BytesProcessedNotification

extends RuntimeException
Class Inheritance

Internal notification exception used to re-wrap the original InputStream into a Reader. This is required for performance reasons as overriding InputStream#read() incurs a heavy performance penalty when the implementation is native (as in FileInputStream#read().

Field Summary

Modifier and TypeField and Description
public final String
public final InputStream

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Throwable
fillInStackTrace()

Overrides java.lang.Throwable.fillInStackTrace.

Fills in the execution stack trace.

Field Detail

encodingback to summary
public final String encoding
inputback to summary
public final InputStream input

Constructor Detail

BytesProcessedNotificationback to summary
public BytesProcessedNotification(InputStream input, String encoding)

Method Detail

fillInStackTraceback to summary
public Throwable fillInStackTrace()

Overrides java.lang.Throwable.fillInStackTrace.

Doc from java.lang.Throwable.fillInStackTrace.

Fills in the execution stack trace. This method records within this Throwable object information about the current state of the stack frames for the current thread.

If the stack trace of this Throwable is not writable, calling this method has no effect.

Returns:Throwable

a reference to this Throwable instance.

Annotations
@Override