public static InputStream gunzip(final InputStream inputStream) throws IOException { Assert.notNull(inputStream, "inputStream"); GZIPInputStream gzipInputStream = new GZIPInputStream(inputStream); InputOutputStream inputOutputStream = new InputOutputStream(); IOUtils.copy(gzipInputStream, inputOutputStream); return inputOutputStream.getInputStream(); }
public static byte[] toByteArray(final InputStream inputStream) throws IOException { Assert.notNull(inputStream, "inputStream"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); IOUtils.copy(inputStream, outputStream); return outputStream.toByteArray(); }
public static String toString(final Reader reader, final Charset charset) throws IOException { Assert.notNull(reader, "reader"); Assert.notNull(charset, "charset"); byte[] bytes = IOUtils.toByteArray(reader); String s = new String(bytes, charset); return s; }
public static byte[] toByteArray(final Reader reader) throws IOException { Assert.notNull(reader, "reader"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(outputStream); IOUtils.copy(reader, writer); return outputStream.toByteArray(); }
public static String toString(final InputStream inputStream, final Charset charset) throws IOException { Assert.notNull(inputStream, "inputStream"); Assert.notNull(charset, "charset"); byte[] bytes = IOUtils.toByteArray(inputStream); String s = new String(bytes, charset); return s; }
public static byte[] toByteArray(final File file) throws IOException { Assert.notNull(file, "file"); FileInputStream inputStream = new FileInputStream(file); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); IOUtils.copy(inputStream, outputStream); inputStream.close(); return outputStream.toByteArray(); }
public void test1() throws Exception { String[] files = new String[] {"/tmp/image1.png", "/tmp/image2.png", "/tmp/image3.png"}; FileOutputStream outputStream = new FileOutputStream("/tmp/zip.zip"); ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream); for (String s : files) { File file = new File(s); FileInputStream inputStream = new FileInputStream(file); ZipEntry zipEntry = new ZipEntry(file.getName()); zipOutputStream.putNextEntry(zipEntry); IOUtils.copy(inputStream, zipOutputStream); zipOutputStream.closeEntry(); } zipOutputStream.close(); outputStream.close(); }
public static InputStream gunzip(final byte[] bytes) throws IOException { Assert.notNull(bytes, "bytes"); return IOUtils.gunzip(new ByteArrayInputStream(bytes)); }
public static String toString(final Reader reader) throws IOException { return IOUtils.toString(reader, Charset.defaultCharset()); }
public static String toString(final InputStream inputStream) throws IOException { return IOUtils.toString(inputStream, Charset.defaultCharset()); }