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

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

Introduction

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

Prototype

public static int[] checkObjectStart(byte line[]) 

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");
    }//w  w w  . ja  va 2  s .co 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");
    }
}