package org.kne.cloud.network.klalb;

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

public class MonitoredOutputStream extends FilterOutputStream {

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

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

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

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

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

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

	

}
