KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > encoding > ser > OctetStreamDataHandlerDeserializer


1 /*
2  * Copyright 2001-2004 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
17 package org.apache.axis.encoding.ser;
18
19 import org.apache.axis.components.logger.LogFactory;
20 import org.apache.axis.encoding.DeserializationContext;
21 import org.apache.axis.attachments.OctetStream;
22 import org.apache.commons.logging.Log;
23 import org.xml.sax.Attributes JavaDoc;
24 import org.xml.sax.SAXException JavaDoc;
25
26 import javax.activation.DataHandler JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.io.InputStream JavaDoc;
29 import java.io.ByteArrayOutputStream JavaDoc;
30
31 /**
32  * application/octet-stream DataHandler Deserializer
33  * Modified by Davanum Srinivas <dims@yahoo.com>
34  */

35 public class OctetStreamDataHandlerDeserializer extends JAFDataHandlerDeserializer {
36     protected static Log log =
37             LogFactory.getLog(OctetStreamDataHandlerDeserializer.class.getName());
38
39     public void startElement(String JavaDoc namespace, String JavaDoc localName,
40                              String JavaDoc prefix, Attributes JavaDoc attributes,
41                              DeserializationContext context)
42             throws SAXException JavaDoc {
43
44         super.startElement(namespace, localName, prefix, attributes, context);
45
46         if (getValue() instanceof DataHandler JavaDoc) {
47             try {
48                 DataHandler JavaDoc dh = (DataHandler JavaDoc) getValue();
49                 InputStream JavaDoc in = dh.getInputStream();
50                 ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
51                 int byte1 = -1;
52                 while((byte1 = in.read())!=-1)
53                     baos.write(byte1);
54                 OctetStream os = new OctetStream(baos.toByteArray());
55                 setValue(os);
56             } catch (IOException JavaDoc ioe) {
57             }
58         }
59     } // startElement
60
} // class OctetStreamDataHandlerDeserializer
61
Popular Tags