private boolean backscan(ByteBuffer buf, String scanToken) {

        byte[] scanbuf = new byte[32];
        if (scanToken.length() * 2 > scanbuf.length) {
            // should be fine, though less than optimal, for current usages
            throw new IllegalArgumentException("scanToken is too long - " +
                    "adjust buffer length");
        }

        int scanPos = buf.position() - scanbuf.length;
        if (scanPos < 0) {
            // use a shorter scanbuf to do a single, most likely failing, scan
            scanbuf = new byte[buf.position()];
            scanPos = 0;
        }

        while (scanPos >= 0) {
            buf.position(scanPos);
            buf.get(scanbuf);

            // find startxref in scan
            String scans = new String(scanbuf);
            int loc = scans.lastIndexOf(scanToken);
            if (loc > 0) {
                buf.position(scanPos + loc + scanToken.length());
                return true;
            }

            int newScanPos = scanPos - scanbuf.length + scanToken.length() - 1;
            if (newScanPos < 0) {
                scanPos = scanPos == 0 ? -1 : newScanPos;
            } else {
                scanPos = newScanPos;
            }
        }

        return false;
    }