/** * Adapted from {@code com.google.common.io.ByteStreams.toByteArray()}. */ public static byte[] toByteArray(InputStream in) throws IOException { checkNotNull(in, "in"); try { ByteArrayOutputStream out = new ByteArrayOutputStream(); copy(in, out); return out.toByteArray(); } finally { ensureClosed(in); } }