Package org.ec4j.core

Enum Resource.Bom

java.lang.Object
java.lang.Enum<Resource.Bom>
org.ec4j.core.Resource.Bom
All Implemented Interfaces:
Serializable, Comparable<Resource.Bom>, java.lang.constant.Constable
Enclosing interface:
Resource

public static enum Resource.Bom extends Enum<Resource.Bom>
An enum of Byte Order Marks (BOMs) to be able to support encodings with BOM unsupported by Charset.forName(String).
Since:
0.0.4
  • Enum Constant Details

    • UTF_8_BOM

      public static final Resource.Bom UTF_8_BOM
      utf-8-bom
      Since:
      0.0.4
  • Field Details

    • bomBytes

      private final byte[] bomBytes
    • charset

      private final Charset charset
    • name

      private final String name
  • Constructor Details

    • Bom

      private Bom(String name, byte[] bytes, Charset delegate)
  • Method Details

    • values

      public static Resource.Bom[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static Resource.Bom valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • ofName

      public static Resource.Bom ofName(String name)
      Returns a Resource.Bom having the given name.
      Parameters:
      name - name of the encoding
      Returns:
      a Resource.Bom or null if the name is unknown
      Since:
      0.0.4
    • skipBom

      public static String skipBom(byte[] bytes, Charset charset)
      If the given charset is a Resource.Bom.BomCharset, skips the BOM sequence in the given bytes array and returns a new String built out the remaining part of bytes; otherwise returns a new String built out the bytes.
      Parameters:
      bytes - the byte array to process
      charset - the encoding of the bytes
      Returns:
      a new String
      Since:
      0.0.4
    • skipBom

      public static InputStream skipBom(InputStream inputStream, Charset charset) throws IOException
      If the given charset is a Resource.Bom.BomCharset, skips the BOM sequence in the given inputStream and returns the given inputStream; otherwise just returns the given inputStream.
      Parameters:
      inputStream - InputStream to process
      charset - the encoding of the in
      Returns:
      in
      Throws:
      IOException - if there are i/o issues
      Since:
      0.0.4
    • writeBom

      public static OutputStream writeBom(OutputStream outpuStream, Charset charset) throws IOException
      If the given charset is a Resource.Bom.BomCharset, writes the BOM sequence into the given outpuStream and returns the given outpuStream; otherwise just returns the given outpuStream.
      Parameters:
      outpuStream - the OutputStream to write to
      charset - the Charset of the given outputStream
      Returns:
      outpuStream
      Throws:
      IOException - if there are i/o issues
      Since:
      0.0.4
    • bomBytesHumanReadable

      public String bomBytesHumanReadable()
      Returns:
      a comma and space separated HEX formatted BOM bytes
      Since:
      0.0.4
    • getBomBytes

      public byte[] getBomBytes()
      Returns:
      a copy of bomBytes
      Since:
      0.0.4
    • getCharset

      public Charset getCharset()
      Returns:
      the Resource.Bom.BomCharset associated with this Resource.Bom
      Since:
      0.0.4
    • getName

      public String getName()
      Returns:
      the name of the encoding
      Since:
      0.0.4