1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.apache.xmlrpc.serializer; |
17 |
|
|
18 |
|
import java.io.IOException; |
19 |
|
|
20 |
|
import org.apache.ws.commons.util.Base64; |
21 |
|
import org.apache.ws.commons.util.Base64.Encoder; |
22 |
|
import org.xml.sax.ContentHandler; |
23 |
|
import org.xml.sax.SAXException; |
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
33 |
public class ByteArraySerializer extends TypeSerializerImpl { |
31 |
|
|
32 |
|
|
33 |
|
public static final String BASE_64_TAG = "base64"; |
34 |
|
public void write(final ContentHandler pHandler, Object pObject) throws SAXException { |
35 |
33 |
pHandler.startElement("", VALUE_TAG, VALUE_TAG, ZERO_ATTRIBUTES); |
36 |
33 |
pHandler.startElement("", BASE_64_TAG, BASE_64_TAG, ZERO_ATTRIBUTES); |
37 |
33 |
byte[] buffer = (byte[]) pObject; |
38 |
33 |
char[] charBuffer = new char[buffer.length >= 1024 ? 1024 : ((buffer.length+3)/4)*4]; |
39 |
33 |
Encoder encoder = new Base64.SAXEncoder(charBuffer, 0, null, pHandler); |
40 |
|
try { |
41 |
33 |
encoder.write(buffer, 0, buffer.length); |
42 |
33 |
encoder.flush(); |
43 |
0 |
} catch (Base64.SAXIOException e) { |
44 |
0 |
throw e.getSAXException(); |
45 |
0 |
} catch (IOException e) { |
46 |
0 |
throw new SAXException(e); |
47 |
|
} |
48 |
33 |
pHandler.endElement("", BASE_64_TAG, BASE_64_TAG); |
49 |
33 |
pHandler.endElement("", VALUE_TAG, VALUE_TAG); |
50 |
33 |
} |
51 |
|
} |