KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ext > benchsocket > BenchInputStream


1 package org.objectweb.proactive.ext.benchsocket;
2
3 import java.io.IOException JavaDoc;
4 import java.io.InputStream JavaDoc;
5
6
7 /**
8  * @author fabrice
9  *
10  * To change the template for this generated type comment go to
11  * Window - Preferences - Java - Code Generation - Code and Comments
12  */

13 public class BenchInputStream extends InputStream JavaDoc implements BenchStream {
14     private InputStream JavaDoc realInputStream;
15     private int number;
16     private int total;
17
18     public BenchInputStream(InputStream JavaDoc real, int number) {
19         this.realInputStream = real;
20         this.number = number;
21         //we register a hook to be run
22
//when the JVM is killed
23
Runtime.getRuntime().addShutdownHook(new ShutdownThread(this));
24     }
25
26     public void displayTotal() {
27         System.out.println("=== Total Input for socket " + number + " = " +
28             total);
29     }
30
31     /* (non-Javadoc)
32      * @see java.io.InputStream#available()
33      */

34     public int available() throws IOException JavaDoc {
35         return this.realInputStream.available();
36     }
37
38     /* (non-Javadoc)
39      * @see java.io.InputStream#close()
40      */

41     public void close() throws IOException JavaDoc {
42         this.realInputStream.close();
43     }
44
45     /* (non-Javadoc)
46      * @see java.io.InputStream#mark(int)
47      */

48     public synchronized void mark(int readlimit) {
49         this.realInputStream.mark(readlimit);
50     }
51
52     /* (non-Javadoc)
53      * @see java.io.InputStream#markSupported()
54      */

55     public boolean markSupported() {
56         return this.realInputStream.markSupported();
57     }
58
59     public int read() throws IOException JavaDoc {
60         int tmp = this.realInputStream.read();
61         if (BenchSocketFactory.measure) {
62             total += tmp;
63         }
64         total += tmp;
65         return tmp;
66     }
67
68     /* (non-Javadoc)
69      * @see java.io.InputStream#read(byte[], int, int)
70      */

71     public int read(byte[] b, int off, int len) throws IOException JavaDoc {
72         int tmp = this.realInputStream.read(b, off, len);
73         if (BenchSocketFactory.measure) {
74             total += tmp;
75         }
76         return tmp;
77     }
78
79     /* (non-Javadoc)
80      * @see java.io.InputStream#read(byte[])
81      */

82     public int read(byte[] b) throws IOException JavaDoc {
83         int tmp = this.realInputStream.read(b);
84         if (BenchSocketFactory.measure) {
85             total += tmp;
86         }
87         return tmp;
88     }
89
90     /* (non-Javadoc)
91      * @see java.io.InputStream#reset()
92      */

93     public synchronized void reset() throws IOException JavaDoc {
94         this.realInputStream.reset();
95     }
96
97     /* (non-Javadoc)
98      * @see java.io.InputStream#skip(long)
99      */

100     public long skip(long n) throws IOException JavaDoc {
101         return this.realInputStream.skip(n);
102     }
103 }
104
Popular Tags