View Javadoc

1   /*
2    * $Id: PortletServletOutputStream.java 651946 2008-04-27 13:41:38Z apetrelli $
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  
22  package org.apache.struts2.portlet.servlet;
23  
24  import java.io.IOException;
25  import java.io.OutputStream;
26  
27  import javax.servlet.ServletOutputStream;
28  
29  /***
30   * Wrapper object exposing a {@link OutputStream} from a portlet as a {@link ServletOutputStream} instance.
31   * Clients accessing this stream object will in fact operate on the
32   * {@link OutputStream} object wrapped by this stream object.
33   */
34  public class PortletServletOutputStream extends ServletOutputStream {
35  
36  	private OutputStream portletOutputStream;
37  	
38  	public PortletServletOutputStream(OutputStream portletOutputStream) {
39  		this.portletOutputStream = portletOutputStream;
40  	}
41  
42  	/* (non-Javadoc)
43  	 * @see java.io.OutputStream#write(int)
44  	 */
45  	@Override
46  	public void write(int ch) throws IOException {
47  		portletOutputStream.write(ch);
48  	}
49  
50  	/* (non-Javadoc)
51  	 * @see java.io.OutputStream#close()
52  	 */
53  	@Override
54  	public void close() throws IOException {
55  		portletOutputStream.close();
56  	}
57  
58  	/* (non-Javadoc)
59  	 * @see java.io.OutputStream#flush()
60  	 */
61  	@Override
62  	public void flush() throws IOException {
63  		portletOutputStream.flush();
64  	}
65  
66  	/* (non-Javadoc)
67  	 * @see java.io.OutputStream#write(byte[])
68  	 */
69  	@Override
70  	public void write(byte[] b) throws IOException {
71  		portletOutputStream.write(b);
72  	}
73  
74  	/* (non-Javadoc)
75  	 * @see java.io.OutputStream#write(byte[], int, int)
76  	 */
77  	@Override
78  	public void write(byte[] b, int off, int len) throws IOException {
79  		portletOutputStream.write(b, off, len);
80  	}
81  	
82  	/***
83  	 * Get the wrapped {@link OutputStream} instance.
84  	 * @return The wrapped {@link OutputStream} instance.
85  	 */
86  	public OutputStream getOutputStream() {
87  		return portletOutputStream;
88  	}
89  }