View Javadoc

1   /*
2    * $Id: PortletServletInputStream.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.InputStream;
26  
27  import javax.servlet.ServletInputStream;
28  
29  /***
30   * Wrapper object exposing a {@link InputStream} from a portlet as a {@link ServletInputStream} instance.
31   * Clients accessing this stream object will in fact operate on the
32   * {@link InputStream} object wrapped by this stream object.
33   */
34  public class PortletServletInputStream extends ServletInputStream {
35  
36  	private InputStream portletInputStream;
37  	
38  	public PortletServletInputStream(InputStream portletInputStream) {
39  		this.portletInputStream = portletInputStream;
40  	}
41  	
42  	/* (non-Javadoc)
43  	 * @see java.io.InputStream#read()
44  	 */
45  	@Override
46  	public int read() throws IOException {
47  		return portletInputStream.read();
48  	}
49  
50  	/* (non-Javadoc)
51  	 * @see java.io.InputStream#available()
52  	 */
53  	@Override
54  	public int available() throws IOException {
55  		return portletInputStream.available();
56  	}
57  
58  	/* (non-Javadoc)
59  	 * @see java.io.InputStream#close()
60  	 */
61  	@Override
62  	public void close() throws IOException {
63  		portletInputStream.close();
64  	}
65  
66  	/* (non-Javadoc)
67  	 * @see java.io.InputStream#mark(int)
68  	 */
69  	@Override
70  	public synchronized void mark(int readlimit) {
71  		portletInputStream.mark(readlimit);
72  	}
73  
74  	/* (non-Javadoc)
75  	 * @see java.io.InputStream#markSupported()
76  	 */
77  	@Override
78  	public boolean markSupported() {
79  		return portletInputStream.markSupported();
80  	}
81  
82  	/* (non-Javadoc)
83  	 * @see java.io.InputStream#read(byte[], int, int)
84  	 */
85  	@Override
86  	public int read(byte[] b, int off, int len) throws IOException {
87  		return portletInputStream.read(b, off, len);
88  	}
89  
90  	/* (non-Javadoc)
91  	 * @see java.io.InputStream#read(byte[])
92  	 */
93  	@Override
94  	public int read(byte[] b) throws IOException {
95  		return portletInputStream.read(b);
96  	}
97  
98  	/* (non-Javadoc)
99  	 * @see java.io.InputStream#reset()
100 	 */
101 	@Override
102 	public synchronized void reset() throws IOException {
103 		portletInputStream.reset();
104 	}
105 
106 	/* (non-Javadoc)
107 	 * @see java.io.InputStream#skip(long)
108 	 */
109 	@Override
110 	public long skip(long n) throws IOException {
111 		return portletInputStream.skip(n);
112 	}
113 	
114 	/***
115 	 * Get the wrapped {@link InputStream} instance.
116 	 * @return The wrapped {@link InputStream} instance.
117 	 */
118 	public InputStream getInputStream() {
119 		return portletInputStream;
120 	}
121 
122 }