All pastes #36892 Raw Edit

10.2 java

public java v1 · immutable
#36892 ·published 2006-01-15 18:38 UTC
rendered paste body
public void einpacken() throws IOException {				ZirkulaereReihung buffer = new ZirkulaereReihung(maxLookAheadBufferSize + maxSearchBufferSize);		int lookAheadHead = 0;		int lookAheadLen = 0;				int tmpByte = leseByte();		while (tmpByte >= 0 || lookAheadLen > 0)		{			//run this loop while there is something to read or LookAhead is not empty			if(tmpByte >= 0)			{				if(buffer.isFull())				{  //Make some room for a new byte					buffer.dequeue();					lookAheadHead--;				}				buffer.append((byte)tmpByte);				lookAheadLen++;			}						if(lookAheadLen == maxLookAheadBufferSize || tmpByte == -1)			{				//Just do something if LookAhead is at max capacity (to get best results) or we are at eof.				int searchpos = 1;				int foundlength = 0;				int offset = 0;				for(int i = lookAheadHead - searchpos; i >= 0; i--)				{					//Look for matches					if(buffer.getAt(i) == buffer.getAt(lookAheadHead))					{						//Found a match						int len = 0;						while(buffer.getAt(i+len) == buffer.getAt(lookAheadHead + len) && i + len < lookAheadHead  && len < lookAheadLen - 1 && searchpos < maxSearchBufferSize)						{							len++;						}												if(len >= foundlength)						{							//Found a better match so use this one							foundlength=len;							offset = searchpos;						}					}						searchpos++;				}				//write our result				schreibeTupel(offset, foundlength, (int)buffer.getAt(lookAheadHead + foundlength));				lookAheadHead += foundlength + 1;				lookAheadLen -= foundlength + 1;				}			if(tmpByte >= 0)			{				tmpByte = leseByte();			}		}		}