title: Reading GZIP File Causing Unexpected end of ZLIB input stream in java
body: <p>I am converting GZIP byte array to String form in Java.This is considerably large file and idea is to convert this in to JSON.</p>
  
  <p>But Exception I am getting is quite weird and is not making much Sense.</p>
  
  <p>Code Snippeet:</p>
  
  <pre><code>public static String convert(byte[] bytes) throws IOException {
          final byte[] BUFFER = new byte[16234];
  
          GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(bytes));
  
          ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  
          int len;
          while ((len = gzipInputStream.read(BUFFER)) &gt;= 0) {
              byteArrayOutputStream.write(BUFFER, 0, len);
            if(byteArrayOutputStream.size ()&gt;60812918){
                  System.out.println ( "stopping here" );
              }
          }
  
          byteArrayOutputStream.flush();
          byteArrayOutputStream.close();
  
          gzipInputStream.close();
  
          final byte[] dataPart = byteArrayOutputStream.toByteArray();
  
          String data = new String(dataPart, StandardCharsets.UTF_8);
  
          return data;
      }
  </code></pre>
  
  <p>Exception Trace:</p>
  
  <pre><code>java.io.EOFException: Unexpected end of ZLIB input stream
      at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:240)
      at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
      at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:117)
      at java.io.FilterInputStream.read(FilterInputStream.java:107)
      at com.here.rcs.discoverkernels.testS3FileReader.convert(testS3FileReader.java:84)
      at com.here.rcs.discoverkernels.testS3FileReader.viewJson(testS3FileReader.java:45)
      at com.here.rcs.discoverkernels.testS3FileReader.main(testS3FileReader.java:21)
  </code></pre>
  
  <p>From Coding point of view,I don't think there is something wrong with this piece of code.</p>
  
  <p>Any Suggestions how to move forward with this.</p>
  
  <p>Adding To Byte Conversion Part;</p>
  
  <pre><code>public static byte[] compress(final String data) throws IOException {
  
      final byte[] dataPart = data.getBytes( StandardCharsets.UTF_8 );
  
      ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  
      GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream);
      gzipOutputStream.write(dataPart);
  
      gzipOutputStream.flush();
      gzipOutputStream.close();
  
      byte[] bytes = byteArrayOutputStream.toByteArray();
  
      return bytes;
  }
  </code></pre>