Coverage Report - org.apache.xmlrpc.serializer.ByteArraySerializer
 
Classes in this File Line Coverage Branch Coverage Complexity
ByteArraySerializer
73% 
100% 
5
 
 1  
 /*
 2  
  * Copyright 1999,2005 The Apache Software Foundation.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
 /** A {@link TypeSerializer} for byte arrays.
 29  
  */
 30  33
 public class ByteArraySerializer extends TypeSerializerImpl {
 31  
         /** Tag name of a base64 value.
 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  
 }