public static byte[] readFromInputStream(InputStream in) throws IOException {
		if (in == null) {
			return null;
		}
		ReadableByteChannel rbc = Channels.newChannel(in);
		ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
		byte[] data = new byte[BUFFER_SIZE];
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		while (true) {
			int count = rbc.read(buffer);
			if (count == -1) {
				break;
			}
			if (count < BUFFER_SIZE) {
				data = new byte[count];
			}
			buffer.flip();
			buffer.get(data, 0, count);
			baos.write(data);
			buffer.clear();
		}
		rbc.close();
		return baos.toByteArray();
	}