Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
  public static byte[] toByteArray(final InputStream inputStream) throws IOException {
    Assert.notNull(inputStream, "inputStream");

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    IOUtils.copy(inputStream, outputStream);

    return outputStream.toByteArray();
  }
Ejemplo n.º 3
0
  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;
  }
Ejemplo n.º 4
0
  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();
  }
Ejemplo n.º 5
0
  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;
  }
Ejemplo n.º 6
0
  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();
  }
Ejemplo n.º 7
0
 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();
 }
Ejemplo n.º 8
0
 public static InputStream gunzip(final byte[] bytes) throws IOException {
   Assert.notNull(bytes, "bytes");
   return IOUtils.gunzip(new ByteArrayInputStream(bytes));
 }
Ejemplo n.º 9
0
 public static String toString(final Reader reader) throws IOException {
   return IOUtils.toString(reader, Charset.defaultCharset());
 }
Ejemplo n.º 10
0
 public static String toString(final InputStream inputStream) throws IOException {
   return IOUtils.toString(inputStream, Charset.defaultCharset());
 }