KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.objectweb.proactive.ext.benchsocket;
2
3 import java.io.IOException JavaDoc;
4 import java.io.OutputStream JavaDoc;
5
6
7 public class BenchOutputStream extends OutputStream JavaDoc implements BenchStream {
8     private OutputStream JavaDoc realOutputStream;
9     private int total;
10    private int number;
11
12     public BenchOutputStream(OutputStream JavaDoc o, int number) {
13         this.realOutputStream = o;
14         this.number = number;
15         //we register a hook to be run
16
//when the JVM is killed
17
Runtime.getRuntime().addShutdownHook(new ShutdownThread(this));
18     }
19
20     public void write(int b) throws IOException JavaDoc {
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 JavaDoc {
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 JavaDoc {
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