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