Create a Zip File in Memory

前端 未结 3 739
悲哀的现实
悲哀的现实 2020-12-23 16:42

I\'m trying to zip a file (for example foo.csv) and upload it to a server. I have a working version which creates a local copy and then deletes the local copy. How would I

3条回答
  •  滥情空心
    2020-12-23 17:21

    nifi MergeContent contain compressZip code

    commons-io

    public byte[] compressZip(ByteArrayOutputStream baos,String entryName) throws IOException {
        try (final ByteArrayOutputStream zipBaos = new ByteArrayOutputStream();
             final java.util.zip.ZipOutputStream out = new ZipOutputStream(zipBaos)) {
            final ZipEntry zipEntry = new ZipEntry(entryName);
            zipEntry.setSize(baos.size());
            out.putNextEntry(zipEntry);
            IOUtils.copy(new ByteArrayInputStream(baos.toByteArray()), out);
            out.closeEntry();
            out.finish();
            out.flush();
            return zipBaos.toByteArray();
        }
    }
    

提交回复
热议问题