Package org.postgresql.core
Class Encoding
- java.lang.Object
-
- org.postgresql.core.Encoding
-
- Direct Known Subclasses:
OptimizedUTF8Encoder
public class Encoding extends java.lang.ObjectRepresentation of a particular character encoding.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interfaceEncoding.UTFEncodingProvider
-
Field Summary
Fields Modifier and Type Field Description private static EncodingDEFAULT_ENCODINGprivate java.nio.charset.Charsetencodingprivate static java.util.HashMap<java.lang.String,java.lang.String[]>encodingsprivate booleanfastASCIINumbersprivate static java.util.logging.LoggerLOGGERprivate static Encoding.UTFEncodingProviderUTF_ENCODING_PROVIDER
-
Constructor Summary
Constructors Modifier Constructor Description privateEncoding()Uses the default charset of the JVM.protectedEncoding(java.nio.charset.Charset encoding)Use the charset passed as parameter and tests at creation time whether the specified encoding is compatible with ASCII numbers.protectedEncoding(java.nio.charset.Charset encoding, boolean fastASCIINumbers)Subclasses may use this constructor if they know in advance of their ASCII number compatibility.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringdecode(byte[] encodedString)Decode an array of bytes into a string.java.lang.Stringdecode(byte[] encodedString, int offset, int length)Decode an array of bytes into a string.static EncodingdefaultEncoding()Get an Encoding using the default encoding for the JVM.byte[]encode(java.lang.String s)Encode a string to an array of bytes.static EncodinggetDatabaseEncoding(java.lang.String databaseEncoding)Construct an Encoding for a given database encoding.java.io.ReadergetDecodingReader(java.io.InputStream in)Get a Reader that decodes the given InputStream using this encoding.java.io.WritergetEncodingWriter(java.io.OutputStream out)Get a Writer that encodes to the given OutputStream using this encoding.static EncodinggetJVMEncoding(java.lang.String jvmEncoding)Construct an Encoding for a given JVM encoding.booleanhasAsciiNumbers()Returns true if this encoding has characters '-' and '0'..'9' in exactly same posision as ascii.java.lang.Stringname()Get the name of the (JVM) encoding used.private static booleantestAsciiNumbers(java.nio.charset.Charset encoding)Checks whether this encoding is compatible with ASCII for the number characters '-' and '0'..'9'.java.lang.StringtoString()
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
DEFAULT_ENCODING
private static final Encoding DEFAULT_ENCODING
-
encodings
private static final java.util.HashMap<java.lang.String,java.lang.String[]> encodings
-
UTF_ENCODING_PROVIDER
private static final Encoding.UTFEncodingProvider UTF_ENCODING_PROVIDER
-
encoding
private final java.nio.charset.Charset encoding
-
fastASCIINumbers
private final boolean fastASCIINumbers
-
-
Constructor Detail
-
Encoding
private Encoding()
Uses the default charset of the JVM.
-
Encoding
protected Encoding(java.nio.charset.Charset encoding, boolean fastASCIINumbers)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
protected Encoding(java.nio.charset.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 Detail
-
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
public static Encoding getJVMEncoding(java.lang.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(java.lang.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.
-
name
public java.lang.String name()
Get the name of the (JVM) encoding used.- Returns:
- the JVM encoding name used by this instance.
-
encode
public byte[] encode(java.lang.String s) throws java.io.IOExceptionEncode a string to an array of bytes.- Parameters:
s- the string to encode- Returns:
- a bytearray containing the encoded string
- Throws:
java.io.IOException- if something goes wrong
-
decode
public java.lang.String decode(byte[] encodedString, int offset, int length) throws java.io.IOExceptionDecode an array of bytes into a string.- Parameters:
encodedString- a byte array containing the string to decodeoffset- the offset inencodedStringof the first byte of the encoded representationlength- the length, in bytes, of the encoded representation- Returns:
- the decoded string
- Throws:
java.io.IOException- if something goes wrong
-
decode
public java.lang.String decode(byte[] encodedString) throws java.io.IOExceptionDecode an array of bytes into a string.- Parameters:
encodedString- a byte array containing the string to decode- Returns:
- the decoded string
- Throws:
java.io.IOException- if something goes wrong
-
getDecodingReader
public java.io.Reader getDecodingReader(java.io.InputStream in) throws java.io.IOExceptionGet 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:
java.io.IOException- if something goes wrong
-
getEncodingWriter
public java.io.Writer getEncodingWriter(java.io.OutputStream out) throws java.io.IOExceptionGet 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:
java.io.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 java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
testAsciiNumbers
private static boolean testAsciiNumbers(java.nio.charset.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:
- If faster ASCII number parsing can be used with this encoding.
-
-