Example usage for com.lowagie.text.pdf PRTokeniser readLineSegment

List of usage examples for com.lowagie.text.pdf PRTokeniser readLineSegment

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PRTokeniser readLineSegment.

Prototype

public boolean readLineSegment(byte input[]) throws IOException 

Source Link

Usage

From source file:org.signserver.module.pdfsigner.PDFSigner.java

License:Open Source License

private void checkForDuplicateObjects(byte[] pdfbytes) throws IOException, SignServerException {
    if (LOG.isDebugEnabled()) {
        LOG.debug(">checkForDuplicateObjects");
    }//from   w  ww .  j a v  a 2 s . c o  m
    final PRTokeniser tokens = new PRTokeniser(pdfbytes);
    final Set<String> idents = new HashSet<String>();
    final byte[] line = new byte[16];

    while (tokens.readLineSegment(line)) {
        final int[] obj = PRTokeniser.checkObjectStart(line);
        if (obj != null) {
            final String ident = obj[0] + " " + obj[1];

            if (idents.add(ident)) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Object: " + ident);
                }
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Duplicate object: " + ident);
                }
                throw new SignServerException("Incorrect document");
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<checkForDuplicateObjects");
    }
}