public int blast ( InputStream input , OutputStream output ) throws IOException { m_input = input ; m_output = output ; int lit ; /* true if literals are coded */ int dict ; /* log2(dictionary size) - 6 */ int symbol ; /* decoded symbol, extra bits for distance */ int len ; /* length for copy */ int dist ; /* distance for copy */ int copy ; /* copy counter */ //unsigned char *from, *to; /* copy pointers */ /* read header */ lit = bits ( 8 ) ; if ( lit > 1 ) { return - 1 ; } dict = bits ( 8 ) ; if ( dict < 4 || dict > 6 ) { return - 2 ; } /* decode literals and length/distance pairs */ do { if ( bits ( 1 ) != 0 ) { /* get length */ symbol = decode ( LENCODE ) ; len = BASE [ symbol ] + bits ( EXTRA [ symbol ] ) ; if ( len == 519 ) { break ; /* end code */ } /* get distance */ symbol = len == 2 ? 2 : dict ; dist = decode ( DISTCODE ) << symbol ; dist += bits ( symbol ) ; dist ++ ; if ( m_first != 0 && dist > m_next ) { return - 3 ; /* distance too far back */ } /* copy length bytes from distance bytes back */ do { //to = m_out + m_next; int to = m_next ; int from = to - dist ; copy = MAXWIN ; if ( m_next < dist ) { from += copy ; copy = dist ; } copy -= m_next ; if ( copy > len ) { copy = len ; } len -= copy ; m_next += copy ; do { //*to++ = *from++; m_out [ to ++ ] = m_out [ from ++ ] ; } while ( -- copy != 0 ) ; if ( m_next == MAXWIN ) { //if (s->outfun(s->outhow, s->out, s->next)) return 1; m_output . write ( m_out , 0 , m_next ) ; m_next = 0 ; m_first = 0 ; } } while ( len != 0 ) ; } else { /* get literal and write it */ symbol = lit != 0 ? decode ( LITCODE ) : bits ( 8 ) ; m_out [ m_next ++ ] = ( byte ) symbol ; if ( m_next == MAXWIN ) { //if (s->outfun(s->outhow, s->out, s->next)) return 1; m_output . write ( m_out , 0 , m_next ) ; m_next = 0 ; m_first = 0 ; } } } while ( true ) ; if ( m_next != 0 ) { m_output . write ( m_out , 0 , m_next ) ; } return 0 ; }
Decode PKWare Compression Library stream .