KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > webdav > logger > XServletInputStreamFacade


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/logger/XServletInputStreamFacade.java,v 1.7 2004/08/05 14:43:34 dflorey Exp $
3  * $Revision: 1.7 $
4  * $Date: 2004/08/05 14:43:34 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24
25 package org.apache.slide.webdav.logger;
26
27 import java.io.IOException JavaDoc;
28
29 import javax.servlet.ServletInputStream JavaDoc;
30
31 import org.apache.slide.common.Domain;
32
33 /**
34  * This class is to buffer an ServletInputStream.
35  *
36  */

37 public class XServletInputStreamFacade extends ServletInputStream JavaDoc {
38     private ServletInputStream JavaDoc in;
39     private XByteBuffer byteBuf;
40
41     public XServletInputStreamFacade( ServletInputStream JavaDoc in ) {
42         if ( Domain.isInitialized()) Domain.debug("Create XServletInputStreamFacade");
43         this.in = in;
44         byteBuf = new XByteBuffer();
45     }
46
47
48
49     public int read() throws IOException JavaDoc {
50         if ( Domain.isInitialized())Domain.debug("ENTER: XServletInputStreamFacade:read()");
51         int result = in.read();
52         byteBuf.write(result);
53         if ( Domain.isInitialized())Domain.debug("LEAVE: XServletInputStreamFacade:read() result = " + result );
54         return result;
55     }
56
57     public int read(byte[] b) throws IOException JavaDoc {
58         if ( Domain.isInitialized()) Domain.debug("ENTER: XServletInputStreamFacade:read(byte[] b)");
59         int result = in.read(b);
60         byteBuf.write( b, 0, result );
61         if ( Domain.isInitialized()) Domain.debug("LEAVE: XServletInputStreamFacade:read(byte[] b) result = " + result );
62         return result;
63     }
64
65     public int read(byte[] b, int off, int len) throws IOException JavaDoc {
66         if ( Domain.isInitialized()) Domain.debug("ENTER: XServletInputStreamFacade:read(byte[] b, off="+off+" len="+len+" )");
67         int result = in.read(b, off, len);
68         byteBuf.write( b, off, result );
69         if ( Domain.isInitialized()) Domain.debug("LEAVE: XServletInputStreamFacade:read(byte[] b, off="+off+" len="+len+" ) result = " + result );
70         return result;
71     }
72
73     /**
74      * See the general contract of the <code>skip</code>
75      * method of <code>InputStream</code>.
76      *
77      * @param n the number of bytes to be skipped.
78      * @return the actual number of bytes skipped.
79      * @exception IOException if an I/O error occurs.
80      */

81     public long skip(long n) throws IOException JavaDoc {
82         return in.skip(n);
83     }
84
85     /**
86      * Returns the number of bytes that can be read from this input
87      * stream without blocking.
88      * <p>
89      * The <code>available</code> method of
90      * <code>BufferedInputStream</code> returns the sum of the the number
91      * of bytes remaining to be read in the buffer
92      * (<code>count&nbsp;- pos</code>)
93      * and the result of calling the <code>available</code> method of the
94      * underlying input stream.
95      *
96      * @return the number of bytes that can be read from this input
97      * stream without blocking.
98      * @exception IOException if an I/O error occurs.
99      * @see java.io.FilterInputStream#in
100      */

101     public synchronized int available() throws IOException JavaDoc {
102         return in.available();
103     }
104
105     /**
106      * See the general contract of the <code>mark</code>
107      * method of <code>InputStream</code>.
108      *
109      * @param readlimit the maximum limit of bytes that can be read before
110      * the mark position becomes invalid.
111      * @see java.io.BufferedInputStream#reset()
112      */

113     public synchronized void mark(int readlimit) {
114         in.mark(readlimit);
115     }
116
117     /**
118      * See the general contract of the <code>reset</code>
119      * method of <code>InputStream</code>.
120      * <p>
121      * If <code>markpos</code> is <code>-1</code>
122      * (no mark has been set or the mark has been
123      * invalidated), an <code>IOException</code>
124      * is thrown. Otherwise, <code>pos</code> is
125      * set equal to <code>markpos</code>.
126      *
127      * @exception IOException if this stream has not been marked or
128      * if the mark has been invalidated.
129      * @see java.io.BufferedInputStream#mark(int)
130      */

131     public synchronized void reset() throws IOException JavaDoc {
132         in.reset();
133     }
134
135     /**
136      * Tests if this input stream supports the <code>mark</code>
137      * and <code>reset</code> methods. The <code>markSupported</code>
138      * method of <code>BufferedInputStream</code> returns
139      * <code>true</code>.
140      *
141      * @return a <code>boolean</code> indicating if this stream type supports
142      * the <code>mark</code> and <code>reset</code> methods.
143      * @see java.io.InputStream#mark(int)
144      * @see java.io.InputStream#reset()
145      */

146     public boolean markSupported() {
147         return in.markSupported();
148     }
149
150     /**
151      * Closes this input stream and releases any system resources
152      * associated with the stream.
153      *
154      * @exception IOException if an I/O error occurs.
155      */

156     public void close() throws IOException JavaDoc {
157         in.close();
158     }
159
160     /**
161      * Get content of the read input stream saved in the buffer.
162      **/

163     public String JavaDoc getBufferContent() {
164         return byteBuf.getBufferContent();
165     }
166
167     /**
168      * Get number of bytes read from the input stream saved in the buffer.
169      **/

170     public int getNumberOfBytesWritten() {
171         return byteBuf.getNumberOfBytesWritten();
172     }
173
174 }
175
Popular Tags