示例#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();
 }
示例#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();
  }
示例#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;
  }
示例#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();
  }
示例#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;
  }
示例#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();
  }
示例#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();
 }
示例#8
0
 public static InputStream gunzip(final byte[] bytes) throws IOException {
   Assert.notNull(bytes, "bytes");
   return IOUtils.gunzip(new ByteArrayInputStream(bytes));
 }
示例#9
0
 public static String toString(final Reader reader) throws IOException {
   return IOUtils.toString(reader, Charset.defaultCharset());
 }
示例#10
0
 public static String toString(final InputStream inputStream) throws IOException {
   return IOUtils.toString(inputStream, Charset.defaultCharset());
 }