You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by sf...@apache.org on 2010/01/12 14:41:10 UTC
svn commit: r898319 - in
/incubator/chemistry/trunk/chemistry/chemistry-commons/src:
main/java/org/apache/chemistry/xml/stax/XMLWriter.java
test/java/org/apache/chemistry/xml/stax/TestXMLWriter.java
Author: sfermigier
Date: Tue Jan 12 13:41:10 2010
New Revision: 898319
URL: http://svn.apache.org/viewvc?rev=898319&view=rev
Log:
Fix nasty bug when a stream size is a multiple of 57. Add non-regression test.
Modified:
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/xml/stax/XMLWriter.java
incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/xml/stax/TestXMLWriter.java
Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/xml/stax/XMLWriter.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/xml/stax/XMLWriter.java?rev=898319&r1=898318&r2=898319&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/xml/stax/XMLWriter.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/xml/stax/XMLWriter.java Tue Jan 12 13:41:10 2010
@@ -246,7 +246,7 @@
char[] chars = new char[4 * 19];
while (true) {
int n = in.read(buf);
- if (n == 0) {
+ if (n == -1) {
break;
}
byte[] bytes;
Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/xml/stax/TestXMLWriter.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/xml/stax/TestXMLWriter.java?rev=898319&r1=898318&r2=898319&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/xml/stax/TestXMLWriter.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/xml/stax/TestXMLWriter.java Tue Jan 12 13:41:10 2010
@@ -24,6 +24,7 @@
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
+import java.util.Date;
import javax.xml.namespace.QName;
@@ -39,17 +40,6 @@
public static final QName OBJECT = new QName(CMIS.CMIS_NS, "object",
CMIS.CMIS_PREFIX);
- public static String toString(Reader r) throws IOException {
- char[] chars = new char[1000]; // big enough for this test
- int pos = 0;
- int n = 0;
- do {
- pos += n;
- n = r.read(chars, pos, chars.length - pos);
- } while (n > 0);
- return new String(chars, 0, pos);
- }
-
public void testXMLWriter() throws Exception {
Writer w = new StringWriter();
XMLWriter x = new XMLWriter(w, 2);
@@ -86,4 +76,36 @@
assertEquals(expected.trim(), actual.trim());
}
+
+ // Regression test: test corner case when stream length = 3*19.
+ public void testEncodeBase64CornerCase() throws Exception {
+ Writer w = new StringWriter();
+ XMLWriter x = new XMLWriter(w, 2);
+ String s = "abcdefghij" + "abcdefghij" + "abcdefghij" + "abcdefghij" + "abcdefghij" + "abcdefg";
+ assertEquals(3*19, s.length());
+
+ InputStream in = new ByteArrayInputStream(s.getBytes("UTF-8"));
+ x.start();
+ x.element("root").contentBase64(in);
+ x.end();
+ String actual = w.toString();
+ String expected = "YWJjZGVmZ2hpamFiY2RlZmdoaWphYmNkZWZnaGlqYWJjZGVmZ2hpamFiY2RlZmdoaWphYmNkZWZn";
+ }
+
+ public void testFormatDate() {
+ String s = XMLWriter.formatDate(new Date(0));
+ assertEquals("1970-01-01T00:00:00.000Z", s);
+ }
+
+ private static String toString(Reader r) throws IOException {
+ char[] chars = new char[1000]; // big enough for this test
+ int pos = 0;
+ int n = 0;
+ do {
+ pos += n;
+ n = r.read(chars, pos, chars.length - pos);
+ } while (n > 0);
+ return new String(chars, 0, pos);
+ }
+
}