Class XrefParser

java.lang.Object
org.sejda.sambox.input.XrefParser

class XrefParser extends Object
Component responsible for finding and parsing the xref chain (either tables and streams). In case of errors while parsing the xref chain (Ex. invalid offset, bad dictionaries etc) it has a fallback mechanism performing a document full scan searching for xrefs. When parsing the document, xref info are passed to the COSParser which will use them to retrieve COS objects on demand.
See Also:
  • Field Details

  • Constructor Details

    • XrefParser

      public XrefParser(COSParser parser)
  • Method Details

    • parse

      public void parse() throws IOException
      parse the xref using the given parser.
      Throws:
      IOException
    • findXrefOffset

      private long findXrefOffset() throws IOException
      Looks for the startxref keyword within the latest DEFAULT_TRAIL_BYTECOUNT bytes of the source. If found it returns the Long read after the keyword, if not it returns -1.
      Returns:
      the xref offset or -1 if the startxref keyword is not found
      Throws:
      IOException - If something went wrong.
    • parseXref

      private boolean parseXref(long xrefOffset)
    • doParseXref

      private boolean doParseXref(long xrefOffset) throws IOException
      Throws:
      IOException
    • isValidXrefOffset

      private boolean isValidXrefOffset(long xrefOffset) throws IOException
      Parameters:
      xrefOffset -
      Returns:
      true if the given offset points to an xref table or and xref stream
      Throws:
      IOException
    • isValidXrefStreamOffset

      private boolean isValidXrefStreamOffset(long xrefStreamOffset) throws IOException
      Parameters:
      xrefStreamOffset -
      Returns:
      true if the given offset points to a valid xref stream
      Throws:
      IOException
    • trailer

      public FileTrailer trailer()