Skip to content

Commit

Permalink
PDFBOX-5669: use JDK 11 built-in methods, as suggested by Axel Howind
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1912052 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
THausherr committed Sep 2, 2023
1 parent 6868736 commit 91ae7e0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.apache.pdfbox.io.IOUtils;

/**
* Copied from
* http://svn.apache.org/repos/asf/wink/trunk/wink-component-test-support/src/main/java/org/apache/wink/client/MockHttpServer.java
Expand Down Expand Up @@ -335,8 +333,7 @@ private void processRegularContent(InputStream is) throws IOException {
return;
}
int contentLen = Integer.parseInt(contentLength);
byte[] bytes = new byte[contentLen];
IOUtils.populateBuffer(is, bytes);
byte[] bytes = is.readNBytes(contentLen);
requestContent.write(bytes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ private boolean prepareAESInitializationVector(boolean decrypt, byte[] iv, Input
if (decrypt)
{
// read IV from stream
int ivSize = (int) IOUtils.populateBuffer(data, iv);
int ivSize = data.readNBytes(iv, 0, iv.length);
if (ivSize == 0)
{
return false;
Expand Down Expand Up @@ -515,10 +515,11 @@ public void decryptStream(COSStream stream, long objNum, long genNum) throws IOE
// PDFBOX-3229 check case where metadata is not encrypted despite /EncryptMetadata missing
try (InputStream is = stream.createRawInputStream())
{
buf = new byte[10];
long isResult = IOUtils.populateBuffer(is, buf);
int nBytes = 10;
buf = is.readNBytes(nBytes);
int isResult = buf.length;

if (Long.compare(isResult, buf.length) != 0)
if (buf.length != nBytes)
{
LOG.debug("Tried reading " + buf.length + " bytes but only " + isResult + " bytes read");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSNumber;
import org.apache.pdfbox.filter.DecodeOptions;
import org.apache.pdfbox.io.IOUtils;
import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray;
import org.apache.pdfbox.pdmodel.graphics.color.PDIndexed;
Expand Down Expand Up @@ -98,7 +97,7 @@ public static BufferedImage getStencilImage(PDImage pdImage, Paint paint) throws
for (int y = 0; y < height; y++)
{
int x = 0;
int readLen = (int) IOUtils.populateBuffer(iis, buff);
int readLen = iis.readNBytes(buff, 0, buff.length);
for (int r = 0; r < rowLen && r < readLen; r++)
{
int byteValue = buff[r];
Expand Down Expand Up @@ -421,7 +420,7 @@ private static BufferedImage from1Bit(PDImage pdImage, Rectangle clipped, final
final byte[] buff = new byte[stride];
for (int y = 0; y < starty + scanHeight; y++)
{
int read = (int) IOUtils.populateBuffer(iis, buff);
int read = iis.readNBytes(buff, 0, buff.length);
if (y >= starty && y % currentSubsampling == 0)
{
int x = startx;
Expand Down Expand Up @@ -498,8 +497,8 @@ private static BufferedImage from8bit(PDImage pdImage, WritableRaster raster, Re
if (startx == 0 && starty == 0 && scanWidth == width && scanHeight == height && currentSubsampling == 1)
{
// we just need to copy all sample data, then convert to RGB image.
long inputResult = IOUtils.populateBuffer(input, bank);
if (Long.compare(inputResult, (long) width * height * numComponents) != 0)
int inputResult = input.readNBytes(bank, 0, bank.length);
if (inputResult != (long) width * height * numComponents)
{
LOG.debug("Tried reading " + (long) width * height * numComponents + " bytes but only " + inputResult + " bytes read");
}
Expand All @@ -515,7 +514,7 @@ private static BufferedImage from8bit(PDImage pdImage, WritableRaster raster, Re
int i = 0;
for (int y = 0; y < starty + scanHeight; ++y)
{
long inputResult = IOUtils.populateBuffer(input, tempBytes);
int inputResult = input.readNBytes(tempBytes, 0, tempBytes.length);

if (Long.compare(inputResult, tempBytes.length) != 0)
{
Expand Down

0 comments on commit 91ae7e0

Please sign in to comment.