You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by mw...@apache.org on 2009/01/25 19:49:28 UTC
svn commit: r737567 -
/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/codec/EncoderUtil.java
Author: mwiederkehr
Date: Sun Jan 25 18:49:27 2009
New Revision: 737567
URL: http://svn.apache.org/viewvc?rev=737567&view=rev
Log:
MIME4J-100: use BitSet instead of boolean[] for quoted-printable character tables
Modified:
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/codec/EncoderUtil.java
Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/codec/EncoderUtil.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/codec/EncoderUtil.java?rev=737567&r1=737566&r2=737567&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/codec/EncoderUtil.java (original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/codec/EncoderUtil.java Sun Jan 25 18:49:27 2009
@@ -34,16 +34,9 @@
private static final byte[] BASE64_TABLE = Base64OutputStream.BASE64_TABLE;
private static final char BASE64_PAD = '=';
- private static final boolean[] ENCODE_Q_REGULAR = initQTable("=_?");
- private static final boolean[] ENCODE_Q_RESTRICTED = initQTable("=_?\"#$%&'(),.:;<>@[\\]^`{|}~");
+ private static final BitSet Q_REGULAR_CHARS = initChars("=_?");
- private static boolean[] initQTable(String needToEncode) {
- boolean[] table = new boolean[128];
- for (int i = 0; i < 128; i++) {
- table[i] = i < 32 || i >= 127 || needToEncode.indexOf(i) != -1;
- }
- return table;
- }
+ private static final BitSet Q_RESTRICTED_CHARS = initChars("=_?\"#$%&'(),.:;<>@[\\]^`{|}~");
private static final int MAX_USED_CHARACTERS = 50;
@@ -383,8 +376,8 @@
* @return encoded string.
*/
public static String encodeQ(byte[] bytes, Usage usage) {
- boolean[] encode = usage == Usage.TEXT_TOKEN ? ENCODE_Q_REGULAR
- : ENCODE_Q_RESTRICTED;
+ BitSet qChars = usage == Usage.TEXT_TOKEN ? Q_REGULAR_CHARS
+ : Q_RESTRICTED_CHARS;
StringBuilder sb = new StringBuilder();
@@ -393,7 +386,7 @@
int v = bytes[idx] & 0xff;
if (v == 32) {
sb.append('_');
- } else if (v >= 128 || encode[v]) {
+ } else if (!qChars.get(v)) {
sb.append('=');
sb.append(hexDigit(v >>> 4));
sb.append(hexDigit(v & 0xf));
@@ -522,8 +515,8 @@
}
private static int qEncodedLength(byte[] bytes, Usage usage) {
- boolean[] encode = usage == Usage.TEXT_TOKEN ? ENCODE_Q_REGULAR
- : ENCODE_Q_RESTRICTED;
+ BitSet qChars = usage == Usage.TEXT_TOKEN ? Q_REGULAR_CHARS
+ : Q_RESTRICTED_CHARS;
int count = 0;
@@ -531,7 +524,7 @@
int v = bytes[idx] & 0xff;
if (v == 32) {
count++;
- } else if (v >= 128 || encode[v]) {
+ } else if (!qChars.get(v)) {
count += 3;
} else {
count++;
@@ -569,13 +562,13 @@
if (bytes.length == 0)
return Encoding.Q;
- boolean[] encode = usage == Usage.TEXT_TOKEN ? ENCODE_Q_REGULAR
- : ENCODE_Q_RESTRICTED;
+ BitSet qChars = usage == Usage.TEXT_TOKEN ? Q_REGULAR_CHARS
+ : Q_RESTRICTED_CHARS;
int qEncoded = 0;
for (int i = 0; i < bytes.length; i++) {
int v = bytes[i] & 0xff;
- if (v >= 128 || encode[v]) {
+ if (v != 32 && !qChars.get(v)) {
qEncoded++;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org