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

Jason Pyeron commented on PDFBOX-4554:
--------------------------------------

Example:

There is a single byte[], in it are subsections (offset/length) - these are 
large. 

Every operation that cannot take an offset and length require:
{code:java}
byte[] data=new byte[baseTargetLength];
System.arraycopy(baseData, baseOffset, data, 0, baseTargetLength);
{code}
This is very wasteful when the ByteArrayInputStream can take an offset and 
length. When looking at the patch, it adds the required signature to the 
COSFilterInputStream and getSignedContent:
{code:java|title=COSFilterInputStream.java}
public COSFilterInputStream(byte[] in, int offset, int length, int[] byteRange)
{
   super(new ByteArrayInputStream(in, offset, length));
   this.byteRange = byteRange;
}
{code}
and
{code:java|title=PDSignature.java}
public byte[] getSignedContent(byte[] pdfFile, int offset, int length) throws 
IOException
{
   try (COSFilterInputStream fis = new COSFilterInputStream(pdfFile, offset, 
length, getByteRange()))
   {
      return fis.toByteArray();
   }
}
{code}

> 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