You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2017/12/09 19:05:04 UTC

[jira] [Comment Edited] (PDFBOX-4028) SaveIncremental on same opened file

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

Tilman Hausherr edited comment on PDFBOX-4028 at 12/9/17 7:04 PM:
------------------------------------------------------------------

I looked at the "bad" result file, and it starts with content that belongs to position 4898816. That number is 2^14 * 13 * 23.

2^14 = 16384 which is a typical buffer size.

My theory is that something goes wrong while reading a RandomAccessFile and writing a FileOutputStream. I've tried to simplify the code in COSWriter to this:
{code}
    private void doWriteIncrement() throws IOException
    {
        ByteArrayOutputStream baos = (ByteArrayOutputStream) output; // that's the incremental part

        IOUtils.copy(new RandomAccessInputStream(incrementalInput), incrementalOutput);
        incrementalOutput.write(baos.toByteArray());
    }
{code}
and it still happened. Even if I read from incrementalInput directly and wrote into incrementalOutput and took care to seek in between, it still happened.


was (Author: tilman):
I looked at the "bad" result file, and it starts with content that belongs to position 4898816. That number is 2^14 * 13 * 13.

2^14 = 16384 which is a typical buffer size.

My theory is that something goes wrong while reading a RandomAccessFile and writing a FileOutputStream. I've tried to simplify the code in COSWriter to this:
{code}
    private void doWriteIncrement() throws IOException
    {
        ByteArrayOutputStream baos = (ByteArrayOutputStream) output; // that's the incremental part

        IOUtils.copy(new RandomAccessInputStream(incrementalInput), incrementalOutput);
        incrementalOutput.write(baos.toByteArray());
    }
{code}
and it still happened. Even if I read from incrementalInput directly and wrote into incrementalOutput and took care to seek in between, it still happened.

> SaveIncremental on same opened file
> -----------------------------------
>
>                 Key: PDFBOX-4028
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4028
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Writing
>    Affects Versions: 2.0.8
>            Reporter: Martin Mancuska
>         Attachments: pdf_reference_1-7.pdf
>
>
> The incremental save does not work correctly if it is done on the same opened document. It produces corrupted file. The save incremental should append changes at the end of file (after last origin EOF).
> Newly saved file contains changes also in the middle of the file not only at the end. Changes in the middle of file contains zeroed bytes or garbage. 
> Tested with the latest stable version of PDFBox 2.0.8.
>  
> Sample code:
> {code:java}
> String fileName = "/path/to/document.pdf";
> PDDocument doc = PDDocument.load((new File(fileName));
> ...
> document changes
> ...
> try ( OutputStream outStream = new FileOutputStream(fileName)) {
> 	doc.saveIcremental(outStream);
> }
> catch ....
> ...
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org