CharsetMapping
Date: 2018-05-06

com.mysql.jdbc

## Class CharsetMapping

- java.lang.Object
- - com.mysql.jdbc.CharsetMapping

-     public class CharsetMapping
      extends java.lang.Object

  Mapping between MySQL charset names and Java charset names. I've investigated placing these in a .properties file, but unfortunately under most appservers this complicates configuration because the security policy needs to be changed by the user to allow the driver to read them :(

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.util.Map<java.lang.String,MysqlCharset>` | `CHARSET_NAME_TO_CHARSET`
    `static java.util.Map<java.lang.String,java.lang.Integer>` | `CHARSET_NAME_TO_COLLATION_INDEX`
    `static MysqlCharset[]` | `COLLATION_INDEX_TO_CHARSET`
    `static java.lang.String[]` | `COLLATION_INDEX_TO_COLLATION_NAME`
    `static int` | `MAP_SIZE`
    `static int` | `MYSQL_COLLATION_INDEX_binary`
    `static int` | `MYSQL_COLLATION_INDEX_utf8`
    `static java.util.Set<java.lang.Integer>` | `UTF8MB4_INDEXES`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CharsetMapping()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `(package private) static java.lang.String` | `getCharacterEncodingForErrorMessages(ConnectionImpl conn)` Returns the character encoding for error messages returned from the server.
    `static int` | `getCollationIndexForJavaEncoding(java.lang.String javaEncoding, java.sql.Connection conn)`
    `static java.lang.String` | `getJavaEncodingForCollationIndex(java.lang.Integer collationIndex)`
    `static java.lang.String` | `getJavaEncodingForCollationIndex(java.lang.Integer collationIndex, java.lang.String javaEncoding)`
    `static java.lang.String` | `getJavaEncodingForMysqlCharset(java.lang.String mysqlCharsetName)`
    `static java.lang.String` | `getJavaEncodingForMysqlCharset(java.lang.String mysqlCharsetName, java.lang.String javaEncoding)` MySQL charset could map to several Java encodings.
    `static int` | `getMblen(java.lang.String charsetName)`
    `static java.lang.String` | `getMysqlCharsetForJavaEncoding(java.lang.String javaEncoding, Connection conn)`
    `static java.lang.String` | `getMysqlCharsetNameForCollationIndex(java.lang.Integer collationIndex)`
    `(package private) static int` | `getNumberOfCharsetsConfigured()`
    `static boolean` | `isMultibyteCharset(java.lang.String javaEncodingName)` Character sets that we can't convert ourselves.
    `(package private) static boolean` | `requiresEscapeEasternUnicode(java.lang.String javaEncodingName)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### MAP_SIZE

          public static final int MAP_SIZE

      See Also:
        Constant Field Values

    - #### COLLATION_INDEX_TO_COLLATION_NAME

          public static final java.lang.String[] COLLATION_INDEX_TO_COLLATION_NAME

    - #### COLLATION_INDEX_TO_CHARSET

          public static final MysqlCharset[] COLLATION_INDEX_TO_CHARSET

    - #### CHARSET_NAME_TO_CHARSET

          public static final java.util.Map<java.lang.String,MysqlCharset> CHARSET_NAME_TO_CHARSET

    - #### CHARSET_NAME_TO_COLLATION_INDEX

          public static final java.util.Map<java.lang.String,java.lang.Integer> CHARSET_NAME_TO_COLLATION_INDEX

    - #### UTF8MB4_INDEXES

          public static final java.util.Set<java.lang.Integer> UTF8MB4_INDEXES

    - #### MYSQL_COLLATION_INDEX_utf8

          public static final int MYSQL_COLLATION_INDEX_utf8

      See Also:
        Constant Field Values

    - #### MYSQL_COLLATION_INDEX_binary

          public static final int MYSQL_COLLATION_INDEX_binary

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### CharsetMapping

          public CharsetMapping()

  - ### Method Detail

    - #### getMysqlCharsetForJavaEncoding

          public static final java.lang.String getMysqlCharsetForJavaEncoding(java.lang.String javaEncoding,
                                                        Connection conn)
                                                                       throws java.sql.SQLException

      Throws:
        `java.sql.SQLException`

    - #### getCollationIndexForJavaEncoding

          public static int getCollationIndexForJavaEncoding(java.lang.String javaEncoding,
                                             java.sql.Connection conn)
                                                      throws java.sql.SQLException

      Throws:
        `java.sql.SQLException`

    - #### getMysqlCharsetNameForCollationIndex

          public static java.lang.String getMysqlCharsetNameForCollationIndex(java.lang.Integer collationIndex)

    - #### getJavaEncodingForMysqlCharset

          public static java.lang.String getJavaEncodingForMysqlCharset(java.lang.String mysqlCharsetName,
                                                        java.lang.String javaEncoding)

      MySQL charset could map to several Java encodings. So here we choose the one according to next rules:
    - if there is no static mapping for this charset then return javaEncoding value as is because this could be a custom charset for example
    - if static mapping exists and javaEncoding equals to one of Java encoding canonical names or aliases available for this mapping then javaEncoding value as is; this is required when result should match to connection encoding, for example if connection encoding is Cp943 we must avoid getting SHIFT_JIS for sjis mysql charset
    - if static mapping exists and javaEncoding doesn't match any Java encoding canonical names or aliases available for this mapping then return default Java encoding (the first in mapping list)

Parameters:
  `mysqlCharsetName` -
  `javaEncoding` -

- #### getJavaEncodingForMysqlCharset

      public static java.lang.String getJavaEncodingForMysqlCharset(java.lang.String mysqlCharsetName)

- #### getJavaEncodingForCollationIndex

      public static java.lang.String getJavaEncodingForCollationIndex(java.lang.Integer collationIndex,
                                                      java.lang.String javaEncoding)

- #### getJavaEncodingForCollationIndex

      public static java.lang.String getJavaEncodingForCollationIndex(java.lang.Integer collationIndex)

- #### getNumberOfCharsetsConfigured

      static final int getNumberOfCharsetsConfigured()

- #### getCharacterEncodingForErrorMessages

      static final java.lang.String getCharacterEncodingForErrorMessages(ConnectionImpl conn)
                                                                  throws java.sql.SQLException

  Returns the character encoding for error messages returned from the server. Doesn't return useful values other than Cp1252 until the driver has gone through initialization phase and determined server configuration, as not enough information is available to make an intelligent decision until then.
  Parameters:
    `conn` - the connection to the MySQL server
  Returns:
    the Java encoding name that error messages use
  Throws:
    `java.sql.SQLException` - if determination of the character encoding fails

- #### requiresEscapeEasternUnicode

      static final boolean requiresEscapeEasternUnicode(java.lang.String javaEncodingName)

- #### isMultibyteCharset

      public static final boolean isMultibyteCharset(java.lang.String javaEncodingName)

  Character sets that we can't convert ourselves.
  Parameters:
    `javaEncodingName` -

- #### getMblen

      public static int getMblen(java.lang.String charsetName)