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

Tilman Hausherr commented on PDFBOX-4554:
-----------------------------------------

I intend to replace {{getSignedContent()}} with a more efficient 
implementation, because {{COSFilterInputStream}} does many reading loops after 
the last (used) byte is read:
{code}
public byte[] getSignedContent(byte[] pdfFile) throws IOException
{
    int[] byteRange = getByteRange();
    int length = 0;
    for (int i = 0; i < byteRange.length / 2; ++i)
    {
        length += byteRange[i * 2 + 1];
    }
    byte[] ba = new byte[length];
    int destPos = 0;
    for (int i = 0; i < byteRange.length / 2; ++i)
    {
        System.arraycopy(pdfFile, byteRange[i * 2], ba, destPos, byteRange[i * 
2 + 1]);
        destPos += byteRange[i * 2 + 1];
    }
    return ba;
}
{code}
If you still insist on the (wrong) idea that you have to pass a start and 
length to {{getSignedContent()}}, then adjust the code above to whatever you 
think is needed.

> operations taking a byte[] need to allow for offset and length too
> ------------------------------------------------------------------
>
>                 Key: PDFBOX-4554
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4554
>             Project: PDFBox
>          Issue Type: Improvement
>            Reporter: Jason Pyeron
>            Priority: Major
>
> Without this, massive amounts of memory must be copied/allocated to "trim" 
> byte[].
> See forthcoming pull request.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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

Reply via email to