View Javadoc

1   package fr.in2p3.jsaga.impl.file.copy;
2   
3   import java.io.IOException;
4   import java.io.OutputStream;
5   
6   import org.ogf.saga.file.FileOutputStream;
7   
8   /* ***************************************************
9    * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
10   * ***             http://cc.in2p3.fr/             ***
11   * ***************************************************
12   * File:   MonitoredOutputStream
13   * Author: Lionel Schwarz (lionel.schwarz@in2p3.fr)
14   * Date:   Halloween 2013
15   * ***************************************************/
16  
17  public class MonitoredOutputStream extends OutputStream {
18  
19  	private FileOutputStream out;
20  	private AbstractCopyTask monitor;
21  	
22  	public MonitoredOutputStream(FileOutputStream o, AbstractCopyTask a) {
23  		this.out = o;
24  		this.monitor = a;
25  	}
26  	
27  	@Override
28  	public void write(int b) throws IOException {
29  		out.write(b);
30  	}
31  
32  	@Override
33  	public void write(byte b[]) throws IOException {
34  		this.out.write(b);
35  		if (this.monitor != null)
36  			this.monitor.increment(b.length);
37  	}
38  	
39  	@Override
40  	public void write(byte b[], int off, int len) throws IOException {
41  		this.out.write(b, off, len);
42  		if (this.monitor != null)
43  			this.monitor.increment(len);
44  	}
45  }