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 2022/08/02 05:21:02 UTC

svn commit: r1903180 - /pdfbox/trunk/io/src/main/java/org/apache/pdfbox/io/RandomAccessReadBuffer.java

Author: lehmi
Date: Tue Aug  2 05:21:02 2022
New Revision: 1903180

URL: http://svn.apache.org/viewvc?rev=1903180&view=rev
Log:
PDFBOX-5483: add new method to create a RandomAccessReadBuffer using a given InputStream

Modified:
    pdfbox/trunk/io/src/main/java/org/apache/pdfbox/io/RandomAccessReadBuffer.java

Modified: pdfbox/trunk/io/src/main/java/org/apache/pdfbox/io/RandomAccessReadBuffer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/io/src/main/java/org/apache/pdfbox/io/RandomAccessReadBuffer.java?rev=1903180&r1=1903179&r2=1903180&view=diff
==============================================================================
--- pdfbox/trunk/io/src/main/java/org/apache/pdfbox/io/RandomAccessReadBuffer.java (original)
+++ pdfbox/trunk/io/src/main/java/org/apache/pdfbox/io/RandomAccessReadBuffer.java Tue Aug  2 05:21:02 2022
@@ -364,4 +364,26 @@ public class RandomAccessReadBuffer impl
                 streamLength, true);
     }
 
+    /**
+     * Create e new RandomAccessReadBuffer using the given InputStream. The data is copied to the memory and the
+     * InputStream is closed.
+     * 
+     * @param inputStream the InputStream holding the data to be copied
+     * 
+     * @return the RandomAccessReadBufer holding the data of the InputStream
+     * @throws IOException if something went wrong while copying the data
+     */
+    public static RandomAccessReadBuffer createBufferFromStream(InputStream inputStream) throws IOException
+    {
+        RandomAccessReadBuffer randomAccessRead = null;
+        try
+        {
+            randomAccessRead = new RandomAccessReadBuffer(inputStream);
+        }
+        finally
+        {
+            inputStream.close();
+        }
+        return randomAccessRead;
+    }
 }