? BOMInputStream

????????:
Closeable, AutoCloseable

public class BOMInputStream extends ProxyInputStream
This class is used to wrap a stream that includes an encoded ByteOrderMark as its first bytes.

This class detects these bytes and, if required, can automatically skip them and return the subsequent byte as the first byte in the stream.

The ByteOrderMark implementation has the following pre-defined BOMs:

Example 1 - Detect and exclude a UTF-8 BOM

 BOMInputStream bomIn = new BOMInputStream(in);
 if (bomIn.hasBOM()) {
     // has a UTF-8 BOM
 }
 

Example 2 - Detect a UTF-8 BOM (but don't exclude it)

 boolean include = true;
 BOMInputStream bomIn = new BOMInputStream(in, include);
 if (bomIn.hasBOM()) {
     // has a UTF-8 BOM
 }
 

Example 3 - Detect Multiple BOMs

 BOMInputStream bomIn = new BOMInputStream(in,
   ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE,
   ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE
   );
 if (bomIn.hasBOM() == false) {
     // No BOM found
 } else if (bomIn.hasBOM(ByteOrderMark.UTF_16LE)) {
     // has a UTF-16LE BOM
 } else if (bomIn.hasBOM(ByteOrderMark.UTF_16BE)) {
     // has a UTF-16BE BOM
 } else if (bomIn.hasBOM(ByteOrderMark.UTF_32LE)) {
     // has a UTF-32LE BOM
 } else if (bomIn.hasBOM(ByteOrderMark.UTF_32BE)) {
     // has a UTF-32BE BOM
 }
 
???????:
2.0
????:
  • ???????

    • BOMInputStream

      public BOMInputStream(InputStream delegate)
      Constructs a new BOM InputStream that excludes a ByteOrderMark.UTF_8 BOM.
      ??:
      delegate - the InputStream to delegate to
    • BOMInputStream

      public BOMInputStream(InputStream delegate, boolean include)
      Constructs a new BOM InputStream that detects a a ByteOrderMark.UTF_8 and optionally includes it.
      ??:
      delegate - the InputStream to delegate to
      include - true to include the UTF-8 BOM or false to exclude it
    • BOMInputStream

      public BOMInputStream(InputStream delegate, ByteOrderMark... boms)
      Constructs a new BOM InputStream that excludes the specified BOMs.
      ??:
      delegate - the InputStream to delegate to
      boms - The BOMs to detect and exclude
    • BOMInputStream

      public BOMInputStream(InputStream delegate, boolean include, ByteOrderMark... boms)
      Constructs a new BOM InputStream that detects the specified BOMs and optionally includes them.
      ??:
      delegate - the InputStream to delegate to
      include - true to include the specified BOMs or false to exclude them
      boms - The BOMs to detect and optionally exclude
  • ??????

    • hasBOM

      public boolean hasBOM() throws IOException
      Indicates whether the stream contains one of the specified BOMs.
      ??:
      true if the stream has one of the specified BOMs, otherwise false if it does not
      ??:
      IOException - if an error reading the first bytes of the stream occurs
    • hasBOM

      public boolean hasBOM(ByteOrderMark bom) throws IOException
      Indicates whether the stream contains the specified BOM.
      ??:
      bom - The BOM to check for
      ??:
      true if the stream has the specified BOM, otherwise false if it does not
      ??:
      IllegalArgumentException - if the BOM is not one the stream is configured to detect
      IOException - if an error reading the first bytes of the stream occurs
    • getBOM

      public ByteOrderMark getBOM() throws IOException
      Return the BOM (Byte Order Mark).
      ??:
      The BOM or null if none
      ??:
      IOException - if an error reading the first bytes of the stream occurs
    • getBOMCharsetName

      Return the BOM charset Name - ByteOrderMark.getCharsetName().
      ??:
      The BOM charset Name or null if no BOM found
      ??:
      IOException - if an error reading the first bytes of the stream occurs
    • read

      public int read() throws IOException
      Invokes the delegate's read() method, detecting and optionally skipping BOM.
      ??:
      read ??? ProxyInputStream
      ??:
      the byte read (excluding BOM) or -1 if the end of stream
      ??:
      IOException - if an I/O error occurs
    • read

      public int read(byte[] buf, int off, int len) throws IOException
      Invokes the delegate's read(byte[], int, int) method, detecting and optionally skipping BOM.
      ??:
      read ??? ProxyInputStream
      ??:
      buf - the buffer to read the bytes into
      off - The start offset
      len - The number of bytes to read (excluding BOM)
      ??:
      the number of bytes read or -1 if the end of stream
      ??:
      IOException - if an I/O error occurs
    • read

      public int read(byte[] buf) throws IOException
      Invokes the delegate's read(byte[]) method, detecting and optionally skipping BOM.
      ??:
      read ??? ProxyInputStream
      ??:
      buf - the buffer to read the bytes into
      ??:
      the number of bytes read (excluding BOM) or -1 if the end of stream
      ??:
      IOException - if an I/O error occurs
    • mark

      public void mark(int readlimit)
      Invokes the delegate's mark(int) method.
      ??:
      mark ??? ProxyInputStream
      ??:
      readlimit - read ahead limit
    • reset

      public void reset() throws IOException
      Invokes the delegate's reset() method.
      ??:
      reset ??? ProxyInputStream
      ??:
      IOException - if an I/O error occurs
    • skip

      public long skip(long n) throws IOException
      Invokes the delegate's skip(long) method, detecting and optionally skipping BOM.
      ??:
      skip ??? ProxyInputStream
      ??:
      n - the number of bytes to skip
      ??:
      the number of bytes to skipped or -1 if the end of stream
      ??:
      IOException - if an I/O error occurs