package com.magegrid.net;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class StreamManager {

	public void sendBytes(OutputStream output, byte[] buf) {
		try {
			byte[] bufSend = new byte[buf.length+1];			
			bufSend[0] = (byte)buf.length;
			for(int i=0;i<buf.length;i++)
				bufSend[i+1] = buf[i];
			
			output.write(bufSend);
		} catch (IOException e) {
		}
	}

	public byte[] getBytes(InputStream input) {
		byte[] buf = new byte[0];
		try {
			int l = input.read();			
			buf = new byte[l];			
			int off = 0;
			for(int i=0;i<(l);i++){				
				buf[off++] = (byte)input.read();
			}
		} catch (IOException e) {
		} catch (NegativeArraySizeException e) {
		}
		return buf;
	}

}
