// a simple ring buffer implementation.
// the buffer is divided into slots


public class Puffer {
	private final int slots;
	private final int bytesPerSlot;
	private final int totalBufferLen;
	
	private final byte buffer[];
		
	private int inpos = 0;
	private int outpos = 0;
	
	public Puffer (int slots, int bps) {
			this.slots = slots;
			this.bytesPerSlot = bps;
			this.totalBufferLen = slots * bps;
			buffer = new byte[totalBufferLen];
			
	}
	
	public void put(byte data[], int len){
		for (int i = 0; i < len; i++) {
			buffer[inpos++] = data[i];
			inpos %= totalBufferLen;
		}
		return;
	}
	
	public byte[] get() {
		byte result[] = new byte[bytesPerSlot]; 
		for (int i = 0; i < bytesPerSlot; i++) {
			result[i] = buffer[outpos++];
			outpos %= totalBufferLen;
		}
		return result;
	}
	
	
}
