Package org.postgresql.core

# Class Encoding

java.lang.Object
org.postgresql.core.Encoding

public class Encoding extends Object
Representation of a particular character encoding.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`Encoding(Charset encoding)`
Use the charset passed as parameter and tests at creation time whether the specified encoding is compatible with ASCII numbers.
`protected`
`Encoding(Charset encoding, boolean fastASCIINumbers)`
Subclasses may use this constructor if they know in advance of their ASCII number compatibility.

## Method Summary

Modifier and Type
Method
Description
`static void`
`canonicalize(String string)`
Indicates that string should be staged as a canonicalized value.
`String`
`decode(byte[] encodedString)`
Decode an array of bytes into a string.
`String`
`decode(byte[] encodedString, int offset, int length)`
Decode an array of bytes into a string.
`String`
`decodeCanonicalized(byte[] encodedString)`
Decode an array of bytes possibly into a canonicalized string.
`String`
`decodeCanonicalized(byte[] encodedString, int offset, int length)`
Decode an array of bytes possibly into a canonicalized string.
`String`
`decodeCanonicalizedIfPresent(byte[] encodedString, int offset, int length)`
`static Encoding`
`defaultEncoding()`
Get an Encoding using the default encoding for the JVM.
`byte @PolyNull []`
`encode(@PolyNull String s)`
Encode a string to an array of bytes.
`static Encoding`
`getDatabaseEncoding(String databaseEncoding)`
Construct an Encoding for a given database encoding.
`Reader`
`getDecodingReader(InputStream in)`
Get a Reader that decodes the given InputStream using this encoding.
`Writer`
`getEncodingWriter(OutputStream out)`
Get a Writer that encodes to the given OutputStream using this encoding.
`static Encoding`
`getJVMEncoding(String jvmEncoding)`
Construct an Encoding for a given JVM encoding.
`boolean`
`hasAsciiNumbers()`
Returns true if this encoding has characters '-' and '0'..'9' in exactly same position as ascii.
`String`
`name()`
Get the name of the (JVM) encoding used.
`String`
`toString()`

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

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

## Constructor Details

### Encoding

protected Encoding(Charset encoding, boolean fastASCIINumbers)
Subclasses may use this constructor if they know in advance of their ASCII number compatibility.

Parameters:
  `encoding` - charset to use
  `fastASCIINumbers` - whether this encoding is compatible with ASCII numbers.

### Encoding

protected Encoding(Charset encoding)
Use the charset passed as parameter and tests at creation time whether the specified encoding is compatible with ASCII numbers.

Parameters:
  `encoding` - charset to use

## Method Details

### hasAsciiNumbers

public boolean hasAsciiNumbers()
Returns true if this encoding has characters '-' and '0'..'9' in exactly same position as ascii.

Returns:
  true if the bytes can be scanned directly for ascii numbers.

### getJVMEncoding

public static Encoding getJVMEncoding(String jvmEncoding)
Construct an Encoding for a given JVM encoding.

Parameters:
  `jvmEncoding` - the name of the JVM encoding
Returns:
  an Encoding instance for the specified encoding, or an Encoding instance for the default JVM encoding if the specified encoding is unavailable.

### getDatabaseEncoding

public static Encoding getDatabaseEncoding(String databaseEncoding)
Construct an Encoding for a given database encoding.

Parameters:
  `databaseEncoding` - the name of the database encoding
Returns:
  an Encoding instance for the specified encoding, or an Encoding instance for the default JVM encoding if the specified encoding is unavailable.

### canonicalize

public static void canonicalize(String string)
Indicates that string should be staged as a canonicalized value.

This is intended for use with `String` constants.

Parameters:
  `string` - The string to maintain canonicalized reference to. Must not be `null`.
See Also:
  - `decodeCanonicalized(byte[], int, int)`

### name

public String name()
Get the name of the (JVM) encoding used.

Returns:
  the JVM encoding name used by this instance.

### encode

public byte @PolyNull [] encode(@PolyNull String s) throws IOException
Encode a string to an array of bytes.

Parameters:
  `s` - the string to encode
Returns:
  a bytearray containing the encoded string
Throws:
  `IOException` - if something goes wrong

### decodeCanonicalized

public String decodeCanonicalized(byte[] encodedString, int offset, int length) throws IOException
Decode an array of bytes possibly into a canonicalized string.

Only ascii compatible encoding support canonicalization and only ascii `String` values are eligible to be canonicalized.

Parameters:
  `encodedString` - a byte array containing the string to decode
  `offset` - the offset in `encodedString` of the first byte of the encoded representation
  `length` - the length, in bytes, of the encoded representation
Returns:
  the decoded string
Throws:
  `IOException` - if something goes wrong

### decodeCanonicalizedIfPresent

public String decodeCanonicalizedIfPresent(byte[] encodedString, int offset, int length) throws IOException

Throws:
  `IOException`

### decodeCanonicalized

public String decodeCanonicalized(byte[] encodedString) throws IOException
Decode an array of bytes possibly into a canonicalized string.

Only ascii compatible encoding support canonicalization and only ascii `String` values are eligible to be canonicalized.

Parameters:
  `encodedString` - a byte array containing the string to decode
Returns:
  the decoded string
Throws:
  `IOException` - if something goes wrong

### decode

public String decode(byte[] encodedString, int offset, int length) throws IOException
Decode an array of bytes into a string.

Parameters:
  `encodedString` - a byte array containing the string to decode
  `offset` - the offset in `encodedString` of the first byte of the encoded representation
  `length` - the length, in bytes, of the encoded representation
Returns:
  the decoded string
Throws:
  `IOException` - if something goes wrong

### decode

public String decode(byte[] encodedString) throws IOException
Decode an array of bytes into a string.

Parameters:
  `encodedString` - a byte array containing the string to decode
Returns:
  the decoded string
Throws:
  `IOException` - if something goes wrong

### getDecodingReader

public Reader getDecodingReader(InputStream in) throws IOException
Get a Reader that decodes the given InputStream using this encoding.

Parameters:
  `in` - the underlying stream to decode from
Returns:
  a non-null Reader implementation.
Throws:
  `IOException` - if something goes wrong

### getEncodingWriter

public Writer getEncodingWriter(OutputStream out) throws IOException
Get a Writer that encodes to the given OutputStream using this encoding.

Parameters:
  `out` - the underlying stream to encode to
Returns:
  a non-null Writer implementation.
Throws:
  `IOException` - if something goes wrong

### defaultEncoding

public static Encoding defaultEncoding()
Get an Encoding using the default encoding for the JVM.

Returns:
  an Encoding instance

### toString

public String toString()

Overrides:
  `toString` in class `Object`