⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 infcodes.java

📁 zlib 算法在j2me 中的应用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	  if(m==0){	    if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}	    if(m==0){	      s.write=q; r=s.inflate_flush(z,r);	      q=s.write;m=q<s.read?s.read-q-1:s.end-q;	      if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}	      if(m==0){		s.bitb=b;s.bitk=k;		z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;		s.write=q;		return s.inflate_flush(z,r);	      }  	    }	  }	  //s.window[q++]=s.window[f++]; m--;                s.window.set(q++,s.window.get(f++)); m--; 	  if (f == s.end)            f = 0;	  len--;	}	mode = START;	break;      case LIT:           // o: got literal, waiting for output space	if(m==0){	  if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}	  if(m==0){	    s.write=q; r=s.inflate_flush(z,r);	    q=s.write;m=q<s.read?s.read-q-1:s.end-q;	    if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}	    if(m==0){	      s.bitb=b;s.bitk=k;	      z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;	      s.write=q;	      return s.inflate_flush(z,r);	    }	  }	}	r=Z_OK;	//s.window[q++]=(byte)lit; m--;              s.window.set(q++,(byte)lit); m--;		mode = START;	break;      case WASH:           // o: got eob, possibly more output	if (k > 7){        // return unused byte, if any	  k -= 8;	  n++;	  p--;             // can always return one	}	s.write=q; r=s.inflate_flush(z,r);	q=s.write;m=q<s.read?s.read-q-1:s.end-q;	if (s.read != s.write){	  s.bitb=b;s.bitk=k;	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;	  s.write=q;	  return s.inflate_flush(z,r);	}	mode = END;      case END:	r = Z_STREAM_END;	s.bitb=b;s.bitk=k;	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;	s.write=q;	return s.inflate_flush(z,r);      case BADCODE:       // x: got error	r = Z_DATA_ERROR;	s.bitb=b;s.bitk=k;	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;	s.write=q;	return s.inflate_flush(z,r);      default:	r = Z_STREAM_ERROR;	s.bitb=b;s.bitk=k;	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;	s.write=q;	return s.inflate_flush(z,r);      }    }  }  void free(ZStream z){    //  ZFREE(z, c);  }  // Called with number of bytes left to write in window at least 258  // (the maximum string length) and number of input bytes available  // at least ten.  The ten bytes are six bytes for the longest length/  // distance pair plus four bytes for overloading the bit buffer.  int inflate_fast(int bl, int bd, 		   int_AccessibleArray tl, int tl_index,		   int_AccessibleArray td, int td_index,		   InfBlocks s, ZStream z){    int t;                // temporary pointer    int_AccessibleArray tp;             // temporary pointer    int tp_index;         // temporary pointer    int e;                // extra bits or operation    int b;                // bit buffer    int k;                // bits in bit buffer    int p;                // input data pointer    int n;                // bytes available there    int q;                // output window write pointer    int m;                // bytes to end of window or read pointer    int ml;               // mask for literal/length tree    int md;               // mask for distance tree    int c;                // bytes to copy    int d;                // distance back to copy from    int r;                // copy source pointer    // load input, output, bit values    p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;    q=s.write;m=q<s.read?s.read-q-1:s.end-q;    // initialize masks    ml = inflate_mask[bl];    md = inflate_mask[bd];    // do until not enough input or output space for fast loop    do {                          // assume called with m >= 258 && n >= 10      // get literal/length code      while(k<(20)){              // max bits for literal/length code	n--;	b|=(z.next_in[p++]&0xff)<<k;k+=8;      }      t= b&ml;      tp=tl;       tp_index=tl_index;      //if ((e = tp[(tp_index+t)*3]) == 0){      if ((e = tp.get((tp_index+t)*3)) == 0){		//b>>=(tp[(tp_index+t)*3+1]); k-=(tp[(tp_index+t)*3+1]);	b>>=(tp.get((tp_index+t)*3+1)); k-=(tp.get((tp_index+t)*3+1));	//s.window[q++] = (byte)tp[(tp_index+t)*3+2];	s.window.set(q++,(byte)tp.get((tp_index+t)*3+2));	m--;	continue;      }      do {	//b>>=(tp[(tp_index+t)*3+1]); k-=(tp[(tp_index+t)*3+1]);	b>>=(tp.get((tp_index+t)*3+1)); k-=(tp.get((tp_index+t)*3+1));	if((e&16)!=0){	  e &= 15;	  //c = tp[(tp_index+t)*3+2] + ((int)b & inflate_mask[e]);                c = tp.get((tp_index+t)*3+2) + ((int)b & inflate_mask[e]);	  b>>=e; k-=e;	  // decode distance base of block to copy	  while(k<(15)){           // max bits for distance code	    n--;	    b|=(z.next_in[p++]&0xff)<<k;k+=8;	  }	  t= b&md;	  tp=td;	  tp_index=td_index;	  //e = tp[(tp_index+t)*3];	  e = tp.get((tp_index+t)*3);	  do {	    //b>>=(tp[(tp_index+t)*3+1]); k-=(tp[(tp_index+t)*3+1]);	    b>>=(tp.get((tp_index+t)*3+1)); k-=(tp.get((tp_index+t)*3+1));	    if((e&16)!=0){	      // get extra bits to add to distance base	      e &= 15;	      while(k<(e)){         // get extra bits (up to 13)		n--;		b|=(z.next_in[p++]&0xff)<<k;k+=8;	      }	      //d = tp[(tp_index+t)*3+2] + (b&inflate_mask[e]);	      d = tp.get((tp_index+t)*3+2) + (b&inflate_mask[e]);	      	      b>>=(e); k-=(e);	      // do the copy	      m -= c;	      if (q >= d){                // offset before dest		//  just copy		r=q-d;		if(q-r>0 && 2>(q-r)){           		  //s.window[q++]=s.window[r++]; c--; // minimum count is three,		  //s.window[q++]=s.window[r++]; c--; // so unroll loop a little		  s.window.set(q++,s.window.get(r++)); c--; // minimum count is three,		  s.window.set(q++,s.window.get(r++)); c--; // so unroll loop a little		  		}		else{		  //System.arraycopy(s.window, r, s.window, q, 2);                               byte_array.Copy(s.window, r, s.window, q, 2);		  		  q+=2; r+=2; c-=2;		}	      }	      else{                  // else offset after destination                r=q-d;                do{                  r+=s.end;          // force pointer in window                }while(r<0);         // covers invalid distances		e=s.end-r;		if(c>e){             // if source crosses,		  c-=e;              // wrapped copy		  if(q-r>0 && e>(q-r)){           		    //do{s.window[q++] = s.window[r++];}                                do{s.window.set(q++,s.window.get(r++));}		    		    while(--e!=0);		  }		  else{		    //System.arraycopy(s.window, r, s.window, q, e);		    byte_array.Copy(s.window, r, s.window, q, e);		    		    q+=e; r+=e; e=0;		  }		  r = 0;                  // copy rest from start of window		}	      }	      // copy all or what's left	      if(q-r>0 && c>(q-r)){           		//do{s.window[q++] = s.window[r++];}		do{s.window.set(q++,s.window.get(r++));}				while(--c!=0);	      }	      else{		//System.arraycopy(s.window, r, s.window, q, c);                            byte_array.Copy(s.window, r, s.window, q, c);				q+=c; r+=c; c=0;	      }	      break;	    }	    else if((e&64)==0){	      //t+=tp[(tp_index+t)*3+2];	      t+=tp.get((tp_index+t)*3+2);	      t+=(b&inflate_mask[e]);	      //e=tp[(tp_index+t)*3];	      e=tp.get((tp_index+t)*3);	    }	    else{	      z.msg = "invalid distance code";	      c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;	      s.bitb=b;s.bitk=k;	      z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;	      s.write=q;	      return Z_DATA_ERROR;	    }	  }	  while(true);	  break;	}	if((e&64)==0){	  //t+=tp[(tp_index+t)*3+2];	  t+=tp.get((tp_index+t)*3+2);	  t+=(b&inflate_mask[e]);	  //if((e=tp[(tp_index+t)*3])==0){	  if((e=tp.get((tp_index+t)*3))==0){	    //b>>=(tp[(tp_index+t)*3+1]); k-=(tp[(tp_index+t)*3+1]);	    b>>=(tp.get((tp_index+t)*3+1)); k-=(tp.get((tp_index+t)*3+1));	    	    //s.window[q++]=(byte)tp[(tp_index+t)*3+2];                  s.window.set(q++,(byte)tp.get((tp_index+t)*3+2));	    m--;	    break;	  }	}	else if((e&32)!=0){	  c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3; 	  s.bitb=b;s.bitk=k;	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;	  s.write=q;	  return Z_STREAM_END;	}	else{	  z.msg="invalid literal/length code";	  c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;	  s.bitb=b;s.bitk=k;	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;	  s.write=q;	  return Z_DATA_ERROR;	}      }       while(true);    }     while(m>=258 && n>= 10);    // not enough input or output--restore pointers and return    c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;    s.bitb=b;s.bitk=k;    z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;    s.write=q;    return Z_OK;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -