net.sf.okapi.common

## Class BOMAwareInputStream

- java.lang.Object
- - java.io.InputStream
  - - net.sf.okapi.common.BOMAwareInputStream

- All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

      public class BOMAwareInputStream
      extends java.io.InputStream

  Helper class to detect and skip BOM in InputStream, including for UTF-8.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BOMAwareInputStream(java.io.InputStream input, java.lang.String defaultEncoding)` Creates a new BOMAwareInputStream object for a given InputStream and a given default encoding.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `autoDtected()` Indicates if the guessed encoding was auto-detected.
    `java.lang.String` | `detectEncoding()` Tries to detect the presence of a Byte-Order-Mark.
    `int` | `getBOMSize()` Gets the number of bytes used by the Byte-Order-mark in this document.
    `java.lang.String` | `getDetectedEncoding()` Gets the encoding that was guessed.
    `boolean` | `hasUTF8BOM()` Indicates if the guessed encoding is UTF-8 and this file has a BOM.
    `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`

- - ### Constructor Detail

    - #### BOMAwareInputStream

          public BOMAwareInputStream(java.io.InputStream input,
                             java.lang.String defaultEncoding)

      Creates a new BOMAwareInputStream object for a given InputStream and a given default encoding.
      Parameters:
        `input` - The input stream to use.
        `defaultEncoding` - The default encoding to use if none can be auto-detected.

  - ### Method Detail

    - #### detectEncoding

          public java.lang.String detectEncoding()
                                          throws java.io.IOException

      Tries to detect the presence of a Byte-Order-Mark.
      Returns:
        The encoding guessed after the try. If nothing has been found, the default encoding is returned.
      Throws:
        `java.io.IOException`

    - #### getDetectedEncoding

          public java.lang.String getDetectedEncoding()

      Gets the encoding that was guessed. It can be the default encoding.
      Returns:
        the guessed encoding.

    - #### autoDtected

          public boolean autoDtected()

      Indicates if the guessed encoding was auto-detected. If not it is the default encoding that was provided.
      Returns:
        True if the guessed encoding was auto-detected, false if not.

    - #### getBOMSize

          public int getBOMSize()

      Gets the number of bytes used by the Byte-Order-mark in this document.
      Returns:
        The byte size of the BOM in this document.

    - #### hasUTF8BOM

          public boolean hasUTF8BOM()

      Indicates if the guessed encoding is UTF-8 and this file has a BOM.
      Returns:
        True if the guessed encoding is UTF-8 and this file has a BOM, false otherwise.

    - #### read

          public int read()
                   throws java.io.IOException

      Specified by:
        `read` in class `java.io.InputStream`
      Throws:
        `java.io.IOException`