public class Encoding
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static Encoding |
DEFAULT_ENCODING |
private java.lang.String |
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 |
UTF8_ENCODING |
Modifier | Constructor and Description |
---|---|
private |
Encoding()
Uses the default charset of the JVM.
|
protected |
Encoding(java.lang.String encoding)
Use the charset passed as parameter.
|
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 boolean |
testAsciiNumbers()
Checks weather 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 Encoding UTF8_ENCODING
private static final java.util.HashMap<java.lang.String,java.lang.String[]> encodings
private final java.lang.String encoding
private final boolean fastASCIINumbers
private Encoding()
protected Encoding(java.lang.String encoding)
encoding
- charset name 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 boolean testAsciiNumbers()