package org.kne.cloud.network.klalb;

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.concurrent.atomic.AtomicLong;

public class MonitoredOutputStream extends FilterOutputStream {

	private AtomicLong[] total;
	public MonitoredOutputStream(OutputStream outputStream,AtomicLong ...v) {
		super(outputStream);
		this.total=v;
	}

	@Override
	public void write(int b) throws IOException {
		out.write(b);
		for(AtomicLong x:total)
		x.incrementAndGet();
	}

	@Override
	public void write(byte[] b) throws IOException {
		out.write(b);
		for(AtomicLong x:total)
		x.addAndGet(b.length);
	}

	@Override
	public void write(byte[] b, int off, int len) throws IOException {
		out.write(b, off, len);
		for(AtomicLong x:total)
		x.addAndGet(len);
	}

	@Override
	public void flush() throws IOException {
		out.flush();
	}

	@Override
	public void close() throws IOException {
		out.close();
	}

	

}
