View Javadoc

1   /*
2    * $Id: $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.struts2.portlet.servlet;
22  
23  import java.io.IOException;
24  import java.io.OutputStream;
25  
26  import javax.servlet.ServletOutputStream;
27  
28  /***
29   * Wrapper object exposing a {@link OutputStream} from a portlet as a {@link ServletOutputStream} instance.
30   * Clients accessing this stream object will in fact operate on the
31   * {@link OutputStream} object wrapped by this stream object.
32   */
33  public class PortletServletOutputStream extends ServletOutputStream {
34  
35  	private OutputStream portletOutputStream;
36  	
37  	public PortletServletOutputStream(OutputStream portletOutputStream) {
38  		this.portletOutputStream = portletOutputStream;
39  	}
40  
41  	/* (non-Javadoc)
42  	 * @see java.io.OutputStream#write(int)
43  	 */
44  	@Override
45  	public void write(int ch) throws IOException {
46  		portletOutputStream.write(ch);
47  	}
48  
49  	/* (non-Javadoc)
50  	 * @see java.io.OutputStream#close()
51  	 */
52  	@Override
53  	public void close() throws IOException {
54  		portletOutputStream.close();
55  	}
56  
57  	/* (non-Javadoc)
58  	 * @see java.io.OutputStream#flush()
59  	 */
60  	@Override
61  	public void flush() throws IOException {
62  		portletOutputStream.flush();
63  	}
64  
65  	/* (non-Javadoc)
66  	 * @see java.io.OutputStream#write(byte[])
67  	 */
68  	@Override
69  	public void write(byte[] b) throws IOException {
70  		portletOutputStream.write(b);
71  	}
72  
73  	/* (non-Javadoc)
74  	 * @see java.io.OutputStream#write(byte[], int, int)
75  	 */
76  	@Override
77  	public void write(byte[] b, int off, int len) throws IOException {
78  		portletOutputStream.write(b, off, len);
79  	}
80  	
81  	/***
82  	 * Get the wrapped {@link OutputStream} instance.
83  	 * @return The wrapped {@link OutputStream} instance.
84  	 */
85  	public OutputStream getOutputStream() {
86  		return portletOutputStream;
87  	}
88  }