1 42 43 package org.jfree.xml.parser; 44 45 import java.io.ByteArrayInputStream ; 46 import java.io.IOException ; 47 import java.io.ObjectInputStream ; 48 49 import org.jfree.xml.util.Base64; 50 import org.xml.sax.SAXException ; 51 52 57 public class Base64ReadHandler extends AbstractXmlReadHandler { 58 59 60 private String encodedObject; 61 62 65 public Base64ReadHandler() { 66 super(); 67 } 68 69 78 public void characters(final char[] ch, final int start, final int length) 79 throws SAXException { 80 this.encodedObject = new String (ch, start, length); 81 } 82 83 90 public Object getObject() throws XmlReaderException { 91 try { 92 final byte[] bytes = Base64.decode(this.encodedObject.toCharArray()); 93 final ObjectInputStream in = 94 new ObjectInputStream (new ByteArrayInputStream (bytes)); 95 return in.readObject(); 96 } 97 catch (IOException e) { 98 throw new XmlReaderException("Can't read class for <" + getTagName() + ">", e); 99 } 100 catch (ClassNotFoundException e) { 101 throw new XmlReaderException("Class not found for <" + getTagName() + ">", e); 102 } 103 } 104 } 105 | Popular Tags |