KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > server > httpPresentation > servlet > ServletHttpPresentationInputStream


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  * $Id: ServletHttpPresentationInputStream.java,v 1.2 2005/03/24 10:51:16 slobodan Exp $
23  */

24
25
26
27
28
29 package com.lutris.appserver.server.httpPresentation.servlet;
30
31 import java.io.IOException JavaDoc;
32
33 import javax.servlet.ServletInputStream JavaDoc;
34
35 import com.lutris.appserver.server.httpPresentation.HttpPresentationIOException;
36 import com.lutris.appserver.server.httpPresentation.HttpPresentationInputStream;
37
38 /**
39  * HTTP request input stream reader for servlets.
40  * This implements all methods that are defined in InputStream as calles
41  * to the servlet object, since we don't know which ones are implemented by
42  * ServletInputStream.
43  *
44  * @see javax.servlet.ServletInputStream
45  */

46 public class ServletHttpPresentationInputStream
47     extends HttpPresentationInputStream {
48     private ServletInputStream JavaDoc inputStream;
49
50     /**
51      * Construct an object for accessing a servlet input stream.
52      */

53     protected ServletHttpPresentationInputStream(ServletInputStream JavaDoc inputStream) {
54         this.inputStream = inputStream;
55     }
56
57     /**
58      * Starting at the specified offset, reads into the given array of
59      * bytes until all requested bytes have been read or a '\n' is
60      * encountered, in which case the '\n' is read into the array as well.
61      * @param b the buffer into which the data is read
62      * @param off the start offset of the data
63      * @param len the maximum number of bytes to read
64      * @return the actual number of bytes read, or -1 if the end of the
65      * stream is reached
66      * @exception IOException if an I/O error has occurred
67      */

68     public int readLine(byte[] b, int off, int len)
69         throws IOException JavaDoc {
70         try {
71             return inputStream.readLine(b, off, len);
72         } catch (IOException JavaDoc except) {
73             throw new HttpPresentationIOException(except);
74         }
75     }
76
77     /*
78      * InputStream methods vectored off to the ServletInputStream.
79      */

80     public int read() throws IOException JavaDoc {
81         try {
82             return inputStream.read();
83         } catch (IOException JavaDoc except) {
84             throw new HttpPresentationIOException(except);
85         }
86     }
87
88     public int read(byte b[]) throws IOException JavaDoc {
89         try {
90             return inputStream.read(b);
91         } catch (IOException JavaDoc except) {
92             throw new HttpPresentationIOException(except);
93         }
94     }
95
96     public int read(byte b[], int off, int len) throws IOException JavaDoc {
97         try {
98             return inputStream.read(b, off, len);
99         } catch (IOException JavaDoc except) {
100             throw new HttpPresentationIOException(except);
101         }
102     }
103
104     public long skip(long n) throws IOException JavaDoc {
105         try {
106             return inputStream.skip(n);
107         } catch (IOException JavaDoc except) {
108             throw new HttpPresentationIOException(except);
109         }
110     }
111
112     public int available() throws IOException JavaDoc {
113         try {
114             return inputStream.available();
115         } catch (IOException JavaDoc except) {
116             throw new HttpPresentationIOException(except);
117         }
118     }
119
120     public synchronized void mark(int readlimit) {
121         inputStream.mark(readlimit);
122     }
123
124     public synchronized void reset() throws IOException JavaDoc {
125         try {
126             inputStream.reset();
127         } catch (IOException JavaDoc except) {
128             throw new HttpPresentationIOException(except);
129         }
130     }
131
132     public boolean markSupported() {
133         return inputStream.markSupported();
134     }
135 }
136
Popular Tags