01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.io;
19:
20: import java.io.IOException;
21: import java.io.OutputStream;
22:
23: /**
24: * This outputstream implementation will both write to the outputstream
25: * that is specified and cache the data at the same time. This allows us
26: * to go back and retransmit the data at a later time if necessary.
27: *
28: */
29: public class CacheAndWriteOutputStream extends CachedOutputStream {
30:
31: OutputStream flowThroughStream;
32:
33: public CacheAndWriteOutputStream(OutputStream stream) {
34: super ();
35: flowThroughStream = stream;
36: }
37:
38: @Override
39: protected void doClose() throws IOException {
40: flowThroughStream.flush();
41: flowThroughStream.close();
42: }
43:
44: @Override
45: protected void onWrite() throws IOException {
46: // does nothing
47: }
48:
49: @Override
50: public void write(int b) throws IOException {
51: flowThroughStream.write(b);
52: super .write(b);
53: }
54:
55: @Override
56: public void write(byte[] b, int off, int len) throws IOException {
57: flowThroughStream.write(b, off, len);
58: super .write(b, off, len);
59: }
60:
61: @Override
62: public void write(byte[] b) throws IOException {
63: flowThroughStream.write(b);
64: super.write(b);
65: }
66: }
|