[ 
https://issues.apache.org/jira/browse/PDFBOX-3514?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15529264#comment-15529264
 ] 

simon steiner edited comment on PDFBOX-3514 at 9/28/16 10:59 AM:
-----------------------------------------------------------------

maybe use
{code}
    public static String getDictionaryHash(COSBase base) throws IOException {
        if (base instanceof COSDictionary) {
            StringBuilder sb = new StringBuilder();
            for (Map.Entry<COSName, COSBase> x : ((COSDictionary) 
base).entrySet()) {
                sb.append(x.getKey());
                sb.append(":");
                sb.append(getDictionaryHash(x.getValue()));
                sb.append(";");
            }
            if (base instanceof COSStream) {
                InputStream stream = ((COSStream)base).getFilteredStream();
                byte[] b = IOUtils.toByteArray(stream);
                sb.append("COSStream{").append(Arrays.hashCode(b)).append("}");
            }
            return sb.toString();
        } else if (base instanceof COSObject) {
            COSObject obj = (COSObject) base;
            return obj.getObjectNumber().intValue() + " " + 
obj.getGenerationNumber().intValue();
        } else {
            return base.toString();
        }
    }
{code}


was (Author: ssteiner1):
maybe use

    public static String getDictionaryHash(COSBase base) throws IOException {
        if (base instanceof COSDictionary) {
            StringBuilder sb = new StringBuilder();
            for (Map.Entry<COSName, COSBase> x : ((COSDictionary) 
base).entrySet()) {
                sb.append(x.getKey());
                sb.append(":");
                sb.append(getDictionaryHash(x.getValue()));
                sb.append(";");
            }
            if (base instanceof COSStream) {
                InputStream stream = ((COSStream)base).getFilteredStream();
                byte[] b = IOUtils.toByteArray(stream);
                sb.append("COSStream{").append(Arrays.hashCode(b)).append("}");
            }
            return sb.toString();
        } else if (base instanceof COSObject) {
            COSObject obj = (COSObject) base;
            return obj.getObjectNumber().intValue() + " " + 
obj.getGenerationNumber().intValue();
        } else {
            return base.toString();
        }
    }

> Stackoverflow exception
> -----------------------
>
>                 Key: PDFBOX-3514
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3514
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Parsing
>    Affects Versions: 2.0.3
>            Reporter: simon steiner
>
> pdf from PDFBOX-1365
>         PDDocument x = PDDocument.load(new File("out_PDFA.pdf"));
>         x.getPage(0).getCOSObject().toString();
>         x.close();



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to