code: protected int findScanLength(long offset) throws FileParsingException {
      int length = -1;
      try {
        RandomAccessFile raf = source.getRandomAccessFile();
        raf.seek(offset);
        InputStream is = Channels.newInputStream(raf.getChannel());
        BufferedInputStream bis = new BufferedInputStream(is);
        MZXMLMultiSpectraParser parser = source.getSpectraParser(
            bis, LCMSDataSubset.STRUCTURE_ONLY, source.getReaderPool(), 1);
  
        length = parser.findThisStreamFirstScanLen();
        is.close();
      } catch (IOException e) {
        throw new FileParsingException(e);
      } finally {
        source.close();
      }
      return length;
    }
docs: Finds the length of a scan entry in the original file by reading it, starting at the provided
  offset and looking for an "end of scan" tag.
  <b>Note that the {@code} source must be closed prior to calling this method.</b>
  
  @param offset offset in the file, where to start reading
  @return -1 if no end of scan was found