- All Known Implementing Classes:
CharsetEncoding.Any
Not all of the encodings that PostgreSQL supports for communication with
the client are also supported for use in the backend and in storage.
The usableOnServer
method identifies which ones
are suitable as server encodings.
The encoding that is in use for the current database cannot change during
a session, and is found in the final SERVER_ENCODING
field.
The encoding currently in use by the connected client may change during
a session, and is returned by the clientEncoding
method.
The charset
method returns the corresponding Java
Charset
if that can be identified, and several convenience
methods are provided to decode or encode values accordingly.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
A distinguishedCharsetEncoding
representing uses such as-1
in thecollencoding
column ofpg_collation
, indicating the collation is usable with any encoding. -
Field Summary
Modifier and TypeFieldDescriptionstatic final CharsetEncoding.Any
A distinguishedCharsetEncoding
representing uses such as-1
in thecollencoding
column ofpg_collation
, indicating the collation is usable with any encoding.static final CharsetEncoding
-
Method Summary
Modifier and TypeMethodDescriptioncharset()
Returns the corresponding JavaCharset
, or null if none can be identified.static CharsetEncoding
Returns the encoding currently selected by the connected client.default CharBuffer
decode
(ByteBuffer bb) Decode bytes to characters, with exceptions reported.default CharBuffer
decode
(Datum.Input in, boolean close) Decode bytes to characters, with exceptions reported.default ByteBuffer
Encode characters to bytes, with exceptions reported.default ByteBuffer
encode
(CharBuffer cb) Encode characters to bytes, with exceptions reported.static CharsetEncoding
Returns theCharsetEncoding
for the given PostgreSQL encoding name.static CharsetEncoding
fromOrdinal
(int ordinal) Returns theCharsetEncoding
for the given PostgreSQL encoding number (as used in theencoding
columns of some system catalogs).icuName()
Returns the name identifying this encoding in ICU (international components for Unicode), or null if its implementation in PostgreSQL does not define one.name()
Returns the PostgreSQL name for this encoding.default CharsetDecoder
Returns aCharsetDecoder
, configured to report all decoding errors (rather than silently substituting data), ifcharset()
would return a non-null value.default CharsetEncoder
Returns aCharsetEncoder
, configured to report all encoding errors (rather than silently substituting data), ifcharset()
would return a non-null value.int
ordinal()
Returns the PostgreSQL encoding number (as used in theencoding
columns of some system catalogs) for this encoding.default InputStreamReader
reader
(InputStream in) Return anInputStreamReader
that reports exceptions.boolean
Indicates whether this encoding is usable as a server encoding.default OutputStreamWriter
writer
(OutputStream out) Return anOutputStreamWriter
that reports exceptions.
-
Field Details
-
SERVER_ENCODING
-
ANY
A distinguishedCharsetEncoding
representing uses such as-1
in thecollencoding
column ofpg_collation
, indicating the collation is usable with any encoding.This is its only instance.
-
-
Method Details
-
clientEncoding
Returns the encoding currently selected by the connected client. -
fromOrdinal
Returns theCharsetEncoding
for the given PostgreSQL encoding number (as used in theencoding
columns of some system catalogs).- Throws:
IllegalArgumentException
- if the argument is not the ordinal of some known encoding
-
fromName
Returns theCharsetEncoding
for the given PostgreSQL encoding name.- Throws:
IllegalArgumentException
- if the argument is not the name of some known encoding
-
ordinal
int ordinal()Returns the PostgreSQL encoding number (as used in theencoding
columns of some system catalogs) for this encoding. -
name
String name()Returns the PostgreSQL name for this encoding.The PostgreSQL encoding names have a long history and may not match cleanly with more standardized names in modern libraries.
-
icuName
String icuName()Returns the name identifying this encoding in ICU (international components for Unicode), or null if its implementation in PostgreSQL does not define one.When present, the ICU name can be a better choice for matching encodings in other libraries.
-
usableOnServer
boolean usableOnServer()Indicates whether this encoding is usable as a server encoding. -
charset
Charset charset()Returns the corresponding JavaCharset
, or null if none can be identified. -
newDecoder
Returns aCharsetDecoder
, configured to report all decoding errors (rather than silently substituting data), ifcharset()
would return a non-null value. -
newEncoder
Returns aCharsetEncoder
, configured to report all encoding errors (rather than silently substituting data), ifcharset()
would return a non-null value. -
decode
Decode bytes to characters, with exceptions reported.Unlike the corresponding convenience method on
Charset
, this method will throw exceptions rather than silently substituting characters. This is a database system; it doesn't go changing your data without telling you.Other behaviors can be obtained by calling
newDecoder
and configuring it as desired.- Throws:
CharacterCodingException
-
encode
Encode characters to bytes, with exceptions reported.Unlike the corresponding convenience method on
Charset
, this method will throw exceptions rather than silently substituting characters. This is a database system; it doesn't go changing your data without telling you.Other behaviors can be obtained by calling
newEncoder
and configuring it as desired.- Throws:
CharacterCodingException
-
encode
Encode characters to bytes, with exceptions reported.Unlike the corresponding convenience method on
Charset
, this method will throw exceptions rather than silently substituting characters. This is a database system; it doesn't go changing your data without telling you.Other behaviors can be obtained by calling
newEncoder
and configuring it as desired.- Throws:
CharacterCodingException
-
decode
Decode bytes to characters, with exceptions reported.The input
Datum
is pinned around the decoding operation.- Throws:
SQLException
IOException
-
reader
Return anInputStreamReader
that reports exceptions.Other behaviors can be obtained by calling
newDecoder
and configuring it as desired before constructing anInputStreamReader
. -
writer
Return anOutputStreamWriter
that reports exceptions.Other behaviors can be obtained by calling
newEncoder
and configuring it as desired before constructing anOutputStreamWriter
.
-