01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.OutputStream;
21:
22: import org.springframework.util.Assert;
23:
24: /**
25: * A <code>TransportOutputStream</code> is an output stream with MIME input headers. It is used to write {@link
26: * org.springframework.ws.WebServiceMessage WebServiceMessages} to a transport.
27: *
28: * @author Arjen Poutsma
29: * @see #addHeader(String,String)
30: * @since 1.0.0
31: */
32: public abstract class TransportOutputStream extends OutputStream {
33:
34: private OutputStream outputStream;
35:
36: protected TransportOutputStream() {
37: }
38:
39: private OutputStream getOutputStream() throws IOException {
40: if (outputStream == null) {
41: outputStream = createOutputStream();
42: Assert.notNull(outputStream,
43: "outputStream must not be null");
44: }
45: return outputStream;
46: }
47:
48: public void close() throws IOException {
49: getOutputStream().close();
50: }
51:
52: public void flush() throws IOException {
53: getOutputStream().flush();
54: }
55:
56: public void write(byte b[]) throws IOException {
57: getOutputStream().write(b);
58: }
59:
60: public void write(byte b[], int off, int len) throws IOException {
61: getOutputStream().write(b, off, len);
62: }
63:
64: public void write(int b) throws IOException {
65: getOutputStream().write(b);
66: }
67:
68: /**
69: * Adds a header with the given name and value. This method can be called multiple times, to allow for headers with
70: * multiple values.
71: *
72: * @param name the name of the header
73: * @param value the value of the header
74: */
75: public abstract void addHeader(String name, String value)
76: throws IOException;
77:
78: /** Returns the output stream to write to. */
79: protected abstract OutputStream createOutputStream()
80: throws IOException;
81: }
|