private byte [ ] unGZip ( byte [ ] bytes ) { if ( bytes == null || bytes . length == 0 ) { return bytes ; } GZIPInputStream gzis = null ; ByteArrayOutputStream baos = null ; try { gzis = new GZIPInputStream ( new ByteArrayInputStream ( bytes ) ) ; baos = new ByteArrayOutputStream ( ) ; int len ; byte [ ] buffer = new byte [ 1024 ] ; while ( ( len = gzis . read ( buffer ) ) > 0 ) { baos . write ( buffer , 0 , len ) ; } return baos . toByteArray ( ) ; } catch ( IOException e ) { // unable to work up // send back null } finally { if ( gzis != null ) { try { gzis . close ( ) ; } catch ( IOException e ) { // eat up } } if ( baos != null ) { try { baos . close ( ) ; } catch ( IOException e ) { // eat up } } } return null ; }
UnGZIP a given byte stream .