public class Encoding
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static interface |
Encoding.UTFEncodingProvider |
Modifier and Type | Field and Description |
---|---|
private static Encoding |
DEFAULT_ENCODING |
private java.nio.charset.Charset |
encoding |
private static java.util.HashMap<java.lang.String,java.lang.String[]> |
encodings |
private boolean |
fastASCIINumbers |
private static java.util.logging.Logger |
LOGGER |
private static Encoding.UTFEncodingProvider |
UTF_ENCODING_PROVIDER |
Modifier | Constructor and Description |
---|---|
private |
Encoding()
Uses the default charset of the JVM.
|
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.
|
protected |
Encoding(java.nio.charset.Charset encoding,
boolean fastASCIINumbers)
Subclasses may use this constructor if they know in advance of their ASCII number
compatibility.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
decode(byte[] encodedString)
Decode an array of bytes into a string.
|
java.lang.String |
decode(byte[] encodedString,
int offset,
int length)
Decode an array of bytes into a string.
|
static Encoding |
defaultEncoding()
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 Encoding |
getDatabaseEncoding(java.lang.String databaseEncoding)
Construct an Encoding for a given database encoding.
|
java.io.Reader |
getDecodingReader(java.io.InputStream in)
Get a Reader that decodes the given InputStream using this encoding.
|
java.io.Writer |
getEncodingWriter(java.io.OutputStream out)
Get a Writer that encodes to the given OutputStream using this encoding.
|
static Encoding |
getJVMEncoding(java.lang.String jvmEncoding)
Construct an Encoding for a given JVM encoding.
|
boolean |
hasAsciiNumbers()
Returns true if this encoding has characters '-' and '0'..'9' in exactly same posision as
ascii.
|
java.lang.String |
name()
Get the name of the (JVM) encoding used.
|
private static boolean |
testAsciiNumbers(java.nio.charset.Charset encoding)
Checks whether this encoding is compatible with ASCII for the number characters '-' and
'0'..'9'.
|
java.lang.String |
toString() |
private static final java.util.logging.Logger LOGGER
private static final Encoding DEFAULT_ENCODING
private static final java.util.HashMap<java.lang.String,java.lang.String[]> encodings
private static final Encoding.UTFEncodingProvider UTF_ENCODING_PROVIDER
private final java.nio.charset.Charset encoding
private final boolean fastASCIINumbers
private Encoding()
protected Encoding(java.nio.charset.Charset encoding, boolean fastASCIINumbers)
encoding
- charset to usefastASCIINumbers
- whether this encoding is compatible with ASCII numbers.protected Encoding(java.nio.charset.Charset encoding)
encoding
- charset to usepublic boolean hasAsciiNumbers()
public static Encoding getJVMEncoding(java.lang.String jvmEncoding)
jvmEncoding
- the name of the JVM encodingpublic static Encoding getDatabaseEncoding(java.lang.String databaseEncoding)
databaseEncoding
- the name of the database encodingpublic java.lang.String name()
public byte[] encode(java.lang.String s) throws java.io.IOException
s
- the string to encodejava.io.IOException
- if something goes wrongpublic java.lang.String decode(byte[] encodedString, int offset, int length) throws java.io.IOException
encodedString
- a byte array containing the string to decodeoffset
- the offset in encodedString
of the first byte of the encoded
representationlength
- the length, in bytes, of the encoded representationjava.io.IOException
- if something goes wrongpublic java.lang.String decode(byte[] encodedString) throws java.io.IOException
encodedString
- a byte array containing the string to decodejava.io.IOException
- if something goes wrongpublic java.io.Reader getDecodingReader(java.io.InputStream in) throws java.io.IOException
in
- the underlying stream to decode fromjava.io.IOException
- if something goes wrongpublic java.io.Writer getEncodingWriter(java.io.OutputStream out) throws java.io.IOException
out
- the underlying stream to encode tojava.io.IOException
- if something goes wrongpublic static Encoding defaultEncoding()
public java.lang.String toString()
toString
in class java.lang.Object
private static boolean testAsciiNumbers(java.nio.charset.Charset encoding)