Package org.postgresql.core
Class Encoding
- java.lang.Object
-
- org.postgresql.core.Encoding
-
public class Encoding extends java.lang.ObjectRepresentation of a particular character encoding.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedEncoding(java.lang.String encoding)Use the charset passed as parameter.
-
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.java.lang.StringtoString()
-
-
-
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
-
-