public void decompress ( String path ) throws IOException { File bzip2 = new File ( path ) ; // File unarchived = new File ( bzip2 . getName ( ) . replace ( ".bz2" , "" ) ) ; unarchived . createNewFile ( ) ; BufferedInputStream inputStr = new BufferedInputStream ( new FileInputStream ( bzip2 ) ) ; // read bzip2 prefix inputStr . read ( ) ; inputStr . read ( ) ; BufferedInputStream buffStr = new BufferedInputStream ( inputStr ) ; CBZip2InputStream input = new CBZip2InputStream ( buffStr ) ; FileOutputStream outStr = new FileOutputStream ( unarchived ) ; while ( true ) { byte [ ] compressedBytes = new byte [ DECOMPRESSION_CACHE ] ; int byteRead = input . read ( compressedBytes ) ; outStr . write ( compressedBytes , 0 , byteRead ) ; if ( byteRead != DECOMPRESSION_CACHE ) { break ; } } input . close ( ) ; buffStr . close ( ) ; inputStr . close ( ) ; outStr . close ( ) ; }
Uncompress bz2 file