question: private int readFirstStartRef ( ) throws PdfException { offset . setRefTableInvalid ( false ) ; int pointer = - 1 ; int i = 1019 ; final StringBuilder startRef = new StringBuilder ( 10 ) ; final int block = 1024 ; byte [ ] lastBytes = new byte [ block ] ; long end ; final int [ ] EndOfFileMarker = { 37 , 37 , 69 , 79 } ; int valReached = 3 ; boolean EOFFound = false ; try { end = eof ; final int bufSize = 255 ; while ( true ) { final byte [ ] buffer = getBytes ( end - bufSize , bufSize ) ; int offset = 0 ; for ( int ii = bufSize - 1 ; ii > - 1 ; ii -- ) { if ( ! EOFFound ) { valReached = 3 ; } if ( buffer [ ii ] == EndOfFileMarker [ valReached ] ) { valReached -- ; EOFFound = true ; } else { EOFFound = false ; } offset -- ; if ( valReached < 0 ) { ii = - 1 ; } } if ( valReached < 0 ) { end -= offset ; break ; } else { end -= bufSize ; } if ( end < 0 ) { end = eof ; break ; } } int count = ( int ) ( end - block ) ; if ( count < 0 ) { count = 0 ; final int size = ( int ) eof ; lastBytes = new byte [ size ] ; i = size + 3 ; } lastBytes = getBytes ( count , lastBytes . length ) ; } catch ( final Exception e ) { LogWriter . writeLog ( "Exception " + e + " reading last 1024 bytes" ) ; throw new PdfException ( e + " reading last 1024 bytes" ) ; } final int fileSize = lastBytes . length ; if ( i > fileSize ) { i = fileSize - 5 ; } while ( i > - 1 ) { if ( ( ( lastBytes [ i ] == 116 && lastBytes [ i + 1 ] == 120 ) || ( lastBytes [ i ] == 114 && lastBytes [ i + 1 ] == 116 ) ) && ( lastBytes [ i + 2 ] == 114 ) && ( lastBytes [ i + 3 ] == 101 ) && ( lastBytes [ i + 4 ] == 102 ) ) { break ; } i -- ; } if ( i == - 1 ) { try { closeFile ( ) ; } catch ( final IOException e1 ) { LogWriter . writeLog ( "Exception " + e1 + " closing file" ) ; } throw new PdfException ( "No Startxref found in last 1024 bytes " ) ; } i += 5 ; while ( i < 1024 && ( lastBytes [ i ] == 10 || lastBytes [ i ] == 32 || lastBytes [ i ] == 13 ) ) { i ++ ; } while ( ( i < 1024 ) && ( lastBytes [ i ] != 10 ) && ( lastBytes [ i ] != 32 ) && ( lastBytes [ i ] != 13 ) ) { startRef . append ( ( char ) lastBytes [ i ] ) ; i ++ ; } if ( startRef . length ( ) > 0 ) { pointer = Integer . parseInt ( startRef . toString ( ) ) ; } if ( pointer == - 1 ) { LogWriter . writeLog ( "No Startref found in last 1024 bytes " ) ; try { closeFile ( ) ; } catch ( final IOException e1 ) { LogWriter . writeLog ( "Exception " + e1 + " closing file" ) ; } throw new PdfException ( "No Startref found in last 1024 bytes " ) ; } return pointer ; }
target:  read first start ref from last 1024 bytes