Enum SignatureCharset

  • All Implemented Interfaces:
    Serializable, Comparable<SignatureCharset>

    public enum SignatureCharset
    extends Enum<SignatureCharset>
    A byte stream signature (Signature) coupled with a charset (UnicodeCharset) that may follow the signature (aka a signature/charset pair). Observe that, in the absence of a signature (Signature.NONE), many different charsets are allowed. Instances of this class enforce signature removal upon decoding and insertion upon charset; there is no attempt made to identify matching signatures, as done by Serialization.
    Since:
    0.6.0
    Version:
    $Id: SignatureCharset.java 16154 2012-07-14 16:34:05Z colin $
    Author:
    tlerios@marketcetera.com
    • Constructor Detail

      • SignatureCharset

        private SignatureCharset​(Signature signature,
                                 UnicodeCharset charset)
        Creates a new signature/charset pair with the given signature and charset.
        Parameters:
        signature - The signature.
        charset - The charset.
    • Method Detail

      • values

        public static SignatureCharset[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (SignatureCharset c : SignatureCharset.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static SignatureCharset 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
      • getSignature

        public Signature getSignature()
        Returns the receiver's signature.
        Returns:
        The signature.
      • getCharset

        public UnicodeCharset getCharset()
        Returns the receiver's charset.
        Returns:
        The charset.
      • isSupported

        public boolean isSupported()
        Checks whether the JVM supports the receiver's charset.
        Returns:
        True if so.
      • assertSupported

        public void assertSupported()
                             throws I18NException
        Asserts that the JVM supports the receiver's charset.
        Throws:
        I18NException - Thrown if it does not.
      • decode

        public String decode​(byte[] data)
                      throws I18NException
        Decodes the given byte array using the receiver's charset, and returns the result. The receiver's signature BOM is assumed to be present in the header of the byte array, and is removed (without a check performed to confirm its presence).
        Parameters:
        data - The byte array, which may be null.
        Returns:
        The decoded string; it is null if the given byte array is null.
        Throws:
        I18NException - Thrown if the receiver's charset is not a supported JVM charset.
      • encode

        public byte[] encode​(String data)
                      throws I18NException
        Encodes the given string using the receiver's charset, and returns the result. The receiver's signature BOM is always prepended to the header of the returned byte array.
        Parameters:
        data - The string, which may be null.
        Returns:
        The encoded byte array; it is null if the given string is null.
        Throws:
        I18NException - Thrown if the receiver's charset is not a supported JVM charset.