Top Description Fields Constructors Methods
org.postgresql.core

public Class Encoding

extends Object
Class Inheritance
Imports
org.checkerframework.checker.nullness.qual.PolyNull, java.io.IOException, .InputStream, .InputStreamReader, .OutputStream, .OutputStreamWriter, .Reader, .Writer, java.nio.charset.Charset, .StandardCharsets, java.util.HashMap, java.util.logging.Level, .Logger

Representation of a particular character encoding.

Field Summary

Modifier and TypeField and Description
private static final Encoding
private final Charset
private static final HashMap<String, String[]>
private final boolean
pack-priv static final AsciiStringInterner
private static final Logger
private static final Encoding

Constructor Summary

AccessConstructor and Description
private
Encoding()

Uses the default charset of the JVM.

protected
Encoding(Charset
charset to use
encoding
,
boolean
whether this encoding is compatible with ASCII numbers.
fastASCIINumbers
)

Subclasses may use this constructor if they know in advance of their ASCII number compatibility.

protected
Encoding(Charset
charset to use
encoding
)

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

Method Summary

Modifier and TypeMethod and Description
public static void
canonicalize(String
The string to maintain canonicalized reference to. Must not be null.
string
)

Indicates that string should be staged as a canonicalized value.

public String

Returns:

the decoded string
decode
(byte[]
a byte array containing the string to decode
encodedString
,
int
the offset in encodedString of the first byte of the encoded representation
offset
,
int
the length, in bytes, of the encoded representation
length
)

Decode an array of bytes into a string.

public String

Returns:

the decoded string
decode
(byte[]
a byte array containing the string to decode
encodedString
)

Decode an array of bytes into a string.

public String

Returns:

the decoded string
decodeCanonicalized
(byte[]
a byte array containing the string to decode
encodedString
,
int
the offset in encodedString of the first byte of the encoded representation
offset
,
int
the length, in bytes, of the encoded representation
length
)

Decode an array of bytes possibly into a canonicalized string.

public String

Returns:

the decoded string
decodeCanonicalized
(byte[]
a byte array containing the string to decode
encodedString
)

Decode an array of bytes possibly into a canonicalized string.

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

public static Encoding

Returns:

an Encoding instance
defaultEncoding
()

Get an Encoding using the default encoding for the JVM.

public @PolyNull byte[]

Returns:

a bytearray containing the encoded string
encode
(@PolyNull String
the string to encode
s
)

Encode a string to an array of bytes.

public static 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
(String
the name of the database encoding
databaseEncoding
)

Construct an Encoding for a given database encoding.

public Reader

Returns:

a non-null Reader implementation.
getDecodingReader
(InputStream
the underlying stream to decode from
in
)

Get a Reader that decodes the given InputStream using this encoding.

public Writer

Returns:

a non-null Writer implementation.
getEncodingWriter
(OutputStream
the underlying stream to encode to
out
)

Get a Writer that encodes to the given OutputStream using this encoding.

public static Encoding

Returns:

an Encoding instance for the specified encoding, or an Encoding instance for the default JVM encoding if the specified encoding is unavailable.
getJVMEncoding
(String
the name of the JVM encoding
jvmEncoding
)

Construct an Encoding for a given JVM encoding.

public boolean

Returns:

true if the bytes can be scanned directly for ascii numbers.
hasAsciiNumbers
()

Returns true if this encoding has characters '-' and '0'..'9' in exactly same position as ascii.

public String

Returns:

the JVM encoding name used by this instance.
name
()

Get the name of the (JVM) encoding used.

private static boolean

Returns:

If faster ASCII number parsing can be used with this encoding.
testAsciiNumbers
(Charset encoding)

Checks whether this encoding is compatible with ASCII for the number characters '-' and '0'..'9'.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

DEFAULT_ENCODINGback to summary
private static final Encoding DEFAULT_ENCODING
encodingback to summary
private final Charset encoding
encodingsback to summary
private static final HashMap<String, String[]> encodings
fastASCIINumbersback to summary
private final boolean fastASCIINumbers
INTERNERback to summary
pack-priv static final AsciiStringInterner INTERNER
LOGGERback to summary
private static final Logger LOGGER
UTF8_ENCODINGback to summary
private static final Encoding UTF8_ENCODING

Constructor Detail

Encodingback to summary
private Encoding()

Uses the default charset of the JVM.

Encodingback to summary
protected Encoding(Charset encoding, boolean fastASCIINumbers)

Subclasses may use this constructor if they know in advance of their ASCII number compatibility.

Parameters
encoding:Charset

charset to use

fastASCIINumbers:boolean

whether this encoding is compatible with ASCII numbers.

Encodingback to summary
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

charset to use

Method Detail

canonicalizeback to summary
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:String

The string to maintain canonicalized reference to. Must not be null.

See Also
Encoding#decodeCanonicalized(byte[], int, int)
decodeback to summary
public String decode(byte[] encodedString, int offset, int length) throws IOException

Decode an array of bytes into a string.

Parameters
encodedString:byte[]

a byte array containing the string to decode

offset:int

the offset in encodedString of the first byte of the encoded representation

length:int

the length, in bytes, of the encoded representation

Returns:String

the decoded string

Exceptions
IOException:
if something goes wrong
decodeback to summary
public String decode(byte[] encodedString) throws IOException

Decode an array of bytes into a string.

Parameters
encodedString:byte[]

a byte array containing the string to decode

Returns:String

the decoded string

Exceptions
IOException:
if something goes wrong
decodeCanonicalizedback to summary
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:byte[]

a byte array containing the string to decode

offset:int

the offset in encodedString of the first byte of the encoded representation

length:int

the length, in bytes, of the encoded representation

Returns:String

the decoded string

Exceptions
IOException:
if something goes wrong
decodeCanonicalizedback to summary
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:byte[]

a byte array containing the string to decode

Returns:String

the decoded string

Exceptions
IOException:
if something goes wrong
decodeCanonicalizedIfPresentback to summary
public String decodeCanonicalizedIfPresent(byte[] encodedString, int offset, int length) throws IOException
defaultEncodingback to summary
public static Encoding defaultEncoding()

Get an Encoding using the default encoding for the JVM.

Returns:Encoding

an Encoding instance

encodeback to summary
public @PolyNull byte[] encode(@PolyNull String s) throws IOException

Encode a string to an array of bytes.

Parameters
s:@PolyNull String

the string to encode

Returns:@PolyNull byte[]

a bytearray containing the encoded string

Exceptions
IOException:
if something goes wrong
getDatabaseEncodingback to summary
public static Encoding getDatabaseEncoding(String databaseEncoding)

Construct an Encoding for a given database encoding.

Parameters
databaseEncoding:String

the name of the database encoding

Returns:Encoding

an Encoding instance for the specified encoding, or an Encoding instance for the default JVM encoding if the specified encoding is unavailable.

getDecodingReaderback to summary
public Reader getDecodingReader(InputStream in) throws IOException

Get a Reader that decodes the given InputStream using this encoding.

Parameters
in:InputStream

the underlying stream to decode from

Returns:Reader

a non-null Reader implementation.

Exceptions
IOException:
if something goes wrong
getEncodingWriterback to summary
public Writer getEncodingWriter(OutputStream out) throws IOException

Get a Writer that encodes to the given OutputStream using this encoding.

Parameters
out:OutputStream

the underlying stream to encode to

Returns:Writer

a non-null Writer implementation.

Exceptions
IOException:
if something goes wrong
getJVMEncodingback to summary
public static Encoding getJVMEncoding(String jvmEncoding)

Construct an Encoding for a given JVM encoding.

Parameters
jvmEncoding:String

the name of the JVM encoding

Returns:Encoding

an Encoding instance for the specified encoding, or an Encoding instance for the default JVM encoding if the specified encoding is unavailable.

hasAsciiNumbersback to summary
public boolean hasAsciiNumbers()

Returns true if this encoding has characters '-' and '0'..'9' in exactly same position as ascii.

Returns:boolean

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

nameback to summary
public String name()

Get the name of the (JVM) encoding used.

Returns:String

the JVM encoding name used by this instance.

testAsciiNumbersback to summary
private static boolean testAsciiNumbers(Charset encoding)

Checks whether this encoding is compatible with ASCII for the number characters '-' and '0'..'9'. Where compatible means that they are encoded with exactly same values.

Returns:boolean

If faster ASCII number parsing can be used with this encoding.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override