public static byte[] decode(InputStream in) throws IOException {
		byte first = (byte) in.read();

		if (first == -1) {
			throw new IOException("End of stream");
		}

		int length;

		if (first >= 0) {
			length = first + 1;
		} else {
			length = (first & 0x1F) + 1;
			int count = (first & 0x60) >>> 5;

			for (int i = 0; i < count; i++) {
				length += in.read() << (i << 3) + 5;
			}
		}

		byte[] buffer = new byte[length];
		in.read(buffer, 0, length);
		return buffer;
	}