public class Translate
extends java.lang.Object
Typical usage:
String s = Translate.decode (getTextFromHtmlPage ());or
String s = "<HTML>" + Translate.encode (getArbitraryText ()) + "</HTML>";
限定符和类型 | 字段和说明 |
---|---|
static boolean |
DECODE_LINE_BY_LINE
If this member is set
true , decoding of streams is
done line by line in order to reduce the maximum memory required. |
static boolean |
ENCODE_HEXADECIMAL
If this member is set
true , encoding of numeric character
references uses hexadecimal digits, i.e. |
限定符和类型 | 方法和说明 |
---|---|
static void |
decode(java.io.InputStream in,
java.io.PrintStream out)
Decode a stream containing references.
|
static java.lang.String |
decode(java.lang.String string)
Decode a string containing references.
|
static java.lang.String |
decode(java.lang.StringBuffer buffer)
Decode the characters in a string buffer containing references.
|
static void |
encode(java.io.InputStream in,
java.io.PrintStream out)
Encode a stream to use references.
|
static java.lang.String |
encode(int character)
Convert a character to a numeric character reference.
|
static java.lang.String |
encode(java.lang.String string)
Encode a string to use references.
|
static CharacterReference |
lookup(char character)
Look up a reference by character.
|
static CharacterReference |
lookup(java.lang.String kernel,
int start,
int end)
Look up a reference by kernel.
|
static void |
main(java.lang.String[] args)
Numeric character reference and character entity reference to unicode codec.
|
public static boolean DECODE_LINE_BY_LINE
true
, decoding of streams is
done line by line in order to reduce the maximum memory required.public static boolean ENCODE_HEXADECIMAL
true
, encoding of numeric character
references uses hexadecimal digits, i.e. ○, instead of decimal
digits.public static CharacterReference lookup(char character)
character
- The character to be looked up.null
.public static CharacterReference lookup(java.lang.String kernel, int start, int end)
lookup(CharacterReference)
instead.kernel
- The string to lookup, i.e. "amp".start
- The starting point in the string of the kernel.end
- The ending point in the string of the kernel.
This should be the index of the semicolon if it exists, or failing that,
at least an index past the last character of the kernel.null
if it wasn't found.public static java.lang.String decode(java.lang.String string)
string
- The string to translate.public static java.lang.String decode(java.lang.StringBuffer buffer)
buffer
- The StringBuffer containing references.public static void decode(java.io.InputStream in, java.io.PrintStream out)
DECODE_LINE_BY_LINE
is true,
the input stream is broken up into lines, terminated by either
carriage return or newline, in order to reduce the latency and maximum
buffering memory size required.in
- The stream to translate. It is assumed that the input
stream is encoded with ISO-8859-1 since the table of character
entity references in this class applies only to ISO-8859-1.out
- The stream to write the decoded stream to.public static java.lang.String encode(int character)
character
- The character to convert.public static java.lang.String encode(java.lang.String string)
string
- The string to translate.public static void encode(java.io.InputStream in, java.io.PrintStream out)
in
- The stream to translate. It is assumed that the input
stream is encoded with ISO-8859-1 since the table of character
entity references in this class applies only to ISO-8859-1.out
- The stream to write the decoded stream to.public static void main(java.lang.String[] args)
System.in
input into an encoded or decoded
stream and send the results to System.out
.args
- If arg[0] is -encode
perform an encoding on
System.in
, otherwise perform a decoding.