aboutsummaryrefslogtreecommitdiffstats
path: root/poi
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2024-06-05 16:31:36 +0000
committerPJ Fanning <fanningpj@apache.org>2024-06-05 16:31:36 +0000
commitf56eea8e45522cb497074ba9861f523705a9c7f2 (patch)
tree7082e9f09e65197934721051d6fc75e39516b0f8 /poi
parent160fc0122c77bb2594495b832286220e07ac736f (diff)
downloadpoi-f56eea8e45522cb497074ba9861f523705a9c7f2.tar.gz
poi-f56eea8e45522cb497074ba9861f523705a9c7f2.zip
BoundedInputStream deprecation warnings
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1918175 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java2
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDocumentOutputStream.java18
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardDecryptor.java10
-rw-r--r--poi/src/main/java/org/apache/poi/util/IOUtils.java2
4 files changed, 27 insertions, 5 deletions
diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java b/poi/src/main/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java
index ed0cf12372..bc6eccdaf4 100644
--- a/poi/src/main/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java
+++ b/poi/src/main/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java
@@ -205,7 +205,7 @@ public class CryptoAPIDecryptor extends Decryptor {
for (StreamDescriptorEntry entry : entries) {
sbis.seek(entry.streamOffset);
sbis.setBlock(entry.block);
- try (InputStream is = new BoundedInputStream(sbis, entry.streamSize)) {
+ try (InputStream is = BoundedInputStream.builder().setInputStream(sbis).setMaxCount(entry.streamSize).get()) {
fsOut.createDocument(is, entry.streamName);
}
}
diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDocumentOutputStream.java b/poi/src/main/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDocumentOutputStream.java
index 34c4a74675..cd2443d46f 100644
--- a/poi/src/main/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDocumentOutputStream.java
+++ b/poi/src/main/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDocumentOutputStream.java
@@ -16,7 +16,9 @@
==================================================================== */
package org.apache.poi.poifs.crypt.cryptoapi;
+import java.io.IOException;
import java.io.InputStream;
+import java.io.UncheckedIOException;
import java.security.GeneralSecurityException;
import javax.crypto.Cipher;
@@ -40,8 +42,22 @@ import org.apache.poi.util.Internal;
cipher = encryptor.initCipherForBlock(null, 0);
}
+ /**
+ * Returns the encrypted data.
+ *
+ * @param maxSize
+ * @return the encrypted data
+ * @throws UncheckedIOException if an I/O error occurs
+ */
public InputStream toInputStream(long maxSize) {
- return new BoundedInputStream(toInputStream(), maxSize);
+ try {
+ return BoundedInputStream.builder()
+ .setInputStream(toInputStream())
+ .setMaxCount(maxSize)
+ .get();
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
}
public void setSize(int count) {
diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardDecryptor.java b/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardDecryptor.java
index 145f9b8bb1..eb82aedaee 100644
--- a/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardDecryptor.java
+++ b/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardDecryptor.java
@@ -140,8 +140,14 @@ public class StandardDecryptor extends Decryptor {
long cipherLen = (_length/blockSize + 1) * blockSize;
Cipher cipher = getCipher(getSecretKey());
- InputStream boundedDis = new BoundedInputStream(dis, cipherLen);
- return new BoundedInputStream(new CipherInputStream(boundedDis, cipher), _length);
+ final InputStream boundedDis = BoundedInputStream.builder()
+ .setInputStream(dis)
+ .setMaxCount(cipherLen)
+ .get();
+ return BoundedInputStream.builder()
+ .setInputStream(new CipherInputStream(boundedDis, cipher))
+ .setMaxCount(_length)
+ .get();
}
/**
diff --git a/poi/src/main/java/org/apache/poi/util/IOUtils.java b/poi/src/main/java/org/apache/poi/util/IOUtils.java
index 4fa3484af8..2b9cbd730b 100644
--- a/poi/src/main/java/org/apache/poi/util/IOUtils.java
+++ b/poi/src/main/java/org/apache/poi/util/IOUtils.java
@@ -142,7 +142,7 @@ public final class IOUtils {
stream.mark(limit);
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(limit).get()) {
- copy(new BoundedInputStream(stream, limit), bos);
+ copy(BoundedInputStream.builder().setInputStream(stream).setMaxCount(limit).get(), bos);
int readBytes = bos.size();
if (readBytes == 0) {