gzipoutputstream

How to compress a .zip to a .gz in java?

╄→гoц情女王★ 提交于 2019-12-02 04:33:44
I want to compress a normal file to a .zip and then compress it as gzip file without creating a new file. For example let's say that I have a pdf document doc.pdf , what I have to get is: doc.pdf.zip.gz I don't want to creat a new file called doc.pdf.zip and then open it and gzip it. I'm working with a server to get the file from the browser and return it back, this is my function: public void ZIPandGZIP(String fileName, OutputStream os, String header) throws FileNotFoundException { File file = new File(fileName); FileInputStream fis = new FileInputStream(file); byte[] data = new byte[(int)

Why do gzip of Java and Go get different results?

跟風遠走 提交于 2019-11-27 07:56:49
问题 Firstly, my Java version: string str = "helloworld"; ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream(str.length()); GZIPOutputStream localGZIPOutputStream = new GZIPOutputStream(localByteArrayOutputStream); localGZIPOutputStream.write(str.getBytes("UTF-8")); localGZIPOutputStream.close(); localByteArrayOutputStream.close(); for(int i = 0;i < localByteArrayOutputStream.toByteArray().length;i ++){ System.out.println(localByteArrayOutputStream.toByteArray()[i]); }