• Como Descomprimir Archivos GZIP en Java

    Muy sencillamente podemos descomprimir un archivo ASCII comprimido con GZIP y transformarlo en texto.

    El inputstream que recibe este metodo es un file o quiza un requeset http.

    public String decompress(InputStream input) throws Exception {
      // opens the compressed file
      GZIPInputStream in = new GZIPInputStream(input);
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      // Transfer bytes from the compressed file to the output file
      byte[] buffer = new byte[1024];
      int len;
      while ((len = in.read(buffer)) > 0) {
        output.write(buffer, 0, len);
      }
      in.close();
      output.close();
      return output.toString();
    }
    

Leave a comment