public byte[] readStream(InputStream in) throws IOException {
        if (in == null) return null;
        try {
            byte[] data = new byte[16384];
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            int len;
            while ((len = in.read(data)) != -1) {
                baos.write(data, 0, len);
            }
            baos.flush();
            return baos.toByteArray();
        } finally {
            try {
                in.close();
            } catch (Exception ignored) {
            }
        }
    }