You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2020/06/07 12:05:15 UTC

svn commit: r1878562 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/Loader.java

Author: lehmi
Date: Sun Jun  7 12:05:15 2020
New Revision: 1878562

URL: http://svn.apache.org/viewvc?rev=1878562&view=rev
Log:
PDFBOX-4836: use RandomAccessReadBuffer instead of a ScratchFile for the input if MainMemoryOnly is configured

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/Loader.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/Loader.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/Loader.java?rev=1878562&r1=1878561&r2=1878562&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/Loader.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/Loader.java Sun Jun  7 12:05:15 2020
@@ -440,10 +440,20 @@ public class Loader
     public static PDDocument loadPDF(InputStream input, String password, InputStream keyStore,
             String alias, MemoryUsageSetting memUsageSetting) throws IOException
     {
-        ScratchFile scratchFile = new ScratchFile(memUsageSetting);
+        ScratchFile scratchFile = null;
         try
         {
-            RandomAccessRead source = scratchFile.createBuffer(input);
+            RandomAccessRead source;
+            if (memUsageSetting.useMainMemory() && !memUsageSetting.isMainMemoryRestricted())
+            {
+                // use RandomAccessReadBuffer instead of a ScratchFile for the input if MainMemoryOnly is configured
+                source = new RandomAccessReadBuffer(input);
+            }
+            else
+            {
+                scratchFile = new ScratchFile(memUsageSetting);
+                source = scratchFile.createBuffer(input);
+            }
             PDFParser parser = new PDFParser(source, password, keyStore, alias, scratchFile);
             return parser.parse();
         }