package org.kne.cloud.network.klalb;

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;

public class MonitoredInputStream extends FilterInputStream {

	private LongAdder[] total;
	public MonitoredInputStream(InputStream inputStream,LongAdder... v) {
		super(inputStream);
		this.total=v;
	}
	
	@Override
	public int read() throws IOException {
	int v=in.read();
	if(v!=-1) {
		for(LongAdder x:total)
		x.add(1);
	}
		return v;
	}

	@Override
	public int read(byte[] b) throws IOException {
		int v=in.read(b);
		if(v!=-1) {
			for(LongAdder x:total)
			x.add(v);
		}
		return v;
	}

	@Override
	public int read(byte[] b, int off, int len) throws IOException {
		int v=in.read(b, off, len);
		if(v!=-1) {
			for(LongAdder x:total)
			x.add(v);
		}
		return v;
	}

	@Override
	public long skip(long n) throws IOException {
		return in.skip(n);
	}

	@Override
	public int available() throws IOException {
		return in.available();
	}

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

	@Override
	public void mark(int readlimit) {
		in.mark(readlimit);
	}

	@Override
	public void reset() throws IOException {
		in.reset();
	}

	@Override
	public boolean markSupported() {
		return in.markSupported();
	}


}
