package org.bench4q.agent.storage;

public class Buffer {
	private byte[] content;
	private int currentPos;
	private int totalSize;

	public byte[] getContent() {
		return content;
	}

	public void setContent(byte[] content) {
		this.content = content;
	}

	public int getCurrentPos() {
		return currentPos;
	}

	public void setCurrentPos(int currentPos) {
		this.currentPos = currentPos;
	}

	public int getTotalSize() {
		return totalSize;
	}

	public void setTotalSize(int totalSize) {
		this.totalSize = totalSize;
	}

	public static Buffer createBuffer(int totalSize) {
		Buffer buffer = new Buffer();
		buffer.setContent(new byte[totalSize]);
		buffer.setCurrentPos(0);
		buffer.setTotalSize(totalSize);
		return buffer;
	}

	public int getRemainSize() {
		return this.totalSize - this.currentPos;
	}

	public void reset() {
		this.setCurrentPos(0);
	}

	public void setFull() {
		this.setCurrentPos(this.getTotalSize());
	}

	void writeToCurrentBuffer(int size, byte[] cache) {
		System.arraycopy(cache, 0, this.getContent(), this.getCurrentPos(),
				size);
		this.setCurrentPos(this.getCurrentPos() + size);
	}
}
