package org.kne.io;

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

public class AddOutputStream extends OutputStream {
	volatile byte out=0;
	private OutputStream o;
	
	@Override
	public void close() throws IOException {
		o.close();
	}

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

	public AddOutputStream(OutputStream o) {
		super();
		this.o = o;
	}

	@Override
	public void write(int b) throws IOException {
		o.write((((byte)b)-out)&0xff);
		out=(byte) b;
	}
	public void write(byte[][]e) throws IOException{
		for (int y = 0; y < e.length; y++) {
			byte tmp[]=e[y];
			//System.out.println(Arrays.toString(tmp));
			for (int x = 0; x < tmp.length; x++) {
				write(tmp[x]&0xFF);
			}
		}
	}
}
