KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > message > InputStreamBody


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.message;
18
19 import org.apache.axis.components.logger.LogFactory;
20 import org.apache.axis.encoding.SerializationContext;
21 import org.apache.axis.utils.IOUtils;
22 import org.apache.axis.utils.Messages;
23 import org.apache.commons.logging.Log;
24
25 import java.io.IOException JavaDoc;
26 import java.io.InputStream JavaDoc;
27
28
29 public class InputStreamBody extends SOAPBodyElement
30 {
31     protected static Log log =
32         LogFactory.getLog(InputStreamBody.class.getName());
33
34     protected InputStream JavaDoc inputStream;
35     
36     public InputStreamBody(InputStream JavaDoc inputStream)
37     {
38         this.inputStream = inputStream;
39     }
40     
41     public void outputImpl(SerializationContext context) throws IOException JavaDoc
42     {
43         try {
44             byte[] buf = new byte[ inputStream.available() ];
45             IOUtils.readFully(inputStream,buf);
46             String JavaDoc contents = new String JavaDoc(buf);
47             context.writeString(contents);
48         }
49         catch( IOException JavaDoc ex ) {
50             throw ex;
51         }
52         catch( Exception JavaDoc e ) {
53             log.error(Messages.getMessage("exception00"), e);
54         }
55     }
56 }
57
Popular Tags