Class CharsetEncoding

  • All Implemented Interfaces:
    Serializable

    public class CharsetEncoding
    extends Object
    implements Serializable
    Describes the encoding format of character data. This encompasses not only the character set used, but also the error handling for unencodable characters. The default settings are:
    • The ISO-8859-1 character set is used.
    • Encoding errors are resolved by replacement with the '?' character.
    See Also:
    Charset, CodingErrorAction, Serialized Form
    • Constructor Detail

      • CharsetEncoding

        public CharsetEncoding()
        Creates a container with default settings.
      • CharsetEncoding

        public CharsetEncoding​(String charsetName)
        Creates a container initialized the named character set and the default error policy.
        Parameters:
        charsetName - name of the charset. This must be a name which is recognized by Charset.forName(String).
      • CharsetEncoding

        public CharsetEncoding​(String charsetName,
                               CodingErrorAction errorAction)
        Creates a container initialized with the named character set, using the specified error policy. If a policy of replacement is selected, the default replacement string will be used.
        Parameters:
        charsetName - name of the charset. This must be a name which is recognized by Charset.forName(String).
        errorAction - specifies how encoding errors are to be handled
      • CharsetEncoding

        public CharsetEncoding​(String charsetName,
                               String replacement)
        Creates a container initialized with the named character set, using a replacement error policy with the specified string.
        Parameters:
        charsetName - name of the charset. This must be a name which is recognized by Charset.forName(String).
        replacement - replacement string to be used when handling encoding errors
      • CharsetEncoding

        public CharsetEncoding​(CharsetEncoding source)
        Creates a container initialized using the given character set specification.
        Parameters:
        source - character set data from which to initialize the settings
    • Method Detail

      • set

        public void set​(CharsetEncoding source)
        Copy the settings from the given character set specification
        Parameters:
        source - specifier containing the desired settings
      • getCharset

        public Charset getCharset()
        Gets the character set.
        Returns:
        the character set to use
      • setCharset

        public void setCharset​(Charset charset)
        Sets the character set.
        Parameters:
        charset - the character set to use
      • getCharsetName

        public String getCharsetName()
        Gets the character set name.
        Returns:
        the character set to use
      • setCharsetName

        public void setCharsetName​(String charsetName)
        Sets the character set name.
        Parameters:
        charsetName - name of the charset
        Throws:
        UnsupportedCharsetException - if the named charset is not supported.
      • getErrorAction

        public CodingErrorAction getErrorAction()
        Gets the specified action for an encoding error.
        Returns:
        error action
      • setErrorAction

        public void setErrorAction​(CodingErrorAction errorAction)
        Sets the action for an encoding error.
        Parameters:
        errorAction - error action
      • getReplacement

        public String getReplacement()
        Gets the replacement value used when an error occurs. This value is only used if the error action is set to replacement.
        Returns:
        replacement value used for encoding errors
      • setReplacement

        public void setReplacement​(String replacement)
        Sets the error policy to be replacement with the specified string.
        Parameters:
        replacement - replacement value to use for encoding errors
        Throws:
        IllegalArgumentException - if the replacement is null or empty
      • newEncoder

        public CharsetEncoder newEncoder()
        Gets a new encoder configured for the described encoding.
        Returns:
        a encoder matching the encoding configuration
      • newDecoder

        public CharsetDecoder newDecoder()
        Gets a new decoder configured for the described encoding.
        Returns:
        a decoder matching the encoding configuration