[kaffe] CVS kaffe (kaz): Resynced with GNU Classpath:
Kaffe CVS
cvs-commits at kaffe.org
Fri May 6 18:48:52 PDT 2005
PatchSet 6444
Date: 2005/05/07 01:44:23
Author: kaz
Branch: HEAD
Tag: (none)
Log:
2005-05-07 Ito Kazumitsu <kaz at maczuka.gcd.org>
Resynced with GNU Classpath:
2005-05-05 Chris Burdess <dog at gnu.org>
* gnu/xml/transform/StreamSerializer.java: Produce compact,
human-readable XML for non-UTF/ASCII encodings using NIO.
Members:
ChangeLog:1.3972->1.3973
libraries/javalib/gnu/xml/transform/StreamSerializer.java:1.3->1.4
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3972 kaffe/ChangeLog:1.3973
--- kaffe/ChangeLog:1.3972 Fri May 6 17:05:14 2005
+++ kaffe/ChangeLog Sat May 7 01:44:23 2005
@@ -1,3 +1,12 @@
+2005-05-07 Ito Kazumitsu <kaz at maczuka.gcd.org>
+
+ Resynced with GNU Classpath:
+
+ 2005-05-05 Chris Burdess <dog at gnu.org>
+
+ * gnu/xml/transform/StreamSerializer.java: Produce compact,
+ human-readable XML for non-UTF/ASCII encodings using NIO.
+
2005-05-06 Guilhem Lavaux <guilhem at kaffe.org>
* kaffe/kaffevm/systems/unix-pthreads/thread-impl.c
Index: kaffe/libraries/javalib/gnu/xml/transform/StreamSerializer.java
diff -u kaffe/libraries/javalib/gnu/xml/transform/StreamSerializer.java:1.3 kaffe/libraries/javalib/gnu/xml/transform/StreamSerializer.java:1.4
--- kaffe/libraries/javalib/gnu/xml/transform/StreamSerializer.java:1.3 Wed Jan 5 17:11:46 2005
+++ kaffe/libraries/javalib/gnu/xml/transform/StreamSerializer.java Sat May 7 01:44:26 2005
@@ -41,6 +41,10 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -68,8 +72,9 @@
static final int KET = 0x3e; // >
static final int EQ = 0x3d; // =
- protected String encoding;
- boolean compatibilityMode;
+ protected final String encoding;
+ final Charset charset;
+ final CharsetEncoder encoder;
final int mode;
final Map namespaces;
protected String eol;
@@ -96,16 +101,8 @@
encoding = "UTF-8";
}
this.encoding = encoding.intern();
- compatibilityMode = true;
- if (encoding.length() > 3)
- {
- String p = encoding.substring(0, 3);
- if (p.equalsIgnoreCase("UTF") ||
- p.equalsIgnoreCase("UCS"))
- {
- compatibilityMode = false;
- }
- }
+ charset = Charset.forName(this.encoding);
+ encoder = charset.newEncoder();
this.eol = (eol != null) ? eol : System.getProperty("line.separator");
namespaces = new HashMap();
}
@@ -498,37 +495,42 @@
}
final byte[] encodeText(String text)
- throws UnsupportedEncodingException
+ throws IOException
{
- if (compatibilityMode)
+ encoder.reset();
+ if (!encoder.canEncode(text))
{
+ // Check each character
+ StringBuffer buf = new StringBuffer();
int len = text.length();
- StringBuffer buf = null;
for (int i = 0; i < len; i++)
{
char c = text.charAt(i);
- if (c >= 127)
+ if (encoder.canEncode(c))
{
- if (buf == null)
- {
- buf = new StringBuffer(text.substring(0, i));
- }
- buf.append('&');
- buf.append('#');
- buf.append((int) c);
- buf.append(';');
+ buf.append(c);
}
- else if (buf != null)
+ else
{
- buf.append(c);
+ // Replace with character entity reference
+ String hex = Integer.toHexString((int) c);
+ buf.append("&#x");
+ buf.append(hex);
+ buf.append(';');
}
}
- if (buf != null)
- {
- text = buf.toString();
- }
+ text = buf.toString();
+ }
+ ByteBuffer encoded = encoder.encode(CharBuffer.wrap(text));
+ if (encoded.hasArray())
+ {
+ return encoded.array();
}
- return text.getBytes(encoding);
+ encoded.flip();
+ int len = encoded.limit() - encoded.position();
+ byte[] ret = new byte[len];
+ encoded.get(ret, 0, len);
+ return ret;
}
String encode(String text, boolean encodeCtl, boolean inAttr)
@@ -628,5 +630,5 @@
throw new RuntimeException(e.getMessage());
}
}
-
+
}
More information about the kaffe
mailing list