Author: tilman
Date: Sat Sep  2 11:10:39 2023
New Revision: 1912053

URL: http://svn.apache.org/viewvc?rev=1912053&view=rev
Log:
PDFBOX-5669: use JDK 11 built-in methods, as suggested by Axel Howind

Modified:
    
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
    
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/fontencodingpane/Type0Font.java
    
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/streampane/StreamPane.java
    pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/Tree.java
    
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java
    
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/TSAClient.java
    
pdfbox/trunk/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java
    
pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/RandomAccessReadDataStream.java
    pdfbox/trunk/io/src/test/java/org/apache/pdfbox/io/TestIOUtils.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1FontEmbedder.java
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/JPEGFactory.java
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/COSFilterInputStream.java
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDXFAResource.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSStream.java
    
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java
    
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObjectTest.java
    
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PNGConverterTest.java

Modified: 
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- 
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java 
(original)
+++ 
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java 
Sat Sep  2 11:10:39 2023
@@ -1229,7 +1229,7 @@ public class PDFDebugger extends JFrame
                 COSStream stream = (COSStream) selectedNode;
                 try (InputStream in = stream.createInputStream())
                 {
-                    return new String(IOUtils.toByteArray(in));
+                    return new String(in.readAllBytes());
                 }
             }
             catch( IOException e )

Modified: 
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/fontencodingpane/Type0Font.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/fontencodingpane/Type0Font.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- 
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/fontencodingpane/Type0Font.java
 (original)
+++ 
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/fontencodingpane/Type0Font.java
 Sat Sep  2 11:10:39 2023
@@ -117,7 +117,7 @@ class Type0Font extends FontPane
         if (stream != null)
         {
             InputStream is = stream.createInputStream();
-            byte[] mapAsBytes = IOUtils.toByteArray(is);
+            byte[] mapAsBytes = is.readAllBytes();
             IOUtils.closeQuietly(is);
             int numberOfInts = mapAsBytes.length / 2;
             cid2gid = new Object[numberOfInts][4];
@@ -154,4 +154,4 @@ class Type0Font extends FontPane
         panel.setPreferredSize(new Dimension(300, 500));
         return panel;
     }
-}
\ No newline at end of file
+}

Modified: 
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/streampane/StreamPane.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/streampane/StreamPane.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- 
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/streampane/StreamPane.java
 (original)
+++ 
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/streampane/StreamPane.java
 Sat Sep  2 11:10:39 2023
@@ -264,7 +264,7 @@ public class StreamPane implements Actio
                 JOptionPane.showMessageDialog(panel, command + " text not 
available (filter missing?)");
                 return;
             }
-            hexView.changeData(IOUtils.toByteArray(is));
+            hexView.changeData(is.readAllBytes());
         }
     }
 
@@ -407,7 +407,7 @@ public class StreamPane implements Actio
             PDFStreamParser parser;
             try
             {
-                parser = new PDFStreamParser(IOUtils.toByteArray(inputStream));
+                parser = new PDFStreamParser(inputStream.readAllBytes());
                 parser.parse().forEach(obj -> writeToken(obj, docu));
             }
             catch (IOException e)
@@ -581,4 +581,4 @@ public class StreamPane implements Actio
             }
         }
     }
-}
\ No newline at end of file
+}

Modified: 
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/Tree.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/Tree.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/Tree.java 
(original)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/Tree.java 
Sat Sep  2 11:10:39 2023
@@ -168,7 +168,8 @@ public class Tree extends JTree
         {
             try
             {
-                byte[] bytes = 
IOUtils.toByteArray(cosStream.createRawInputStream());
+                InputStream in = cosStream.createRawInputStream();
+                byte[] bytes = in.readAllBytes();
                 saveStream(bytes, null, null);
             }
             catch (IOException e)
@@ -246,7 +247,8 @@ public class Tree extends JTree
         {
             try
             {
-                byte[] bytes = 
IOUtils.toByteArray(cosStream.createInputStream());
+                InputStream in = cosStream.createInputStream();
+                byte[] bytes = in.readAllBytes();
                 saveStream(bytes, fileFilter, extension);
             }
             catch (IOException e)
@@ -350,7 +352,7 @@ public class Tree extends JTree
             try
             {
                 InputStream data = stream.createInputStream(stopFilters);
-                saveStream(IOUtils.toByteArray(data), null, null);
+                saveStream(data.readAllBytes(), null, null);
             }
             catch (IOException e)
             {

Modified: 
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- 
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java
 (original)
+++ 
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java
 Sat Sep  2 11:10:39 2023
@@ -55,7 +55,6 @@ import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.cos.COSString;
 import 
org.apache.pdfbox.examples.signature.cert.CertificateVerificationException;
 import org.apache.pdfbox.examples.signature.cert.CertificateVerifier;
-import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.io.RandomAccessReadBufferedFile;
 import org.apache.pdfbox.pdfparser.PDFParser;
 import org.apache.pdfbox.pdmodel.PDDocument;
@@ -666,7 +665,7 @@ public final class ShowSignature
                 COSStream cosStream = (COSStream) streamObj.getObject();
                 try (InputStream is = cosStream.createInputStream())
                 {
-                    byte[] streamBytes = IOUtils.toByteArray(is);
+                    byte[] streamBytes = is.readAllBytes();
                     System.out.println(description + " (" + 
elements.indexOf(streamObj) + "): "
                         + Hex.getString(streamBytes));
                 }

Modified: 
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/TSAClient.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/TSAClient.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- 
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/TSAClient.java
 (original)
+++ 
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/TSAClient.java
 Sat Sep  2 11:10:39 2023
@@ -1,185 +1,184 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.examples.signature;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.math.BigInteger;
-import java.net.URL;
-import java.net.URLConnection;
-import java.nio.charset.StandardCharsets;
-import java.security.DigestInputStream;
-import java.security.MessageDigest;
-import java.security.SecureRandom;
-import java.util.Base64;
-import java.util.Random;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.pdfbox.io.IOUtils;
-import org.bouncycastle.asn1.ASN1ObjectIdentifier;
-import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder;
-import org.bouncycastle.operator.DigestAlgorithmIdentifierFinder;
-import org.bouncycastle.tsp.TSPException;
-import org.bouncycastle.tsp.TimeStampRequest;
-import org.bouncycastle.tsp.TimeStampRequestGenerator;
-import org.bouncycastle.tsp.TimeStampResponse;
-import org.bouncycastle.tsp.TimeStampToken;
-
-/**
- * Time Stamping Authority (TSA) Client [RFC 3161].
- * @author Vakhtang Koroghlishvili
- * @author John Hewson
- */
-public class TSAClient
-{
-    private static final Log LOG = LogFactory.getLog(TSAClient.class);
-
-    private static final DigestAlgorithmIdentifierFinder ALGORITHM_OID_FINDER =
-            new DefaultDigestAlgorithmIdentifierFinder();
-
-    private final URL url;
-    private final String username;
-    private final String password;
-    private final MessageDigest digest;
-
-    // SecureRandom.getInstanceStrong() would be better, but sometimes blocks 
on Linux
-    private static final Random RANDOM = new SecureRandom();
-
-    /**
-     *
-     * @param url the URL of the TSA service
-     * @param username user name of TSA
-     * @param password password of TSA
-     * @param digest the message digest to use
-     */
-    public TSAClient(URL url, String username, String password, MessageDigest 
digest)
-    {
-        this.url = url;
-        this.username = username;
-        this.password = password;
-        this.digest = digest;
-    }
-
-    /**
-     *
-     * @param content
-     * @return the time stamp token
-     * @throws IOException if there was an error with the connection or data 
from the TSA server,
-     *                     or if the time stamp response could not be validated
-     */
-    public TimeStampToken getTimeStampToken(InputStream content) throws 
IOException
-    {
-        digest.reset();
-        DigestInputStream dis = new DigestInputStream(content, digest);
-        while (dis.read() != -1)
-        {
-            // do nothing
-        }
-        byte[] hash = digest.digest();
-
-        // 32-bit cryptographic nonce
-        int nonce = RANDOM.nextInt();
-
-        // generate TSA request
-        TimeStampRequestGenerator tsaGenerator = new 
TimeStampRequestGenerator();
-        tsaGenerator.setCertReq(true);
-        ASN1ObjectIdentifier oid = 
ALGORITHM_OID_FINDER.find(digest.getAlgorithm()).getAlgorithm();
-        TimeStampRequest request = tsaGenerator.generate(oid, hash, 
BigInteger.valueOf(nonce));
-
-        // get TSA response
-        byte[] tsaResponse = getTSAResponse(request.getEncoded());
-
-        TimeStampResponse response;
-        try
-        {
-            response = new TimeStampResponse(tsaResponse);
-            response.validate(request);
-        }
-        catch (TSPException e)
-        {
-            throw new IOException(e);
-        }
-
-        TimeStampToken timeStampToken = response.getTimeStampToken();
-        if (timeStampToken == null)
-        {
-            // https://www.ietf.org/rfc/rfc3161.html#section-2.4.2
-            throw new IOException("Response from " + url +
-                    " does not have a time stamp token, status: " + 
response.getStatus() +
-                    " (" + response.getStatusString() + ")");
-        }
-
-        return timeStampToken;
-    }
-
-    // gets response data for the given encoded TimeStampRequest data
-    // throws IOException if a connection to the TSA cannot be established
-    private byte[] getTSAResponse(byte[] request) throws IOException
-    {
-        LOG.debug("Opening connection to TSA server");
-
-        // todo: support proxy servers
-        URLConnection connection = url.openConnection();
-        connection.setDoOutput(true);
-        connection.setDoInput(true);
-        connection.setRequestProperty("Content-Type", 
"application/timestamp-query");
-
-        LOG.debug("Established connection to TSA server");
-
-        if (username != null && password != null && !username.isEmpty() && 
!password.isEmpty())
-        {
-            String contentEncoding = connection.getContentEncoding();
-            if (contentEncoding == null)
-            {
-                contentEncoding = StandardCharsets.UTF_8.name();
-            }
-            connection.setRequestProperty("Authorization", 
-                    "Basic " + new String(Base64.getEncoder().encode((username 
+ ":" + password).
-                            getBytes(contentEncoding))));
-        }
-
-        // read response
-        try (OutputStream output = connection.getOutputStream())
-        {
-            output.write(request);
-        }
-        catch (IOException ex)
-        {
-            LOG.error("Exception when writing to " + this.url, ex);
-            throw ex;
-        }
-
-        LOG.debug("Waiting for response from TSA server");
-
-        byte[] response;
-        try (InputStream input = connection.getInputStream())
-        {
-            response = IOUtils.toByteArray(input);
-        }
-        catch (IOException ex)
-        {
-            LOG.error("Exception when reading from " + this.url, ex);
-            throw ex;
-        }
-
-        LOG.debug("Received response from TSA server");
-
-        return response;
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.examples.signature;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.math.BigInteger;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.charset.StandardCharsets;
+import java.security.DigestInputStream;
+import java.security.MessageDigest;
+import java.security.SecureRandom;
+import java.util.Base64;
+import java.util.Random;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.bouncycastle.asn1.ASN1ObjectIdentifier;
+import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder;
+import org.bouncycastle.operator.DigestAlgorithmIdentifierFinder;
+import org.bouncycastle.tsp.TSPException;
+import org.bouncycastle.tsp.TimeStampRequest;
+import org.bouncycastle.tsp.TimeStampRequestGenerator;
+import org.bouncycastle.tsp.TimeStampResponse;
+import org.bouncycastle.tsp.TimeStampToken;
+
+/**
+ * Time Stamping Authority (TSA) Client [RFC 3161].
+ * @author Vakhtang Koroghlishvili
+ * @author John Hewson
+ */
+public class TSAClient
+{
+    private static final Log LOG = LogFactory.getLog(TSAClient.class);
+
+    private static final DigestAlgorithmIdentifierFinder ALGORITHM_OID_FINDER =
+            new DefaultDigestAlgorithmIdentifierFinder();
+
+    private final URL url;
+    private final String username;
+    private final String password;
+    private final MessageDigest digest;
+
+    // SecureRandom.getInstanceStrong() would be better, but sometimes blocks 
on Linux
+    private static final Random RANDOM = new SecureRandom();
+
+    /**
+     *
+     * @param url the URL of the TSA service
+     * @param username user name of TSA
+     * @param password password of TSA
+     * @param digest the message digest to use
+     */
+    public TSAClient(URL url, String username, String password, MessageDigest 
digest)
+    {
+        this.url = url;
+        this.username = username;
+        this.password = password;
+        this.digest = digest;
+    }
+
+    /**
+     *
+     * @param content
+     * @return the time stamp token
+     * @throws IOException if there was an error with the connection or data 
from the TSA server,
+     *                     or if the time stamp response could not be validated
+     */
+    public TimeStampToken getTimeStampToken(InputStream content) throws 
IOException
+    {
+        digest.reset();
+        DigestInputStream dis = new DigestInputStream(content, digest);
+        while (dis.read() != -1)
+        {
+            // do nothing
+        }
+        byte[] hash = digest.digest();
+
+        // 32-bit cryptographic nonce
+        int nonce = RANDOM.nextInt();
+
+        // generate TSA request
+        TimeStampRequestGenerator tsaGenerator = new 
TimeStampRequestGenerator();
+        tsaGenerator.setCertReq(true);
+        ASN1ObjectIdentifier oid = 
ALGORITHM_OID_FINDER.find(digest.getAlgorithm()).getAlgorithm();
+        TimeStampRequest request = tsaGenerator.generate(oid, hash, 
BigInteger.valueOf(nonce));
+
+        // get TSA response
+        byte[] tsaResponse = getTSAResponse(request.getEncoded());
+
+        TimeStampResponse response;
+        try
+        {
+            response = new TimeStampResponse(tsaResponse);
+            response.validate(request);
+        }
+        catch (TSPException e)
+        {
+            throw new IOException(e);
+        }
+
+        TimeStampToken timeStampToken = response.getTimeStampToken();
+        if (timeStampToken == null)
+        {
+            // https://www.ietf.org/rfc/rfc3161.html#section-2.4.2
+            throw new IOException("Response from " + url +
+                    " does not have a time stamp token, status: " + 
response.getStatus() +
+                    " (" + response.getStatusString() + ")");
+        }
+
+        return timeStampToken;
+    }
+
+    // gets response data for the given encoded TimeStampRequest data
+    // throws IOException if a connection to the TSA cannot be established
+    private byte[] getTSAResponse(byte[] request) throws IOException
+    {
+        LOG.debug("Opening connection to TSA server");
+
+        // todo: support proxy servers
+        URLConnection connection = url.openConnection();
+        connection.setDoOutput(true);
+        connection.setDoInput(true);
+        connection.setRequestProperty("Content-Type", 
"application/timestamp-query");
+
+        LOG.debug("Established connection to TSA server");
+
+        if (username != null && password != null && !username.isEmpty() && 
!password.isEmpty())
+        {
+            String contentEncoding = connection.getContentEncoding();
+            if (contentEncoding == null)
+            {
+                contentEncoding = StandardCharsets.UTF_8.name();
+            }
+            connection.setRequestProperty("Authorization", 
+                    "Basic " + new String(Base64.getEncoder().encode((username 
+ ":" + password).
+                            getBytes(contentEncoding))));
+        }
+
+        // read response
+        try (OutputStream output = connection.getOutputStream())
+        {
+            output.write(request);
+        }
+        catch (IOException ex)
+        {
+            LOG.error("Exception when writing to " + this.url, ex);
+            throw ex;
+        }
+
+        LOG.debug("Waiting for response from TSA server");
+
+        byte[] response;
+        try (InputStream input = connection.getInputStream())
+        {
+            response = input.readAllBytes();
+        }
+        catch (IOException ex)
+        {
+            LOG.error("Exception when reading from " + this.url, ex);
+            throw ex;
+        }
+
+        LOG.debug("Received response from TSA server");
+
+        return response;
+    }
+}

Modified: 
pdfbox/trunk/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- 
pdfbox/trunk/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java
 (original)
+++ 
pdfbox/trunk/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java
 Sat Sep  2 11:10:39 2023
@@ -599,7 +599,7 @@ class TestCreateSignature
                 // verify that all getContents() methods returns the same 
content
                 try (FileInputStream fis = new FileInputStream(signedFile))
                 {
-                    byte[] contents2 = 
sig.getContents(IOUtils.toByteArray(fis));
+                    byte[] contents2 = sig.getContents(((InputStream) 
fis).readAllBytes());
                     assertArrayEquals(contents, contents2);
                 }
                 byte[] contents3 = sig.getContents(new 
FileInputStream(signedFile));
@@ -659,7 +659,7 @@ class TestCreateSignature
     private String calculateDigestString(InputStream inputStream) throws 
NoSuchAlgorithmException, IOException
     {
         MessageDigest md = MessageDigest.getInstance("SHA-256");
-        return Hex.getString(md.digest(IOUtils.toByteArray(inputStream)));
+        return Hex.getString(md.digest(inputStream.readAllBytes()));
     }
 
     /**
@@ -953,7 +953,7 @@ class TestCreateSignature
                 COSStream certStream = (COSStream) sigCertArray.getObject(i);
                 try (InputStream is = certStream.createInputStream())
                 {
-                    sigCertHolderSetFromVRIArray.add(new 
X509CertificateHolder(IOUtils.toByteArray(is)));
+                    sigCertHolderSetFromVRIArray.add(new 
X509CertificateHolder(is.readAllBytes()));
                 }
             }
             for (X509CertificateHolder holder : certificateHolderSet)
@@ -1041,7 +1041,7 @@ class TestCreateSignature
                 X509CertificateHolder certHolder2;
                 try (InputStream is2 = certStream.createInputStream())
                 {
-                    certHolder2 = new 
X509CertificateHolder(IOUtils.toByteArray(is2));
+                    certHolder2 = new 
X509CertificateHolder(is2.readAllBytes());
                 }
                 
                 assertEquals(certHolder2, new 
X509CertificateHolder(crlIssuerCert.getEncoded()),
@@ -1082,7 +1082,7 @@ class TestCreateSignature
                 X509CertificateHolder certHolder2;
                 try (InputStream is2 = certStream.createInputStream())
                 {
-                    certHolder2 = new 
X509CertificateHolder(IOUtils.toByteArray(is2));
+                    certHolder2 = new 
X509CertificateHolder(is2.readAllBytes());
                 }
 
                 assertEquals(certHolder2, ocspCertHolder, "OCSP certificate is 
not in the VRI array");
@@ -1121,7 +1121,7 @@ class TestCreateSignature
             doc.setDocumentId(12345l);
             ExternalSigningSupport externalSigning = 
doc.saveIncrementalForExternalSigning(baos);
             // invoke external signature service
-            return IOUtils.toByteArray(externalSigning.getContent());
+            return externalSigning.getContent().readAllBytes();
         }
         finally
         {

Modified: 
pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/RandomAccessReadDataStream.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/RandomAccessReadDataStream.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- 
pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/RandomAccessReadDataStream.java
 (original)
+++ 
pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/RandomAccessReadDataStream.java
 Sat Sep  2 11:10:39 2023
@@ -20,7 +20,6 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.io.RandomAccessRead;
 
 /**
@@ -62,7 +61,7 @@ class RandomAccessReadDataStream extends
      */
     RandomAccessReadDataStream(InputStream inputStream) throws IOException
     {
-        data = IOUtils.toByteArray(inputStream);
+        data = inputStream.readAllBytes();
         length = data.length;
     }
 

Modified: pdfbox/trunk/io/src/test/java/org/apache/pdfbox/io/TestIOUtils.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/io/src/test/java/org/apache/pdfbox/io/TestIOUtils.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- pdfbox/trunk/io/src/test/java/org/apache/pdfbox/io/TestIOUtils.java 
(original)
+++ pdfbox/trunk/io/src/test/java/org/apache/pdfbox/io/TestIOUtils.java Sat Sep 
 2 11:10:39 2023
@@ -49,7 +49,7 @@ class TestIOUtils
         InputStream in = new ByteArrayInputStream(data);
         count = IOUtils.populateBuffer(in, buffer);
         assertEquals(10, count);
-        byte[] leftOver = IOUtils.toByteArray(in);
+        byte[] leftOver = in.readAllBytes();
         assertEquals(2, leftOver.length);
 
         buffer = new byte[data.length + 2]; //Buffer too big

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java 
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java 
Sat Sep  2 11:10:39 2023
@@ -32,7 +32,6 @@ import java.util.function.BiConsumer;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
 import org.apache.pdfbox.util.DateConverter;
 import org.apache.pdfbox.util.SmallMap;
@@ -1382,7 +1381,7 @@ public class COSDictionary extends COSBa
             {
                 try (InputStream stream = ((COSStream) 
base).createRawInputStream())
                 {
-                    byte[] b = IOUtils.toByteArray(stream);
+                    byte[] b = stream.readAllBytes();
                     
sb.append("COSStream{").append(Arrays.hashCode(b)).append("}");
                 }
             }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java 
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java Sat 
Sep  2 11:10:39 2023
@@ -364,7 +364,7 @@ public class COSStream extends COSDictio
     {
         try (InputStream input = createInputStream())
         {
-            byte[] array = IOUtils.toByteArray(input);
+            byte[] array = input.readAllBytes();
             COSString string = new COSString(array);
             return string.getString();
         }

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java
 Sat Sep  2 11:10:39 2023
@@ -406,7 +406,7 @@ public class PDStream implements COSObje
     {
         try (InputStream is = createInputStream())
         {
-            return IOUtils.toByteArray(is);
+            return is.readAllBytes();
         }
     }
     

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
 Sat Sep  2 11:10:39 2023
@@ -565,7 +565,8 @@ public abstract class SecurityHandler<T_
         {
             return;
         }
-        byte[] rawData = IOUtils.toByteArray(stream.createRawInputStream());
+        InputStream in = stream.createRawInputStream();
+        byte[] rawData = in.readAllBytes();
         ByteArrayInputStream encryptedStream = new 
ByteArrayInputStream(rawData);
         try (OutputStream output = stream.createRawOutputStream())
         {

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java 
(original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java 
Sat Sep  2 11:10:39 2023
@@ -402,7 +402,7 @@ public abstract class PDCIDFont implemen
         if (stream != null)
         {
             InputStream is = stream.createInputStream();
-            byte[] mapAsBytes = IOUtils.toByteArray(is);
+            byte[] mapAsBytes = is.readAllBytes();
             IOUtils.closeQuietly(is);
             int numberOfInts = mapAsBytes.length / 2;
             cid2gid = new int[numberOfInts];

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1FontEmbedder.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1FontEmbedder.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1FontEmbedder.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1FontEmbedder.java
 Sat Sep  2 11:10:39 2023
@@ -1,179 +1,178 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.pdmodel.font;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.fontbox.afm.FontMetrics;
-import org.apache.fontbox.encoding.BuiltInEncoding;
-import org.apache.fontbox.pfb.PfbParser;
-import org.apache.fontbox.type1.Type1Font;
-import org.apache.fontbox.util.BoundingBox;
-import org.apache.pdfbox.cos.COSArray;
-import org.apache.pdfbox.cos.COSDictionary;
-import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.io.IOUtils;
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.common.PDRectangle;
-import org.apache.pdfbox.pdmodel.common.PDStream;
-import org.apache.pdfbox.pdmodel.font.encoding.Encoding;
-import org.apache.pdfbox.pdmodel.font.encoding.GlyphList;
-import org.apache.pdfbox.pdmodel.font.encoding.Type1Encoding;
-
-/**
- * Embedded PDType1Font builder. Helper class to populate a PDType1Font from a 
PFB and AFM.
- *
- * @author Michael Niedermair
- */
-class PDType1FontEmbedder
-{
-    private final Encoding fontEncoding;
-    private final Type1Font type1;
-    
-    /**
-     * This will load a PFB to be embedded into a document.
-     *
-     * @param doc The PDF document that will hold the embedded font.
-     * @param dict The Font dictionary to write to.
-     * @param pfbStream The pfb input.
-     * @throws IOException If there is an error loading the data.
-     */
-    PDType1FontEmbedder(PDDocument doc, COSDictionary dict, InputStream 
pfbStream,
-                        Encoding encoding) throws IOException
-    {
-        dict.setItem(COSName.SUBTYPE, COSName.TYPE1);
-
-        // read the pfb
-        byte[] pfbBytes = IOUtils.toByteArray(pfbStream);
-        PfbParser pfbParser = new PfbParser(pfbBytes);
-        type1 = Type1Font.createWithPFB(pfbBytes);
-        
-        if (encoding == null)
-        {
-            fontEncoding = Type1Encoding.fromFontBox(type1.getEncoding());
-        }
-        else
-        {
-            fontEncoding = encoding;
-        }
-
-        // build font descriptor
-        PDFontDescriptor fd = buildFontDescriptor(type1);
-
-        PDStream fontStream = new PDStream(doc, pfbParser.getInputStream(), 
COSName.FLATE_DECODE);
-        fontStream.getCOSObject().setInt("Length", pfbParser.size());
-        for (int i = 0; i < pfbParser.getLengths().length; i++)
-        {
-            fontStream.getCOSObject().setInt("Length" + (i + 1), 
pfbParser.getLengths()[i]);
-        }
-        fd.setFontFile(fontStream);
-
-        // set the values
-        dict.setItem(COSName.FONT_DESC, fd);
-        dict.setName(COSName.BASE_FONT, type1.getName());
-
-        // widths
-        List<Integer> widths = new ArrayList<>(256);
-        for (int code = 0; code <= 255; code++)
-        {
-            String name = fontEncoding.getName(code);
-            int width = Math.round(type1.getWidth(name));
-            widths.add(width);
-        }
-        
-        dict.setInt(COSName.FIRST_CHAR, 0);
-        dict.setInt(COSName.LAST_CHAR, 255);
-        dict.setItem(COSName.WIDTHS, COSArray.ofCOSIntegers(widths));
-        dict.setItem(COSName.ENCODING, encoding);
-    }
-
-    /**
-     * Returns a PDFontDescriptor for the given PFB.
-     * 
-     * @throws IOException if the font bounding box isn't available
-     */
-    static PDFontDescriptor buildFontDescriptor(Type1Font type1) throws 
IOException
-    {
-        boolean isSymbolic = type1.getEncoding() instanceof BuiltInEncoding;
-        BoundingBox bbox = type1.getFontBBox();
-        PDFontDescriptor fd = new PDFontDescriptor();
-
-        fd.setFontName(type1.getName());
-        fd.setFontFamily(type1.getFamilyName());
-        fd.setNonSymbolic(!isSymbolic);
-        fd.setSymbolic(isSymbolic);
-        fd.setFontBoundingBox(new PDRectangle(bbox));
-        fd.setItalicAngle(type1.getItalicAngle());
-        fd.setAscent(bbox.getUpperRightY());
-        fd.setDescent(bbox.getLowerLeftY());
-        fd.setCapHeight(type1.getBlueValues().get(2).floatValue());
-        fd.setStemV(0); // for PDF/A
-        return fd;
-    }
-
-    /**
-     * Returns a PDFontDescriptor for the given AFM. Used only for Standard 14 
fonts.
-     *
-     * @param metrics AFM
-     */
-    static PDFontDescriptor buildFontDescriptor(FontMetrics metrics)
-    {
-        boolean isSymbolic = 
metrics.getEncodingScheme().equals("FontSpecific");
-
-        PDFontDescriptor fd = new PDFontDescriptor();
-        fd.setFontName(metrics.getFontName());
-        fd.setFontFamily(metrics.getFamilyName());
-        fd.setNonSymbolic(!isSymbolic);
-        fd.setSymbolic(isSymbolic);
-        fd.setFontBoundingBox(new PDRectangle(metrics.getFontBBox()));
-        fd.setItalicAngle(metrics.getItalicAngle());
-        fd.setAscent(metrics.getAscender());
-        fd.setDescent(metrics.getDescender());
-        fd.setCapHeight(metrics.getCapHeight());
-        fd.setXHeight(metrics.getXHeight());
-        fd.setAverageWidth(metrics.getAverageCharacterWidth());
-        fd.setCharacterSet(metrics.getCharacterSet());
-        fd.setStemV(0); // for PDF/A
-        return fd;
-    }
-    
-    /**
-     * Returns the font's encoding.
-     */
-    public Encoding getFontEncoding()
-    {
-        return fontEncoding;
-    }
-
-    /**
-     * Returns the font's glyph list.
-     */
-    public GlyphList getGlyphList()
-    {
-        return GlyphList.getAdobeGlyphList();
-    }
-
-    /**
-     * Returns the Type 1 font.
-     */
-    public Type1Font getType1Font()
-    {
-        return type1;
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel.font;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.fontbox.afm.FontMetrics;
+import org.apache.fontbox.encoding.BuiltInEncoding;
+import org.apache.fontbox.pfb.PfbParser;
+import org.apache.fontbox.type1.Type1Font;
+import org.apache.fontbox.util.BoundingBox;
+import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
+import org.apache.pdfbox.pdmodel.common.PDStream;
+import org.apache.pdfbox.pdmodel.font.encoding.Encoding;
+import org.apache.pdfbox.pdmodel.font.encoding.GlyphList;
+import org.apache.pdfbox.pdmodel.font.encoding.Type1Encoding;
+
+/**
+ * Embedded PDType1Font builder. Helper class to populate a PDType1Font from a 
PFB and AFM.
+ *
+ * @author Michael Niedermair
+ */
+class PDType1FontEmbedder
+{
+    private final Encoding fontEncoding;
+    private final Type1Font type1;
+    
+    /**
+     * This will load a PFB to be embedded into a document.
+     *
+     * @param doc The PDF document that will hold the embedded font.
+     * @param dict The Font dictionary to write to.
+     * @param pfbStream The pfb input.
+     * @throws IOException If there is an error loading the data.
+     */
+    PDType1FontEmbedder(PDDocument doc, COSDictionary dict, InputStream 
pfbStream,
+                        Encoding encoding) throws IOException
+    {
+        dict.setItem(COSName.SUBTYPE, COSName.TYPE1);
+
+        // read the pfb
+        byte[] pfbBytes = pfbStream.readAllBytes();
+        PfbParser pfbParser = new PfbParser(pfbBytes);
+        type1 = Type1Font.createWithPFB(pfbBytes);
+        
+        if (encoding == null)
+        {
+            fontEncoding = Type1Encoding.fromFontBox(type1.getEncoding());
+        }
+        else
+        {
+            fontEncoding = encoding;
+        }
+
+        // build font descriptor
+        PDFontDescriptor fd = buildFontDescriptor(type1);
+
+        PDStream fontStream = new PDStream(doc, pfbParser.getInputStream(), 
COSName.FLATE_DECODE);
+        fontStream.getCOSObject().setInt("Length", pfbParser.size());
+        for (int i = 0; i < pfbParser.getLengths().length; i++)
+        {
+            fontStream.getCOSObject().setInt("Length" + (i + 1), 
pfbParser.getLengths()[i]);
+        }
+        fd.setFontFile(fontStream);
+
+        // set the values
+        dict.setItem(COSName.FONT_DESC, fd);
+        dict.setName(COSName.BASE_FONT, type1.getName());
+
+        // widths
+        List<Integer> widths = new ArrayList<>(256);
+        for (int code = 0; code <= 255; code++)
+        {
+            String name = fontEncoding.getName(code);
+            int width = Math.round(type1.getWidth(name));
+            widths.add(width);
+        }
+        
+        dict.setInt(COSName.FIRST_CHAR, 0);
+        dict.setInt(COSName.LAST_CHAR, 255);
+        dict.setItem(COSName.WIDTHS, COSArray.ofCOSIntegers(widths));
+        dict.setItem(COSName.ENCODING, encoding);
+    }
+
+    /**
+     * Returns a PDFontDescriptor for the given PFB.
+     * 
+     * @throws IOException if the font bounding box isn't available
+     */
+    static PDFontDescriptor buildFontDescriptor(Type1Font type1) throws 
IOException
+    {
+        boolean isSymbolic = type1.getEncoding() instanceof BuiltInEncoding;
+        BoundingBox bbox = type1.getFontBBox();
+        PDFontDescriptor fd = new PDFontDescriptor();
+
+        fd.setFontName(type1.getName());
+        fd.setFontFamily(type1.getFamilyName());
+        fd.setNonSymbolic(!isSymbolic);
+        fd.setSymbolic(isSymbolic);
+        fd.setFontBoundingBox(new PDRectangle(bbox));
+        fd.setItalicAngle(type1.getItalicAngle());
+        fd.setAscent(bbox.getUpperRightY());
+        fd.setDescent(bbox.getLowerLeftY());
+        fd.setCapHeight(type1.getBlueValues().get(2).floatValue());
+        fd.setStemV(0); // for PDF/A
+        return fd;
+    }
+
+    /**
+     * Returns a PDFontDescriptor for the given AFM. Used only for Standard 14 
fonts.
+     *
+     * @param metrics AFM
+     */
+    static PDFontDescriptor buildFontDescriptor(FontMetrics metrics)
+    {
+        boolean isSymbolic = 
metrics.getEncodingScheme().equals("FontSpecific");
+
+        PDFontDescriptor fd = new PDFontDescriptor();
+        fd.setFontName(metrics.getFontName());
+        fd.setFontFamily(metrics.getFamilyName());
+        fd.setNonSymbolic(!isSymbolic);
+        fd.setSymbolic(isSymbolic);
+        fd.setFontBoundingBox(new PDRectangle(metrics.getFontBBox()));
+        fd.setItalicAngle(metrics.getItalicAngle());
+        fd.setAscent(metrics.getAscender());
+        fd.setDescent(metrics.getDescender());
+        fd.setCapHeight(metrics.getCapHeight());
+        fd.setXHeight(metrics.getXHeight());
+        fd.setAverageWidth(metrics.getAverageCharacterWidth());
+        fd.setCharacterSet(metrics.getCharacterSet());
+        fd.setStemV(0); // for PDF/A
+        return fd;
+    }
+    
+    /**
+     * Returns the font's encoding.
+     */
+    public Encoding getFontEncoding()
+    {
+        return fontEncoding;
+    }
+
+    /**
+     * Returns the font's glyph list.
+     */
+    public GlyphList getGlyphList()
+    {
+        return GlyphList.getAdobeGlyphList();
+    }
+
+    /**
+     * Returns the Type 1 font.
+     */
+    public Type1Font getType1Font()
+    {
+        return type1;
+    }
+}

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/JPEGFactory.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/JPEGFactory.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/JPEGFactory.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/JPEGFactory.java
 Sat Sep  2 11:10:39 2023
@@ -48,7 +48,6 @@ import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSInteger;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.filter.Filter;
-import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK;
@@ -81,7 +80,7 @@ public final class JPEGFactory
     public static PDImageXObject createFromStream(PDDocument document, 
InputStream stream)
             throws IOException
     {
-        return createFromByteArray(document, IOUtils.toByteArray(stream));
+        return createFromByteArray(document, stream.readAllBytes());
     }
 
     /**

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/COSFilterInputStream.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/COSFilterInputStream.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/COSFilterInputStream.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/COSFilterInputStream.java
 Sat Sep  2 11:10:39 2023
@@ -1,123 +1,121 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.pdmodel.interactive.digitalsignature;
-
-import java.io.ByteArrayInputStream;
-import java.io.FilterInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Arrays;
-
-import org.apache.pdfbox.io.IOUtils;
-
-/**
- * A filtered stream that includes the bytes that are in the (begin,length) 
intervals passed in the
- * constructor.
- *
- * @author boix_jor
- *
- */
-public class COSFilterInputStream extends FilterInputStream
-{
-    private int[][] ranges;
-    private int range;
-    private long position = 0;
-
-    public COSFilterInputStream(InputStream in, int[] byteRange)
-    {
-        super(in);
-        calculateRanges(byteRange);
-    }
-
-    public COSFilterInputStream(byte[] in, int[] byteRange)
-    {
-        this(new ByteArrayInputStream(in), byteRange);
-    }
-
-    @Override
-    public int read() throws IOException
-    {
-        if ((this.range == -1 || getRemaining() <= 0) && !nextRange())
-        {
-            return -1; // EOF
-        }
-        int result = super.read();
-        this.position++;
-        return result;
-    }
-
-    @Override
-    public int read(byte[] b) throws IOException
-    {
-        return read(b, 0, b.length);
-    }
-
-    @Override
-    public int read(byte[] b, int off, int len) throws IOException
-    {
-        if ((this.range == -1 || getRemaining() <= 0) && !nextRange())
-        {
-            return -1; // EOF
-        }
-        int bytesRead = super.read(b, off, (int) Math.min(len, 
getRemaining()));
-        this.position += bytesRead;
-        return bytesRead;
-    }
-
-    public byte[] toByteArray() throws IOException
-    {
-        return IOUtils.toByteArray(this);
-    }
-
-    private void calculateRanges(int[] byteRange)
-    {
-        this.ranges = new int[byteRange.length / 2][];
-        for (int i = 0; i < byteRange.length / 2; i++)
-        {
-            this.ranges[i] = new int[] { byteRange[i * 2], byteRange[i * 2] + 
byteRange[i * 2 + 1] };
-        }
-        this.range = -1;
-    }
-
-    private long getRemaining()
-    {
-        return this.ranges[this.range][1] - this.position;
-    }
-
-    private boolean nextRange() throws IOException
-    {
-        if (this.range + 1 < this.ranges.length)
-        {
-            this.range++;
-            while (this.position < this.ranges[this.range][0])
-            {
-                long skipped = super.skip(this.ranges[this.range][0] - 
this.position);
-                if (skipped == 0)
-                {
-                    throw new IOException("FilterInputStream.skip() returns 0, 
range: " +
-                            Arrays.toString(this.ranges[this.range]));
-                }
-                this.position += skipped;
-            }
-            return true;
-        }
-        else
-        {
-            return false;
-        }
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel.interactive.digitalsignature;
+
+import java.io.ByteArrayInputStream;
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+
+/**
+ * A filtered stream that includes the bytes that are in the (begin,length) 
intervals passed in the
+ * constructor.
+ *
+ * @author boix_jor
+ *
+ */
+public class COSFilterInputStream extends FilterInputStream
+{
+    private int[][] ranges;
+    private int range;
+    private long position = 0;
+
+    public COSFilterInputStream(InputStream in, int[] byteRange)
+    {
+        super(in);
+        calculateRanges(byteRange);
+    }
+
+    public COSFilterInputStream(byte[] in, int[] byteRange)
+    {
+        this(new ByteArrayInputStream(in), byteRange);
+    }
+
+    @Override
+    public int read() throws IOException
+    {
+        if ((this.range == -1 || getRemaining() <= 0) && !nextRange())
+        {
+            return -1; // EOF
+        }
+        int result = super.read();
+        this.position++;
+        return result;
+    }
+
+    @Override
+    public int read(byte[] b) throws IOException
+    {
+        return read(b, 0, b.length);
+    }
+
+    @Override
+    public int read(byte[] b, int off, int len) throws IOException
+    {
+        if ((this.range == -1 || getRemaining() <= 0) && !nextRange())
+        {
+            return -1; // EOF
+        }
+        int bytesRead = super.read(b, off, (int) Math.min(len, 
getRemaining()));
+        this.position += bytesRead;
+        return bytesRead;
+    }
+
+    public byte[] toByteArray() throws IOException
+    {
+        return readAllBytes();
+    }
+
+    private void calculateRanges(int[] byteRange)
+    {
+        this.ranges = new int[byteRange.length / 2][];
+        for (int i = 0; i < byteRange.length / 2; i++)
+        {
+            this.ranges[i] = new int[] { byteRange[i * 2], byteRange[i * 2] + 
byteRange[i * 2 + 1] };
+        }
+        this.range = -1;
+    }
+
+    private long getRemaining()
+    {
+        return this.ranges[this.range][1] - this.position;
+    }
+
+    private boolean nextRange() throws IOException
+    {
+        if (this.range + 1 < this.ranges.length)
+        {
+            this.range++;
+            while (this.position < this.ranges[this.range][0])
+            {
+                long skipped = super.skip(this.ranges[this.range][0] - 
this.position);
+                if (skipped == 0)
+                {
+                    throw new IOException("FilterInputStream.skip() returns 0, 
range: " +
+                            Arrays.toString(this.ranges[this.range]));
+                }
+                this.position += skipped;
+            }
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+}

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDXFAResource.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDXFAResource.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDXFAResource.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDXFAResource.java
 Sat Sep  2 11:10:39 2023
@@ -24,7 +24,6 @@ import java.io.InputStream;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSStream;
-import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
 import org.w3c.dom.Document;
 
@@ -112,7 +111,7 @@ public final class PDXFAResource impleme
     {
         try (final InputStream is = stream.createInputStream())
         {
-            return IOUtils.toByteArray(is);
+            return is.readAllBytes();
         }
     }
     

Modified: 
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSStream.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSStream.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSStream.java 
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSStream.java 
Sat Sep  2 11:10:39 2023
@@ -19,16 +19,12 @@ package org.apache.pdfbox.cos;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
+import java.io.*;
 import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 
 import org.apache.pdfbox.filter.Filter;
 import org.apache.pdfbox.filter.FilterFactory;
-import org.apache.pdfbox.io.IOUtils;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
@@ -200,14 +196,16 @@ class TestCOSStream
 
     private void validateEncoded(COSStream stream, byte[] expected) throws 
IOException
     {
-        byte[] decoded = IOUtils.toByteArray(stream.createRawInputStream());
+        InputStream in = stream.createRawInputStream();
+        byte[] decoded = in.readAllBytes();
         stream.close();
         assertTrue(Arrays.equals(expected, decoded), "Encoded data doesn't 
match input");
     }
 
     private void validateDecoded(COSStream stream, byte[] expected) throws 
IOException
     {
-        byte[] encoded = IOUtils.toByteArray(stream.createInputStream());
+        InputStream in = stream.createInputStream();
+        byte[] encoded = in.readAllBytes();
         stream.close();
         assertTrue(Arrays.equals(expected, encoded), "Decoded data doesn't 
match input");
     }

Modified: 
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java
 Sat Sep  2 11:10:39 2023
@@ -358,7 +358,7 @@ class TestSymmetricKeyEncryption
             srcImgTab.add(pdfRenderer.renderImage(i));
             try (InputStream unfilteredStream = 
document.getPage(i).getContents())
             {
-                srcContentStreamTab.add(IOUtils.toByteArray(unfilteredStream));
+                srcContentStreamTab.add(unfilteredStream.readAllBytes());
             }
         }
 
@@ -376,7 +376,7 @@ class TestSymmetricKeyEncryption
                 // compare content streams
                 try (InputStream unfilteredStream = 
encryptedDoc.getPage(i).getContents())
                 {
-                    byte[] bytes = IOUtils.toByteArray(unfilteredStream);
+                    byte[] bytes = unfilteredStream.readAllBytes();
                     assertArrayEquals(srcContentStreamTab.get(i),bytes, 
"content stream of page " + i + " not identical");
                 }
             }
@@ -498,11 +498,11 @@ class TestSymmetricKeyEncryption
 
     private byte[] getFileResourceAsByteArray(String testFileName) throws 
IOException
     {
-        return 
IOUtils.toByteArray(TestSymmetricKeyEncryption.class.getResourceAsStream(testFileName));
+        return 
TestSymmetricKeyEncryption.class.getResourceAsStream(testFileName).readAllBytes();
     }
 
     private byte[] getFileAsByteArray(File f) throws IOException
     {
         return Files.readAllBytes(f.toPath());
     }
-}
\ No newline at end of file
+}

Modified: 
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java 
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java 
Sat Sep  2 11:10:39 2023
@@ -18,17 +18,13 @@ package org.apache.pdfbox.filter;
 
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
+import java.io.*;
 
 import java.util.Random;
 
 import org.apache.pdfbox.Loader;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.io.IOUtils;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -142,7 +138,8 @@ class TestFilters
     void testPDFBOX1977() throws IOException
     {
         Filter lzwFilter = 
FilterFactory.INSTANCE.getFilter(COSName.LZW_DECODE);
-        byte[] byteArray = 
IOUtils.toByteArray(this.getClass().getResourceAsStream("PDFBOX-1977.bin"));
+        InputStream in = 
this.getClass().getResourceAsStream("PDFBOX-1977.bin");
+        byte[] byteArray = in.readAllBytes();
         checkEncodeDecode(lzwFilter, byteArray);
     }
 

Modified: 
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObjectTest.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObjectTest.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObjectTest.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObjectTest.java
 Sat Sep  2 11:10:39 2023
@@ -23,9 +23,10 @@ import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URISyntaxException;
 import javax.imageio.ImageIO;
-import org.apache.pdfbox.io.IOUtils;
+
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.parallel.Execution;
@@ -271,7 +272,8 @@ class PDImageXObjectTest
         try (PDDocument doc = new PDDocument())
         {
             File file = new 
File(PDImageXObjectTest.class.getResource(filename).toURI());
-            byte[] byteArray = IOUtils.toByteArray(new FileInputStream(file));
+            InputStream in = new FileInputStream(file);
+            byte[] byteArray = in.readAllBytes();
             PDImageXObject image = PDImageXObject.createFromByteArray(doc, 
byteArray, null);
             
             BufferedImage bim = 
ImageIO.read(PDImageXObjectTest.class.getResourceAsStream(filename));
@@ -288,7 +290,8 @@ class PDImageXObjectTest
         try (PDDocument doc = new PDDocument())
         {
             File file = new 
File(PDImageXObjectTest.class.getResource(filename).toURI());
-            byte[] byteArray = IOUtils.toByteArray(new FileInputStream(file));
+            InputStream in = new FileInputStream(file);
+            byte[] byteArray = in.readAllBytes();
             PDImageXObject image = PDImageXObject.createFromByteArray(doc, 
byteArray, null);
             
             PDImageXObject expectedImage = CCITTFactory.createFromFile(doc, 
file);
@@ -304,7 +307,8 @@ class PDImageXObjectTest
         try (PDDocument doc = new PDDocument())
         {
             File file = new 
File(PDImageXObjectTest.class.getResource(filename).toURI());
-            byte[] byteArray = IOUtils.toByteArray(new FileInputStream(file));
+            InputStream in = new FileInputStream(file);
+            byte[] byteArray = in.readAllBytes();
             PDImageXObject image = PDImageXObject.createFromByteArray(doc, 
byteArray, null);
             
             PDImageXObject expectedImage = JPEGFactory.createFromStream(doc, 
new FileInputStream(file));

Modified: 
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PNGConverterTest.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PNGConverterTest.java?rev=1912053&r1=1912052&r2=1912053&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PNGConverterTest.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PNGConverterTest.java
 Sat Sep  2 11:10:39 2023
@@ -27,6 +27,7 @@ import java.awt.image.WritableRaster;
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -34,7 +35,6 @@ import java.util.Hashtable;
 import javax.imageio.ImageIO;
 
 import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDPageContentStream;
@@ -168,7 +168,8 @@ class PNGConverterTest
     {
         try (PDDocument doc = new PDDocument())
         {
-            byte[] imageBytes = 
IOUtils.toByteArray(PNGConverterTest.class.getResourceAsStream(name));
+            InputStream in = PNGConverterTest.class.getResourceAsStream(name);
+            byte[] imageBytes = in.readAllBytes();
             PDImageXObject pdImageXObject = PNGConverter.convertPNGImage(doc, 
imageBytes);
             assertNull(pdImageXObject);
         }
@@ -178,7 +179,8 @@ class PNGConverterTest
     {
         try (PDDocument doc = new PDDocument())
         {
-            byte[] imageBytes = 
IOUtils.toByteArray(PNGConverterTest.class.getResourceAsStream(name));
+            InputStream in = PNGConverterTest.class.getResourceAsStream(name);
+            byte[] imageBytes = in.readAllBytes();
             PDImageXObject pdImageXObject = PNGConverter.convertPNGImage(doc, 
imageBytes);
             assertNotNull(pdImageXObject);
             
@@ -369,7 +371,8 @@ class PNGConverterTest
 
         try (PDDocument doc = new PDDocument())
         {
-            byte[] imageBytes = 
IOUtils.toByteArray(PNGConverterTest.class.getResourceAsStream("929316.png"));
+            InputStream in = 
PNGConverterTest.class.getResourceAsStream("929316.png");
+            byte[] imageBytes = in.readAllBytes();
             PDImageXObject pdImageXObject = PNGConverter.convertPNGImage(doc, 
imageBytes);
             assertEquals(COSName.PERCEPTUAL, 
pdImageXObject.getCOSObject().getItem(COSName.INTENT));
 


Reply via email to