Hi,
thank you. I'm happy to hear that there is no bug.
I think the section about MemoyUsageSetting in the migration guide for 3.0
could profit from examples. It could show that you can either use the
convenience methods, e.g.
try (PDDocument pdDocument = Loader.loadPDF(new
RandomAccessReadBufferedFile("yourfile.pdf"),
IOUtils.createMemoryOnlyStreamCache())) {
...
}
or you can configure the MemoryUsageSettings yourself as in
MemoryUsageSetting limitMainMemory = MemoryUsageSetting.setupMainMemoryOnly(10
* 1024 * 1024L);
try (PDDocument pdDocument = Loader.loadPDF(new
RandomAccessReadBufferedFile("yourfile.pdf"), limitMainMemory.streamCache)) {
...
}
> -----Ursprüngliche Nachricht-----
> Von: Andreas Lehmkühler [mailto:[email protected]]
> Gesendet: Samstag, 19. August 2023 11:24
> An: [email protected]
> Betreff: Re: [ANNOUNCE] Apache PDFBox 3.0.0 released
>
> Hi,
>
> @Erik thanks for the report but I guess there is a misunderstanding, see
> inline
>
> Am 18.08.23 um 11:32 schrieb Brangs, Erik:
> > Hi,
> >
> >> -----Ursprüngliche Nachricht-----
> >> Von: Andreas Lehmkühler [mailto:[email protected]]
> >> Gesendet: Freitag, 18. August 2023 07:42
> >> An: [email protected]
> >> Betreff: [ANNOUNCE] Apache PDFBox 3.0.0 released
> >>
> >> The Apache PDFBox community is pleased to announce the release of Apache
> >> PDFBox 3.0.0. It is available for download at:
> >>
> >> https://pdfbox.apache.org/download.html
> >>
> >> [...]
> >>
> >> A migration guide is available at
> >>
> >> https://pdfbox.apache.org/3.0/migration.html.
> >>
> >> It is still a work in progress and we are happy to include any valuable
> >> feedback from our community.
> >
> > I was going to suggest to update the documentation to say that you can use
> > the
> streamCache field of MemoryUsageSetting rather than using IOUtils. However,
> I've
> looked at the code of MemoryUsageSetting and I'm not actually sure if that's
> correct.
> >
> > I think there's a bug in MemoryUsageSetting: The comment for streamCache
> > says
> that it creates "an instance of ScratchFile using the current settings".
> However, the line
> >
> > public final StreamCacheCreateFunction streamCache = () -> new
> > ScratchFile(this);
> This is a functional interface. No instance of ScratchFile is created
> when creating an instance of MemoryUsageSetting. It is created once the
> functional interface is used.
>
> > is executed at the start of the constructor of MemoryUsageSetting before the
> instance variables have been set. At least that's what the bytecode output
> from javap
> -c -p says:
> >
> > private org.apache.pdfbox.io.MemoryUsageSetting(boolean, boolean, long,
> > long);
> > Code:
> > 0: aload_0
> > 1: invokespecial #1 // Method
> > java/lang/Object."<init>":()V
> > 4: aload_0
> > 5: aload_0
> > 6: invokedynamic #2, 0 // InvokeDynamic
> #0:create:(Lorg/apache/pdfbox/io/MemoryUsageSetting;)Lorg/apache/pdfbox/io/Rand
> omAccessStreamCache$StreamCacheCreateFunction;
> > 11: putfield #3 // Field
> streamCache:Lorg/apache/pdfbox/io/RandomAccessStreamCache$StreamCacheCreate
> Function;
> > 14: iload_2
> >
> I can't read the byte code but I've double checked the behaviour when
> debbugging one of our test cases
>
> org.apache.pdfbox.multipdf.PDFMergerUtilityTest.testJpegCcitt()
>
> Fortunately everthing is fine ;-)
>
> Andreas
>
> > I think the initialization of ScratchFile needs to happen at the end of the
> > constructor
> if the settings are supposed to be used.
>
>
>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]