Package org.postgresql.core
Class Encoding
java.lang.Object
org.postgresql.core.Encoding
- Direct Known Subclasses:
OptimizedUTF8Encoder
Representation of a particular character encoding.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Encoding
private final Charset
private final boolean
private static final Logger
private static final Encoding.UTFEncodingProvider
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Encoding()
Uses the default charset of the JVM.protected
Use the charset passed as parameter and tests at creation time whether the specified encoding is compatible with ASCII numbers.protected
Subclasses may use this constructor if they know in advance of their ASCII number compatibility. -
Method Summary
Modifier and TypeMethodDescriptiondecode
(byte[] encodedString) Decode an array of bytes into a string.decode
(byte[] encodedString, int offset, int length) Decode an array of bytes into a string.static Encoding
Get an Encoding using the default encoding for the JVM.byte[]
Encode a string to an array of bytes.static Encoding
getDatabaseEncoding
(String databaseEncoding) Construct an Encoding for a given database encoding.Get a Reader that decodes the given InputStream using this encoding.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
Returns true if this encoding has characters '-' and '0'..'9' in exactly same posision as ascii.name()
Get the name of the (JVM) encoding used.private static boolean
testAsciiNumbers
(Charset encoding) Checks whether this encoding is compatible with ASCII for the number characters '-' and '0'..'9'.toString()
-
Field Details
-
LOGGER
-
DEFAULT_ENCODING
-
encodings
-
UTF_ENCODING_PROVIDER
-
encoding
-
fastASCIINumbers
private final boolean fastASCIINumbers
-
-
Constructor Details
-
Encoding
private Encoding()Uses the default charset of the JVM. -
Encoding
Subclasses may use this constructor if they know in advance of their ASCII number compatibility.- Parameters:
encoding
- charset to usefastASCIINumbers
- whether this encoding is compatible with ASCII numbers.
-
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 posision as ascii.- Returns:
- true if the bytes can be scanned directly for ascii numbers.
-
getJVMEncoding
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
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.
-
name
Get the name of the (JVM) encoding used.- Returns:
- the JVM encoding name used by this instance.
-
encode
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
-
decode
Decode an array of bytes into a string.- Parameters:
encodedString
- a byte array containing the string to decodeoffset
- the offset inencodedString
of the first byte of the encoded representationlength
- the length, in bytes, of the encoded representation- Returns:
- the decoded string
- Throws:
IOException
- if something goes wrong
-
decode
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
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
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
Get an Encoding using the default encoding for the JVM.- Returns:
- an Encoding instance
-
toString
-
testAsciiNumbers
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:
- If faster ASCII number parsing can be used with this encoding.
-