1 package org.objectweb.proactive.ext.benchsocket; 2 3 import java.io.IOException ; 4 import java.io.OutputStream ; 5 6 7 public class BenchOutputStream extends OutputStream implements BenchStream { 8 private OutputStream realOutputStream; 9 private int total; 10 private int number; 11 12 public BenchOutputStream(OutputStream o, int number) { 13 this.realOutputStream = o; 14 this.number = number; 15 Runtime.getRuntime().addShutdownHook(new ShutdownThread(this)); 18 } 19 20 public void write(int b) throws IOException { 21 if (BenchSocketFactory.measure){ 22 total ++; 23 } 24 this.realOutputStream.write(b); 25 } 26 27 public void write(byte[] b, int off, int len) throws IOException { 28 if (BenchSocketFactory.measure){ 29 total += len; 30 } 31 32 this.realOutputStream.write(b, off, len); 33 } 34 35 public void write(byte[] b) throws IOException { 36 if (BenchSocketFactory.measure){ 37 total += b.length; 38 } 39 this.realOutputStream.write(b); 40 } 41 42 public void displayTotal() { 43 System.out.println("=== Total Output for socket " + number + " = " + total); 44 } 45 } 46 | Popular Tags |