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(); } } }