Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #30162

Exception in thread "main" java.util.zip.ZipException: Not in GZIP format

Newsgroups comp.lang.java.programmer
Date 2014-10-23 01:51 -0700
Message-ID <38eee3eb-4817-4a14-b823-4609b421b3fa@googlegroups.com> (permalink)
Subject Exception in thread "main" java.util.zip.ZipException: Not in GZIP format
From takouarnauld@gmail.com

Show all headers | View raw


Good Moorning,

I'm trying in my program to Compress/Decompress data using GZIP streams and when using the charset "ISO-8859-1", everything working well but when changing the charset to "UTF-8", i'm getting the Error message "Exception in thread "main" java.util.zip.ZipException: Not in GZIP format". 
this is my code:

public static String compress(String str) throws IOException {
	        if (str == null || str.length() == 0) {
	            return str;
	        }
	        System.out.println("String length : " + str.length());
	        ByteArrayOutputStream out = new ByteArrayOutputStream();
	        GZIPOutputStream gzip = new GZIPOutputStream(out);
	        gzip.write(str.getBytes());
	        gzip.close();
	        String outStr = out.toString("UTF-8");
	        System.out.println("Output String lenght : " + outStr.length());
	        System.out.println("Output : " + outStr.toString());
	        return outStr;
	 }
	    
	 public static String decompress(String str) throws IOException {
	    if (str == null || str.length() == 0) {
	       return str;
	    }
	        System.out.println("Input String length : " + str.length());
	        GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(str.getBytes("UTF-8")));
	        BufferedReader bf = new BufferedReader(new InputStreamReader(gis, "UTF-8"));
	        String outStr = "";
	        String line;
	        while ((line=bf.readLine())!=null) {
	          outStr += line;
	        }
	        System.out.println("Output String lenght : " + outStr.length());
	        return outStr;
	 }
	  
	 public static void main(String[] args) throws IOException {

	        
	        String string = "my data";
	        System.out.println("after compress:");
	        String compressed = compress(string);
	        System.out.println(compressed);
	        System.out.println("after decompress:");
	        String decomp = decompress(compressed);
	        System.out.println(decomp);
	 
	 }


Please can you people help me find a solutioN??

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Exception in thread "main" java.util.zip.ZipException: Not in GZIP format takouarnauld@gmail.com - 2014-10-23 01:51 -0700
  Re: Exception in thread "main" java.util.zip.ZipException: Not in GZIP format Martin Gregorie <martin@address-in-sig.invalid> - 2014-10-23 11:19 +0000
  Re: Exception in thread "main" java.util.zip.ZipException: Not in GZIP format Steven Simpson <ss@domain.invalid> - 2014-10-23 14:31 +0100
  Re: Exception in thread "main" java.util.zip.ZipException: Not in GZIP format Mike Amling <mamling@chaff.us> - 2014-10-23 09:30 -0500

csiph-web