View Javadoc

1   /*
2    * Copyright 1999,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.commons.feedparser.network;
18  
19  import java.io.IOException;
20  import java.io.InputStream;
21  
22  /**
23   * 
24   *
25   * @author <a href="mailto:burton@openprivacy.org">Kevin A. Burton</a>
26   * @version $Id: AdvancedInputStream.java 373622 2006-01-30 22:53:00Z mvdb $
27   */
28  public class AdvancedInputStream extends InputStream {
29  
30      private InputStream is = null;
31  
32      private BaseResourceRequest request = null;
33  
34      /**
35       * 
36       * Create a new <code>AdvancedInputStream</code> instance.
37       *
38       * 
39       */
40      public AdvancedInputStream( InputStream is, ResourceRequest request ) {
41          this.is = is;
42          this.request = (BaseResourceRequest)request;
43      }
44  
45      public int read() throws IOException {
46  
47          int v = is.read();
48  
49          request.fireDataEvent( 1 ); //one byte is read
50  
51          return v;
52      }
53  
54      public int read( byte b[] ) throws IOException {
55  
56          int v = is.read( b );
57          
58          request.fireDataEvent( b.length );
59  
60          return v;
61  
62      }
63  
64      public int read( byte b[], int off, int len ) throws IOException {
65  
66          int v = is.read( b, off, len ); 
67  
68          request.fireDataEvent( len );
69  
70          return v;
71  
72      }
73  
74      public long skip( long n ) throws IOException {
75  
76          long v = is.skip( n );
77  
78          request.fireDataEvent( n );
79  
80          return v;
81      }
82  
83      //non-read related
84      
85      public int available() throws IOException {
86          return is.available();
87      }
88  
89      public void close() throws IOException {
90          is.close();
91  
92          request.fireOnClosed();
93      }
94  
95      public void mark(int readlimit) {
96          is.mark( readlimit );
97      }
98  
99      public void reset() throws IOException {
100         is.reset();
101     }
102 
103     public boolean markSupported() {
104         return is.markSupported();
105     }
106 
107 }