001 /* 002 * Copyright 1999,2004 The Apache Software Foundation. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package org.apache.commons.feedparser.network; 018 019 import java.io.IOException; 020 import java.io.InputStream; 021 022 /** 023 * 024 * 025 * @author <a href="mailto:burton@openprivacy.org">Kevin A. Burton</a> 026 * @version $Id: AdvancedInputStream.java 373622 2006-01-30 22:53:00Z mvdb $ 027 */ 028 public class AdvancedInputStream extends InputStream { 029 030 private InputStream is = null; 031 032 private BaseResourceRequest request = null; 033 034 /** 035 * 036 * Create a new <code>AdvancedInputStream</code> instance. 037 * 038 * 039 */ 040 public AdvancedInputStream( InputStream is, ResourceRequest request ) { 041 this.is = is; 042 this.request = (BaseResourceRequest)request; 043 } 044 045 public int read() throws IOException { 046 047 int v = is.read(); 048 049 request.fireDataEvent( 1 ); //one byte is read 050 051 return v; 052 } 053 054 public int read( byte b[] ) throws IOException { 055 056 int v = is.read( b ); 057 058 request.fireDataEvent( b.length ); 059 060 return v; 061 062 } 063 064 public int read( byte b[], int off, int len ) throws IOException { 065 066 int v = is.read( b, off, len ); 067 068 request.fireDataEvent( len ); 069 070 return v; 071 072 } 073 074 public long skip( long n ) throws IOException { 075 076 long v = is.skip( n ); 077 078 request.fireDataEvent( n ); 079 080 return v; 081 } 082 083 //non-read related 084 085 public int available() throws IOException { 086 return is.available(); 087 } 088 089 public void close() throws IOException { 090 is.close(); 091 092 request.fireOnClosed(); 093 } 094 095 public void mark(int readlimit) { 096 is.mark( readlimit ); 097 } 098 099 public void reset() throws IOException { 100 is.reset(); 101 } 102 103 public boolean markSupported() { 104 return is.markSupported(); 105 } 106 107 }