protected void rebuildXref() throws IOException {
        hybridXref = false;
        newXrefType = false;
        tokens.seek(0);
        long xr[][] = new long[1024][];
        long top = 0;
        trailer = null;
        byte line[] = new byte[64];
        for (;;) {
            long pos = tokens.getFilePointer();
            if (!tokens.readLineSegment(line))
                break;
            if (line[0] == 't') {
                if (!PdfEncodings.convertToString(line, null).startsWith("trailer"))
                    continue;
                tokens.seek(pos);
                tokens.nextToken();
                pos = tokens.getFilePointer();
                try {
                    PdfDictionary dic = (PdfDictionary)readPRObject();
                    if (dic.get(PdfName.ROOT) != null)
                        trailer = dic;
                    else
                        tokens.seek(pos);
                }
                catch (Exception e) {
                    tokens.seek(pos);
                }
            }
            else if (line[0] >= '0' && line[0] <= '9') {
                long obj[] = PRTokeniser.checkObjectStart(line);
                if (obj == null)
                    continue;
                long num = obj[0];
                long gen = obj[1];
                if (num >= xr.length) {
                    long newLength = num * 2;
                    long xr2[][] = new long[(int)newLength][];
                    System.arraycopy(xr, 0, xr2, 0, (int)top);
                    xr = xr2;
                }
                if (num >= top)
                    top = num + 1;
                if (xr[(int)num] == null || gen >= xr[(int)num][1]) {
                    obj[0] = pos;
                    xr[(int)num] = obj;
                }
            }
        }
        if (trailer == null)
            throw new InvalidPdfException(MessageLocalization.getComposedMessage("trailer.not.found"));
        xref = new long[(int)(top * 2)];
        for (int k = 0; k < top; ++k) {
            long obj[] = xr[k];
            if (obj != null)
                xref[k * 2] = obj[0];
        }
    }