Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 package org.apache.xmlrpc.serializer;
00020
00021 import java.io.IOException;
00022
00023 import org.apache.ws.commons.util.Base64;
00024 import org.apache.ws.commons.util.Base64.Encoder;
00025 import org.xml.sax.ContentHandler;
00026 import org.xml.sax.SAXException;
00027
00028
00029
00030
00033 public class ByteArraySerializer extends TypeSerializerImpl {
00036 public static final String BASE_64_TAG = "base64";
00037 public void write(final ContentHandler pHandler, Object pObject) throws SAXException {
00038 pHandler.startElement("", VALUE_TAG, VALUE_TAG, ZERO_ATTRIBUTES);
00039 pHandler.startElement("", BASE_64_TAG, BASE_64_TAG, ZERO_ATTRIBUTES);
00040 byte[] buffer = (byte[]) pObject;
00041 if (buffer.length > 0) {
00042 char[] charBuffer = new char[buffer.length >= 1024 ? 1024 : ((buffer.length+3)/4)*4];
00043 Encoder encoder = new Base64.SAXEncoder(charBuffer, 0, null, pHandler);
00044 try {
00045 encoder.write(buffer, 0, buffer.length);
00046 encoder.flush();
00047 } catch (Base64.SAXIOException e) {
00048 throw e.getSAXException();
00049 } catch (IOException e) {
00050 throw new SAXException(e);
00051 }
00052 }
00053 pHandler.endElement("", BASE_64_TAG, BASE_64_TAG);
00054 pHandler.endElement("", VALUE_TAG, VALUE_TAG);
00055 }
00056 }