001: /*
002: * Copyright 2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.ws.transport;
018:
019: import java.io.IOException;
020: import java.io.InputStream;
021: import java.util.Iterator;
022:
023: import org.springframework.util.Assert;
024:
025: /**
026: * A <code>TransportInputStream</code> is an input stream with MIME input headers. It is used to construct {@link
027: * org.springframework.ws.WebServiceMessage WebServiceMessages} from a transport.
028: *
029: * @author Arjen Poutsma
030: * @see #getHeaderNames()
031: * @see #getHeaders(String)
032: * @since 1.0.0
033: */
034: public abstract class TransportInputStream extends InputStream {
035:
036: private InputStream inputStream;
037:
038: protected TransportInputStream() {
039: }
040:
041: private InputStream getInputStream() throws IOException {
042: if (inputStream == null) {
043: inputStream = createInputStream();
044: Assert.notNull(inputStream, "inputStream must not be null");
045: }
046: return inputStream;
047: }
048:
049: public void close() throws IOException {
050: getInputStream().close();
051: }
052:
053: public int available() throws IOException {
054: return getInputStream().available();
055: }
056:
057: public synchronized void mark(int readlimit) {
058: try {
059: getInputStream().mark(readlimit);
060: } catch (IOException e) {
061: // ignored
062: }
063: }
064:
065: public boolean markSupported() {
066: try {
067: return getInputStream().markSupported();
068: } catch (IOException e) {
069: return false;
070: }
071: }
072:
073: public int read(byte b[]) throws IOException {
074: return getInputStream().read(b);
075: }
076:
077: public int read(byte b[], int off, int len) throws IOException {
078: return getInputStream().read(b, off, len);
079: }
080:
081: public synchronized void reset() throws IOException {
082: getInputStream().reset();
083: }
084:
085: public long skip(long n) throws IOException {
086: return getInputStream().skip(n);
087: }
088:
089: public int read() throws IOException {
090: return getInputStream().read();
091: }
092:
093: /** Returns the input stream to read from. */
094: protected abstract InputStream createInputStream()
095: throws IOException;
096:
097: /**
098: * Returns an iteration over all the header names this stream contains. Returns an empty <code>Iterator</code> if
099: * there are no headers.
100: */
101: public abstract Iterator getHeaderNames() throws IOException;
102:
103: /**
104: * Returns an iteration over all the string values of the specified header. Returns an empty <code>Iterator</code>
105: * if there are no headers of the specified name.
106: */
107: public abstract Iterator getHeaders(String name) throws IOException;
108: }
|