View Javadoc

1   /*
2    * Copyright 2006 the original author or authors.
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.springframework.ws.transport;
18  
19  import java.io.IOException;
20  import java.io.InputStream;
21  import java.util.Iterator;
22  
23  import org.springframework.util.Assert;
24  
25  /**
26   * A <code>TransportInputStream</code> is an input stream with MIME input headers. It is used to construct {@link
27   * org.springframework.ws.WebServiceMessage WebServiceMessages} from a transport.
28   *
29   * @author Arjen Poutsma
30   * @see #getHeaderNames()
31   * @see #getHeaders(String)
32   * @since 1.0.0
33   */
34  public abstract class TransportInputStream extends InputStream {
35  
36      private InputStream inputStream;
37  
38      protected TransportInputStream() {
39      }
40  
41      private InputStream getInputStream() throws IOException {
42          if (inputStream == null) {
43              inputStream = createInputStream();
44              Assert.notNull(inputStream, "inputStream must not be null");
45          }
46          return inputStream;
47      }
48  
49      public void close() throws IOException {
50          getInputStream().close();
51      }
52  
53      public int available() throws IOException {
54          return getInputStream().available();
55      }
56  
57      public synchronized void mark(int readlimit) {
58          try {
59              getInputStream().mark(readlimit);
60          }
61          catch (IOException e) {
62              // ignored
63          }
64      }
65  
66      public boolean markSupported() {
67          try {
68              return getInputStream().markSupported();
69          }
70          catch (IOException e) {
71              return false;
72          }
73      }
74  
75      public int read(byte b[]) throws IOException {
76          return getInputStream().read(b);
77      }
78  
79      public int read(byte b[], int off, int len) throws IOException {
80          return getInputStream().read(b, off, len);
81      }
82  
83      public synchronized void reset() throws IOException {
84          getInputStream().reset();
85      }
86  
87      public long skip(long n) throws IOException {
88          return getInputStream().skip(n);
89      }
90  
91      public int read() throws IOException {
92          return getInputStream().read();
93      }
94  
95      /** Returns the input stream to read from. */
96      protected abstract InputStream createInputStream() throws IOException;
97  
98      /**
99       * Returns an iteration over all the header names this stream contains. Returns an empty <code>Iterator</code> if
100      * there are no headers.
101      */
102     public abstract Iterator getHeaderNames() throws IOException;
103 
104     /**
105      * Returns an iteration over all the string values of the specified header. Returns an empty <code>Iterator</code>
106      * if there are no headers of the specified name.
107      */
108     public abstract Iterator getHeaders(String name) throws IOException;
109 }