1 package org.objectweb.proactive.ext.benchsocket; 2 3 import java.io.IOException ; 4 import java.io.InputStream ; 5 6 7 13 public class BenchInputStream extends InputStream implements BenchStream { 14 private InputStream realInputStream; 15 private int number; 16 private int total; 17 18 public BenchInputStream(InputStream real, int number) { 19 this.realInputStream = real; 20 this.number = number; 21 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 34 public int available() throws IOException { 35 return this.realInputStream.available(); 36 } 37 38 41 public void close() throws IOException { 42 this.realInputStream.close(); 43 } 44 45 48 public synchronized void mark(int readlimit) { 49 this.realInputStream.mark(readlimit); 50 } 51 52 55 public boolean markSupported() { 56 return this.realInputStream.markSupported(); 57 } 58 59 public int read() throws IOException { 60 int tmp = this.realInputStream.read(); 61 if (BenchSocketFactory.measure) { 62 total += tmp; 63 } 64 total += tmp; 65 return tmp; 66 } 67 68 71 public int read(byte[] b, int off, int len) throws IOException { 72 int tmp = this.realInputStream.read(b, off, len); 73 if (BenchSocketFactory.measure) { 74 total += tmp; 75 } 76 return tmp; 77 } 78 79 82 public int read(byte[] b) throws IOException { 83 int tmp = this.realInputStream.read(b); 84 if (BenchSocketFactory.measure) { 85 total += tmp; 86 } 87 return tmp; 88 } 89 90 93 public synchronized void reset() throws IOException { 94 this.realInputStream.reset(); 95 } 96 97 100 public long skip(long n) throws IOException { 101 return this.realInputStream.skip(n); 102 } 103 } 104 | Popular Tags |