aboutsummaryrefslogtreecommitdiffstats
path: root/poi-ooxml/src/main/java
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2023-06-08 08:53:08 +0000
committerDominik Stadler <centic@apache.org>2023-06-08 08:53:08 +0000
commitd3e35e740a593027a1105e6509c0aadaa54399b0 (patch)
tree4f9c5b276aa7a088def6aaa7282bb37c39b16105 /poi-ooxml/src/main/java
parentc8f9fe4c2c01aa896c80de7b43725788b4ce6c4a (diff)
downloadpoi-d3e35e740a593027a1105e6509c0aadaa54399b0.tar.gz
poi-d3e35e740a593027a1105e6509c0aadaa54399b0.zip
Remove deprecation warnings reported with newer commons-io
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1910300 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml/src/main/java')
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/MemoryPackagePart.java9
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/MemoryPackagePartOutputStream.java2
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipArchiveFakeEntry.java2
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/DigestOutputStream.java4
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/OOXMLURIDereferencer.java2
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/SignatureLine.java4
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java7
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xslf/draw/SVGImageRenderer.java2
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xslf/draw/SVGRenderExtension.java2
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFMetroShape.java2
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java2
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xslf/util/DummyFormat.java2
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java2
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFBuiltinTableStyle.java4
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFChartSheet.java4
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java6
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java2
17 files changed, 33 insertions, 25 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/MemoryPackagePart.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/MemoryPackagePart.java
index dd53be0ea9..9096b69457 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/MemoryPackagePart.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/MemoryPackagePart.java
@@ -88,7 +88,12 @@ public final class MemoryPackagePart extends PackagePart {
if (data == null) {
data = new byte[0];
}
- return new UnsynchronizedByteArrayInputStream(data);
+ try {
+ return UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get();
+ } catch (IOException e) {
+ // not possible with ByteArray but still declared in the API
+ throw new IllegalStateException(e);
+ }
}
@Override
@@ -113,7 +118,7 @@ public final class MemoryPackagePart extends PackagePart {
@Override
public boolean load(InputStream is) throws InvalidFormatException {
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
// Grab the data
IOUtils.copy(is, baos);
// Save it
diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/MemoryPackagePartOutputStream.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/MemoryPackagePartOutputStream.java
index 071718021b..3b146103c4 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/MemoryPackagePartOutputStream.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/MemoryPackagePartOutputStream.java
@@ -33,7 +33,7 @@ public final class MemoryPackagePartOutputStream extends OutputStream {
public MemoryPackagePartOutputStream(MemoryPackagePart part) {
this._part = part;
- _buff = new UnsynchronizedByteArrayOutputStream();
+ _buff = UnsynchronizedByteArrayOutputStream.builder().get();
}
@Override
diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipArchiveFakeEntry.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipArchiveFakeEntry.java
index 34b28ab662..7a74f07472 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipArchiveFakeEntry.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipArchiveFakeEntry.java
@@ -104,7 +104,7 @@ import org.apache.poi.util.TempFile;
throw new IOException("temp file " + tempFile.getAbsolutePath() + " is missing");
}
} else if (data != null) {
- return new UnsynchronizedByteArrayInputStream(data);
+ return UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get();
} else {
throw new IOException("Cannot retrieve data from Zip Entry, probably because the Zip Entry was closed before the data was requested.");
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/DigestOutputStream.java b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/DigestOutputStream.java
index baf8e0a215..bf49df547d 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/DigestOutputStream.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/DigestOutputStream.java
@@ -65,7 +65,7 @@ import org.ietf.jgss.Oid;
}
public byte[] sign() throws IOException, GeneralSecurityException {
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
bos.write(getHashMagic());
bos.write(md.digest());
@@ -91,7 +91,7 @@ import org.ietf.jgss.Oid;
// in an earlier release the hashMagic (aka DigestAlgorithmIdentifier) contained only
// an object identifier, but to conform with the header generated by the
// javax-signature API, the empty <associated parameters> are also included
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
final byte[] oidBytes = new Oid(algo.rsaOid).getDER();
bos.write(0x30);
diff --git a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/OOXMLURIDereferencer.java b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/OOXMLURIDereferencer.java
index c4c988b4de..01c05652bd 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/OOXMLURIDereferencer.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/OOXMLURIDereferencer.java
@@ -90,7 +90,7 @@ public class OOXMLURIDereferencer implements URIDereferencer {
if (part.getPartName().toString().endsWith(".rels")) {
// although xmlsec has an option to ignore line breaks, currently this
// only affects .rels files, so we only modify these
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
for (int ch; (ch = dataStream.read()) != -1; ) {
if (ch == 10 || ch == 13) continue;
bos.write(ch);
diff --git a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/SignatureLine.java b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/SignatureLine.java
index 54964d1dec..060ab3b12c 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/SignatureLine.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/SignatureLine.java
@@ -341,7 +341,7 @@ public abstract class SignatureLine {
rnd.drawImage(gfx, new Rectangle2D.Double(0, 0, defaultWidth, defaultHeight));
gfx.dispose();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
ImageIO.write(bi, "PNG", bos);
return bos.toByteArray();
}
@@ -426,7 +426,7 @@ public abstract class SignatureLine {
gfx.dispose();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
ImageIO.write(bi, "PNG", bos);
return bos.toByteArray();
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java
index a9d0a4171e..7e5bbcf5ac 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java
@@ -223,9 +223,12 @@ public class XAdESXLSignatureFacet implements SignatureFacet {
X509CRL crl;
try {
crl = (X509CRL) this.certificateFactory
- .generateCRL(new UnsynchronizedByteArrayInputStream(encodedCrl));
+ .generateCRL(UnsynchronizedByteArrayInputStream.builder().setByteArray(encodedCrl).get());
} catch (CRLException e) {
throw new IllegalStateException("CRL parse error: " + e.getMessage(), e);
+ } catch (IOException e) {
+ // not possible with ByteArray but still declared in the API
+ throw new IllegalStateException(e);
}
CRLIdentifierType crlIdentifier = crlRef.addNewCRLIdentifier();
@@ -299,7 +302,7 @@ public class XAdESXLSignatureFacet implements SignatureFacet {
}
private static byte[] getC14nValue(List<Node> nodeList, String c14nAlgoId) {
- try (UnsynchronizedByteArrayOutputStream c14nValue = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream c14nValue = UnsynchronizedByteArrayOutputStream.builder().get()) {
for (Node node : nodeList) {
/*
* Re-initialize the c14n else the namespaces will get cached
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/SVGImageRenderer.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/SVGImageRenderer.java
index 1e16483ea9..2bd46c4876 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/SVGImageRenderer.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/SVGImageRenderer.java
@@ -68,7 +68,7 @@ public class SVGImageRenderer implements ImageRenderer {
@Override
public void loadImage(byte[] data, String contentType) throws IOException {
- loadImage(new UnsynchronizedByteArrayInputStream(data), contentType);
+ loadImage(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get(), contentType);
}
@Override
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/SVGRenderExtension.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/SVGRenderExtension.java
index 8e2bb21aed..7f78762996 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/SVGRenderExtension.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/SVGRenderExtension.java
@@ -310,7 +310,7 @@ public class SVGRenderExtension extends DefaultExtensionHandler {
}
if (imgData == null) {
BufferedImage bi = imgRdr.getImage();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try {
ImageIO.write(bi, "PNG", bos);
} catch (IOException e) {
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFMetroShape.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFMetroShape.java
index c01b9ff3de..cdb9d0e4af 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFMetroShape.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFMetroShape.java
@@ -44,7 +44,7 @@ public class XSLFMetroShape implements MetroShapeProvider {
/** parses the metro bytes to a XSLF shape */
@Override
public XSLFShape parseShape(byte[] metroBytes) throws IOException {
- try (OPCPackage pkg = OPCPackage.open(new UnsynchronizedByteArrayInputStream(metroBytes))) {
+ try (OPCPackage pkg = OPCPackage.open(UnsynchronizedByteArrayInputStream.builder().setByteArray(metroBytes).get())) {
PackagePartName shapePN = PackagingURIHelper.createPartName("/drs/shapexml.xml");
PackagePart shapePart = pkg.getPart(shapePN);
if (shapePart == null) {
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
index 53727ef5e8..b7e2bb5496 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
@@ -372,7 +372,7 @@ public class XSLFPictureShape extends XSLFSimpleShape
}
BufferedImage thmBI = renderer.getImage(dim);
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(100000)) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(100000).get()) {
// use extension instead of enum name, because of "jpeg"
ImageIO.write(thmBI, pt.extension.substring(1), bos);
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/util/DummyFormat.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/util/DummyFormat.java
index b090c34cc3..0a995ed498 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/util/DummyFormat.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/util/DummyFormat.java
@@ -34,7 +34,7 @@ public class DummyFormat implements OutputFormat {
public DummyFormat() {
try {
- bos = new UnsynchronizedByteArrayOutputStream();
+ bos = UnsynchronizedByteArrayOutputStream.builder().get();
dummy2d = new DummyGraphics2d(new PrintStream(bos, true, StandardCharsets.UTF_8.name()));
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
index 38feae68e9..eccbc02e22 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
@@ -1019,7 +1019,7 @@ public class SXSSFWorkbook implements Workbook {
flushSheets();
//Save the template
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
_wb.write(bos);
//Substitute the template entries with the generated sheet data files
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFBuiltinTableStyle.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFBuiltinTableStyle.java
index 63ef92a707..b650380e88 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFBuiltinTableStyle.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFBuiltinTableStyle.java
@@ -409,8 +409,8 @@ public enum XSSFBuiltinTableStyle {
// hack because I can't figure out how to get XMLBeans to parse a sub-element in a standalone manner
// - build a fake styles.xml file with just this built-in
StylesTable styles = new StylesTable();
- try (UnsynchronizedByteArrayInputStream bis = new UnsynchronizedByteArrayInputStream(
- styleXML(dxfsNode, tableStyleNode).getBytes(StandardCharsets.UTF_8))) {
+ try (UnsynchronizedByteArrayInputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(
+ styleXML(dxfsNode, tableStyleNode).getBytes(StandardCharsets.UTF_8)).get()) {
styles.readFrom(bis);
}
styleMap.put(builtIn, new XSSFBuiltinTypeStyleStyle(builtIn, styles.getExplicitTableStyle(styleName)));
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFChartSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFChartSheet.java
index 6f0b5e1169..aeb7874a6c 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFChartSheet.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFChartSheet.java
@@ -57,7 +57,7 @@ public class XSSFChartSheet extends XSSFSheet {
@Override
protected void read(InputStream is) throws IOException {
//initialize the supeclass with a blank worksheet
- super.read(new UnsynchronizedByteArrayInputStream(BLANK_WORKSHEET));
+ super.read(UnsynchronizedByteArrayInputStream.builder().setByteArray(BLANK_WORKSHEET).get());
try {
chartsheet = ChartsheetDocument.Factory.parse(is, DEFAULT_XML_OPTIONS).getChartsheet();
@@ -95,7 +95,7 @@ public class XSSFChartSheet extends XSSFSheet {
}
private static byte[] blankWorksheet(){
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
try {
new XSSFSheet().write(out);
} catch (IOException e){
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
index c15b21ebf6..cc7284e04b 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
@@ -511,7 +511,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
protected static OPCPackage newPackage(XSSFWorkbookType workbookType) {
OPCPackage pkg = null;
try {
- pkg = OPCPackage.create(new UnsynchronizedByteArrayOutputStream()); // NOSONAR - we do not want to close this here
+ pkg = OPCPackage.create(UnsynchronizedByteArrayOutputStream.builder().get()); // NOSONAR - we do not want to close this here
// Main part
PackagePartName corePartName = PackagingURIHelper.createPartName(XSSFRelation.WORKBOOK.getDefaultFileName());
// Create main part relationship
@@ -665,7 +665,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
}
- try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) {
srcSheet.write(out);
try (InputStream bis = out.toInputStream()) {
clonedSheet.read(bis);
@@ -2466,7 +2466,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
Ole10Native ole10 = new Ole10Native(label, fileName, command, oleData);
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(oleData.length+500)) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(oleData.length+500).get()) {
ole10.writeOut(bos);
try (POIFSFileSystem poifs = new POIFSFileSystem()) {
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
index 0e2d09dc91..ee285455f4 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
@@ -174,7 +174,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
protected static OPCPackage newPackage() {
OPCPackage pkg = null;
try {
- pkg = OPCPackage.create(new UnsynchronizedByteArrayOutputStream()); // NOSONAR - we do not want to close this here
+ pkg = OPCPackage.create(UnsynchronizedByteArrayOutputStream.builder().get()); // NOSONAR - we do not want to close this here
// Main part
PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
// Create main part relationship