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/05/23 12:04:47 UTC
svn commit: r1878057 - in /pdfbox/trunk/pdfbox/src:
main/java/org/apache/pdfbox/io/RandomAccessBufferedFile.java
test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java
Author: lehmi
Date: Sat May 23 12:04:47 2020
New Revision: 1878057
URL: http://svn.apache.org/viewvc?rev=1878057&view=rev
Log:
PDFBOX-4842: remove usage of an InputStream as source for a RandomAccessBufferedFile
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBufferedFile.java
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBufferedFile.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBufferedFile.java?rev=1878057&r1=1878056&r2=1878057&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBufferedFile.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBufferedFile.java Sat May 23 12:04:47 2020
@@ -17,9 +17,7 @@
package org.apache.pdfbox.io;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.RandomAccessFile;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -34,16 +32,10 @@ import java.util.Map;
*/
public class RandomAccessBufferedFile implements RandomAccessRead
{
- /**
- * The prefix for the temp file being used.
- */
- private static final String TMP_FILE_PREFIX = "tmpPDFBox";
-
private int pageSizeShift = 12;
private int pageSize = 1 << pageSizeShift;
private long pageOffsetMask = -1L << pageSizeShift;
private int maxCachedPages = 1000;
- private File tempFile;
private byte[] lastRemovedCachePage = null;
@@ -98,45 +90,6 @@ public class RandomAccessBufferedFile im
seek(0);
}
- /**
- * Create a random access buffered file for the given input stream by copying the data to a temporary file.
- *
- * @param input the input stream to be read. It will be closed by this method.
- * @throws IOException if something went wrong while creating the temporary file.
- */
- public RandomAccessBufferedFile( InputStream input ) throws IOException
- {
- tempFile = createTmpFile(input);
- fileLength = tempFile.length();
- raFile = new RandomAccessFile(tempFile, "r");
- seek(0);
- }
-
- private File createTmpFile(InputStream input) throws IOException
- {
- File tmpFile = File.createTempFile(TMP_FILE_PREFIX, ".pdf");
- try (FileOutputStream fos = new FileOutputStream(tmpFile))
- {
- IOUtils.copy(input, fos);
- return tmpFile;
- }
- finally
- {
- IOUtils.closeQuietly(input);
- }
- }
-
- /**
- * Remove the temporary file. A temporary file is created if this class is instantiated with an InputStream
- */
- private void deleteTempFile()
- {
- if (tempFile != null)
- {
- tempFile.delete();
- }
- }
-
/** Returns offset in file at which next byte would be read. */
@Override
public long getPosition()
@@ -272,7 +225,6 @@ public class RandomAccessBufferedFile im
public void close() throws IOException
{
raFile.close();
- deleteTempFile();
pageCache.clear();
isClosed = true;
}
@@ -303,7 +255,6 @@ public class RandomAccessBufferedFile im
@Override
public boolean isEOF() throws IOException
{
- int peek = peek();
- return peek == -1;
+ return peek() == -1;
}
}
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java?rev=1878057&r1=1878056&r2=1878057&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java Sat May 23 12:04:47 2020
@@ -96,24 +96,12 @@ public class TestPDFParser
}
@Test
- public void testPDFParserInputStream() throws IOException
- {
- executeParserTest(new RandomAccessBufferedFile(new FileInputStream(PATH_OF_PDF)), MemoryUsageSetting.setupMainMemoryOnly());
- }
-
- @Test
public void testPDFParserFileScratchFile() throws IOException
{
executeParserTest(new RandomAccessBufferedFile(new File(PATH_OF_PDF)), MemoryUsageSetting.setupTempFileOnly());
}
@Test
- public void testPDFParserInputStreamScratchFile() throws IOException
- {
- executeParserTest(new RandomAccessBufferedFile(new FileInputStream(PATH_OF_PDF)), MemoryUsageSetting.setupTempFileOnly());
- }
-
- @Test
public void testPDFParserMissingCatalog() throws IOException, URISyntaxException
{
// PDFBOX-3060