public int /* udword_ppt */ decompress ( final short [ ] /* const void* */ source , int /* udword_ppt */ size , final Decompressed decomp ) { this . source = source ; globalError = false ; // assume no error readPtr = 0 ; if ( ! isCompressed ( source , size ) ) { return 0 ; } // Uncompressed size is stored at end of source file. // Backwards decompression. readPtr += ( size - 4 ) ; int /* udword_ppt */ lastDword = readBEdword ( source , readPtr ) ; // Uncompressed length in bits 31-8 of last dword. int /* udword_ppt */ outputLen = lastDword >> 8 ; // Allocate memory for output data. dest = new short /* ubyte_ppt */ [ outputLen ] ; // Lowest dest. address for range-checks. // Put destptr to end of uncompressed data. writePtr = outputLen ; // Read number of unused bits in 1st data dword // from lowest bits 7-0 of last dword. bits = 32 - ( lastDword & 0xFF ) ; // Main decompression loop. bytesTOdword ( ) ; if ( bits != 32 ) current >>= ( 32 - bits ) ; do { if ( readBits ( 1 ) == 0 ) bytes ( ) ; if ( writePtr > 0 ) sequence ( ) ; if ( globalError ) { // statusString already set. outputLen = 0 ; // unsuccessful decompression break ; } } while ( writePtr > 0 ) ; // Finished. if ( outputLen > 0 ) // successful { decomp . destBufRef = new short [ dest . length ] ; // Free any previously existing destination buffer. System . arraycopy ( dest , 0 , decomp . destBufRef , 0 , dest . length ) ; } return outputLen ; }
If successful allocates a new buffer containing the uncompresse data and returns the uncompressed length . Else returns 0 .