com.mysql.jdbc

## Class SingleByteCharsetConverter

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

    public class SingleByteCharsetConverter
    extends java.lang.Object

Converter for char[]->byte[] and byte[]->char[] for single-byte character sets. Much faster (5-6x) than the built-in solution that ships with the JVM, even with JDK-1.4.x and NewIo.

### Method Summary

Methods
`static SingleByteCharsetConverter` `getInstance(java.lang.String encodingName, Connection conn)` Get a converter for the given encoding name
`static SingleByteCharsetConverter` `initCharset(java.lang.String javaEncodingName)` Initialize the shared instance of a converter for the given character encoding.
`byte[]` `toBytes(char[] c)`
`byte[]` `toBytes(char[] chars, int offset, int length)`
`byte[]` `toBytes(java.lang.String s)` Convert the given string to an array of bytes.
`byte[]` `toBytes(java.lang.String s, int offset, int length)` Convert the given string to an array of bytes.
`byte[]` `toBytesWrapped(char[] c, char beginWrap, char endWrap)`
`byte[]` `toBytesWrapped(java.lang.String s, char beginWrap, char endWrap)`
`java.lang.String` `toString(byte[] buffer)` Convert the byte buffer to a string using this instance's character encoding.
`java.lang.String` `toString(byte[] buffer, int startPos, int length)` Convert the byte buffer from startPos to a length of length to a string using this instance's character encoding.
`static java.lang.String` `toStringDefaultEncoding(byte[] buffer, int startPos, int length)` Convert the byte buffer from startPos to a length of length to a string using the default platform encoding.

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

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

### Method Detail

#### getInstance

    public static SingleByteCharsetConverter getInstance(java.lang.String encodingName,
                                         Connection conn)
                                                  throws java.io.UnsupportedEncodingException,
                                                         java.sql.SQLException

Get a converter for the given encoding name

Parameters:
  `encodingName` - the Java character encoding name
  `conn` -
Returns:
  a converter for the given encoding name
Throws:
  `java.io.UnsupportedEncodingException` - if the character encoding is not supported
  `java.sql.SQLException`

#### initCharset

    public static SingleByteCharsetConverter initCharset(java.lang.String javaEncodingName)
                                                  throws java.io.UnsupportedEncodingException,
                                                         java.sql.SQLException

Initialize the shared instance of a converter for the given character encoding.

Parameters:
  `javaEncodingName` - the Java name for the character set to initialize
Returns:
  a converter for the given character set
Throws:
  `java.io.UnsupportedEncodingException` - if the character encoding is not supported
  `java.sql.SQLException`

#### toStringDefaultEncoding

    public static java.lang.String toStringDefaultEncoding(byte[] buffer,
                                           int startPos,
                                           int length)

Convert the byte buffer from startPos to a length of length to a string using the default platform encoding.

Parameters:
  `buffer` - the bytes to convert
  `startPos` - the index to start at
  `length` - the number of bytes to convert
Returns:
  the String representation of the given bytes

#### toBytes

    public final byte[] toBytes(char[] c)

#### toBytesWrapped

    public final byte[] toBytesWrapped(char[] c,
                        char beginWrap,
                        char endWrap)

#### toBytes

    public final byte[] toBytes(char[] chars,
                 int offset,
                 int length)

#### toBytes

    public final byte[] toBytes(java.lang.String s)

Convert the given string to an array of bytes.

Parameters:
  `s` - the String to convert
Returns:
  the bytes that make up the String

#### toBytesWrapped

    public final byte[] toBytesWrapped(java.lang.String s,
                        char beginWrap,
                        char endWrap)

#### toBytes

    public final byte[] toBytes(java.lang.String s,
                 int offset,
                 int length)

Convert the given string to an array of bytes.

Parameters:
  `s` - the String to convert
  `offset` - the offset to start at
  `length` - length (max) to convert
Returns:
  the bytes that make up the String

#### toString

    public final java.lang.String toString(byte[] buffer)

Convert the byte buffer to a string using this instance's character encoding.

Parameters:
  `buffer` - the bytes to convert to a String
Returns:
  the converted String

#### toString

    public final java.lang.String toString(byte[] buffer,
                            int startPos,
                            int length)

Convert the byte buffer from startPos to a length of length to a string using this instance's character encoding.

Parameters:
  `buffer` - the bytes to convert
  `startPos` - the index to start at
  `length` - the number of bytes to convert
Returns:
  the String representation of the given bytes