title: Java: Error creating a GZIPInputStream: Not in GZIP format
body: <p>I am trying to use the following Java code to compress and uncompress a String.  But the line that creates a new GZipInputStream object out of a new ByteArrayInputStream object throws a "java.util.zip.ZipException: Not in GZIP format" exception.  Does anyone know how to solve this?</p>
  
  <pre><code>        String orig = ".............";
  
          // compress it
          ByteArrayOutputStream baostream = new ByteArrayOutputStream();
          OutputStream outStream = new GZIPOutputStream(baostream);
          outStream.write(orig.getBytes());
          outStream.close();
          String compressedStr = baostream.toString();
  
          // uncompress it
          InputStream inStream = new GZIPInputStream(new ByteArrayInputStream(compressedStr.getBytes()));
          ByteArrayOutputStream baoStream2 = new ByteArrayOutputStream();
          byte[] buffer = new byte[8192];
          int len;
          while((len = inStream.read(buffer))&gt;0)
              baoStream2.write(buffer, 0, len);
          String uncompressedStr = baoStream2.toString();
  </code></pre>