package org.kne.io;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public final class AddInputStream extends InputStream {

	volatile byte out = 0;
	private InputStream in;

	@Override
	public int read() throws IOException {
		int read = in.read();
		if (read==-1) {
			return -1;
		}
		out = (byte) (out+(byte) read);
		return out&0xff;
	}

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

	public AddInputStream(InputStream in) {
		super();
		this.in = in;
	}

	public void read(byte[][] e) throws IOException {
		for (int y = 0; y<e.length; y++) {
			byte tmp[] = e[y];

			for (int x = 0; x<tmp.length; x++) {
				tmp[x] = (byte) read();
			}
		}
	}

}
