package de.tudarmstadt.informatik.hostage.nio;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import de.tudarmstadt.informatik.hostage.wrapper.Packet;

public class Reader {

	BufferedInputStream in;

	public Reader(InputStream in) {
		this.in = new BufferedInputStream(in);
	}

	public Packet read() throws IOException {
		ByteArrayOutputStream payload = new ByteArrayOutputStream();
		do {
			payload.write(in.read());
			Thread.yield();
		} while (in.available() > 0);
		return new Packet(payload.toByteArray());
	}

}