scheu 02/02/04 14:34:53
Modified: java/src/org/apache/axis/encoding/ser
Base64Deserializer.java
Log:
The following code was requested by Paul Mietz Egli.
SAX can break up values into 5k chunks. The
base64Deserializer is changed to collect all the data
before decoding.
Revision Changes Path
1.3 +22 -8
xml-axis/java/src/org/apache/axis/encoding/ser/Base64Deserializer.java
Index: Base64Deserializer.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/Base64Deserializer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Base64Deserializer.java 31 Jan 2002 03:26:09 -0000 1.2
+++ Base64Deserializer.java 4 Feb 2002 22:34:53 -0000 1.3
@@ -81,6 +81,9 @@
public QName xmlType;
public Class javaType;
+
+ StringBuffer buf = null;
+
public Base64Deserializer(Class javaType, QName xmlType) {
this.xmlType = xmlType;
this.javaType = javaType;
@@ -92,15 +95,12 @@
public void characters(char [] chars, int start, int end)
throws SAXException
{
- value = Base64.decode(chars, start, end);
- if (javaType == Byte[].class) {
- Byte[] data = new Byte[ ((byte[])value).length ];
- for (int i=0; i<data.length; i++) {
- byte b = ((byte[]) value)[i];
- data[i] = new Byte(b);
- }
- value = data;
+ // Characters are collected in a buffer because
+ // SAX may chunk the data.
+ if (buf == null) {
+ buf = new StringBuffer();
}
+ buf.append(chars, start, end);
}
/**
@@ -110,7 +110,21 @@
DeserializationContext context)
throws SAXException
{
+ // Decode the collected characters
+ if (buf != null) {
+ value = Base64.decode(buf.toString());
+ if (javaType == Byte[].class) {
+ Byte[] data = new Byte[ ((byte[])value).length ];
+ for (int i=0; i<data.length; i++) {
+ byte b = ((byte[]) value)[i];
+ data[i] = new Byte(b);
+ }
+ value = data;
+ }
+ }
+
super.onEndElement(namespace,localName, context);
+ // If no value was specified, return a zero length byte or Byte array
if (value == null) {
if (javaType == byte[].class) {
value = new byte[0];