Class Encoding

java.lang.Object
chemaxon.marvin.io.Encoding
All Implemented Interfaces:
Externalizable, Serializable

@PublicApi public final class Encoding extends Object implements Externalizable
File encoding information.
Since:
Marvin 5.0, 11/10/2007
See Also:
  • Field Details

    • DEFAULT

      public static final Encoding DEFAULT
      The system's default encoding.
  • Constructor Details

    • Encoding

      public Encoding(String name, int wordLength, ByteOrder order)
      Creates an Encoding for the specified name, word length and byte order.
      Parameters:
      name - the encoding name
      wordLength - the word length
      order - the byte order
  • Method Details

    • forName

      public static Encoding forName(String name)
      Creates an Encoding for the specified name, with #UNKNOWN endianness.
      Parameters:
      name - the encoding name or null
      Returns:
      the encoding or null
      Throws:
      IllegalCharsetNameException - if the encoding is illegal
      UnsupportedCharsetException - if the encoding is unsupported
    • recognize

      public static Encoding recognize(byte[] buf, int off, int len)
      Tries to recognize the encoding of a byte array.
      Parameters:
      buf - the byte array
      off - array offset
      len - length
      Returns:
      the encoding of null if not recognized
      Since:
      Marvin 5.1.3, 10/20/2008
    • recognizeByBOM

      public static Encoding recognizeByBOM(byte[] buf, int off, int len)
      Tries to recognize the encoding of a byte array by the byte order mark.
      Parameters:
      buf - the byte array
      off - array offset
      len - length
      Returns:
      the encoding of null if not recognized
      Since:
      Marvin 5.1.3, 10/18/2008
    • name

      public String name()
      Gets the name of the encoding.
      Returns:
      the name
    • wordLength

      public int wordLength()
      Gets the word length in bytes.
      Returns:
      the word length
    • order

      public ByteOrder order()
      Gets the endianness.
      Returns:
      the byte order
    • convert

      public String convert(byte[] buf, int offset, int numbytes) throws UnsupportedEncodingException
      Converts a byte array to a string.
      Parameters:
      buf - the byte array
      offset - offset in the array
      numbytes - number of bytes to convert
      Throws:
      UnsupportedEncodingException
      Since:
      Marvin 5.1.3, 10/18/2008
    • toString

      public String toString()
      Converts the encoding object to string.
      Overrides:
      toString in class Object
      Returns:
      the encoding name
    • equals

      public boolean equals(Encoding o)
      Tests whether two encodings are equal.
      Returns:
      true if the name, the word length and the byte order are the same
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Tests whether two encodings are equal.
      Overrides:
      equals in class Object
      Returns:
      true if the name, the word length and the byte order are the same
    • canonicalName

      public static String canonicalName(String enc)
      Standardize a Java encoding.
      Parameters:
      enc - the encoding name or null
      Returns:
      the standard encoding name or null
      Throws:
      IllegalCharsetNameException - if the encoding is illegal
      UnsupportedCharsetException - if the encoding is unsupported
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Saves object state.
      Specified by:
      writeExternal in interface Externalizable
      Parameters:
      out - the stream to write the object to
      Throws:
      IOException - Includes any I/O exceptions that may occur
    • readExternal

      public void readExternal(ObjectInput in) throws IOException
      Restores object state. For internal use only!
      Specified by:
      readExternal in interface Externalizable
      Parameters:
      in - the stream to read data from in order to restore the object
      Throws:
      IOException - if I/O errors occur
    • read

      public static Encoding read(ObjectInput in) throws IOException
      Reads an externalized encoding object.
      Parameters:
      in - the stream to read data from in order to restore the object
      Returns:
      the encoding object
      Throws:
      IOException - if I/O errors occur