diff options
author | Dominik Stadler <centic@apache.org> | 2023-06-08 08:53:08 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2023-06-08 08:53:08 +0000 |
commit | d3e35e740a593027a1105e6509c0aadaa54399b0 (patch) | |
tree | 4f9c5b276aa7a088def6aaa7282bb37c39b16105 /poi-ooxml | |
parent | c8f9fe4c2c01aa896c80de7b43725788b4ce6c4a (diff) | |
download | poi-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')
63 files changed, 179 insertions, 171 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 diff --git a/poi-ooxml/src/test/java/org/apache/poi/ooxml/TestPOIXMLDocument.java b/poi-ooxml/src/test/java/org/apache/poi/ooxml/TestPOIXMLDocument.java index 80f18926a9..cc22c41ca9 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/ooxml/TestPOIXMLDocument.java +++ b/poi-ooxml/src/test/java/org/apache/poi/ooxml/TestPOIXMLDocument.java @@ -17,7 +17,6 @@ package org.apache.poi.ooxml; -import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -38,6 +37,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; +import org.apache.commons.io.output.NullOutputStream; import org.apache.poi.POIDataSamples; import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart; import org.apache.poi.ooxml.util.PackageHelper; @@ -141,7 +141,7 @@ public final class TestPOIXMLDocument { // Should not be able to write a document that has been closed doc.close(); - IOException e2 = assertThrows(IOException.class, () -> doc.write(NULL_OUTPUT_STREAM), + IOException e2 = assertThrows(IOException.class, () -> doc.write(NullOutputStream.INSTANCE), "Should not be able to write a document that has been closed."); assertEquals("Cannot write data, document seems to have been closed already", e2.getMessage()); diff --git a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackage.java b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackage.java index c52135d5c5..d0d0514a80 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackage.java +++ b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackage.java @@ -218,7 +218,7 @@ public final class TestPackage { */ @Test void createPackageWithCoreDocument() throws IOException, InvalidFormatException, URISyntaxException, SAXException { - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); try (OPCPackage pkg = OPCPackage.create(baos)) { // Add a core document @@ -676,7 +676,7 @@ public final class TestPackage { @Test void zipBombCreateAndHandle() throws IOException, EncryptedDocumentException { - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(2500000); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(2500000).get(); try (ZipFile zipFile = ZipHelper.openZipFile(getSampleFile("sample.xlsx")); ZipArchiveOutputStream append = new ZipArchiveOutputStream(bos)) { diff --git a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java index 6ef0bab8f4..5979190252 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java +++ b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java @@ -216,7 +216,7 @@ public final class TestPackageCoreProperties { @Test void testGetPropertiesLO() throws Exception { - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); // Open the package try (OPCPackage pkg1 = OPCPackage.open(openSampleStream("51444.xlsx"))) { PackageProperties props1 = pkg1.getPackageProperties(); @@ -284,7 +284,7 @@ public final class TestPackageCoreProperties { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ROOT); df.setTimeZone(LocaleUtil.TIMEZONE_UTC); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); try (InputStream is = openSampleStream("OPCCompliance_CoreProperties_AlternateTimezones.docx"); OPCPackage pkg1 = OPCPackage.open(is)) { PackagePropertiesPart props1 = (PackagePropertiesPart) pkg1.getPackageProperties(); diff --git a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestRelationships.java b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestRelationships.java index 7fd655d4a1..ce63f811a8 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestRelationships.java +++ b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestRelationships.java @@ -198,7 +198,7 @@ class TestRelationships { // Write out and re-load - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); pkg.save(baos); // use revert to not re-write the input file @@ -226,7 +226,7 @@ class TestRelationships { @Test void testCreateRelationsFromScratch() throws Exception { - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); OPCPackage pkg = OPCPackage.create(baos); PackagePart partA = @@ -298,7 +298,7 @@ class TestRelationships { OPCPackage pkg = OPCPackage.open(filepath); assert_50154(pkg); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); pkg.save(baos); // use revert to not re-write the input file @@ -353,7 +353,7 @@ class TestRelationships { @Test void testSelfRelations_bug51187() throws Exception { - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); PackageRelationship rel1; try (OPCPackage pkg = OPCPackage.create(baos)) { @@ -399,7 +399,7 @@ class TestRelationships { assertEquals("mailto:nobody@nowhere.uk%C2%A0", targetUri.toASCIIString()); assertEquals("nobody@nowhere.uk\u00A0", targetUri.getSchemeSpecificPart()); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); pkg1.save(out); try (OPCPackage pkg2 = OPCPackage.open(out.toInputStream())) { diff --git a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/ZipFileAssert.java b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/ZipFileAssert.java index a22ad42d19..ea49804ead 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/ZipFileAssert.java +++ b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/ZipFileAssert.java @@ -106,7 +106,7 @@ public final class ZipFileAssert { while ((entree = zis.getNextEntry()) != null) { /* Create an array for the current entry */ - UnsynchronizedByteArrayOutputStream byteArray = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream byteArray = UnsynchronizedByteArrayOutputStream.builder().get(); IOUtils.copy(zis, byteArray); zipContent.put(entree.getName(), byteArray); } diff --git a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java index b079f00bf3..2079cbd9e1 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java +++ b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java @@ -216,7 +216,7 @@ public final class TestOPCComplianceCoreProperties { @Test void testNoCoreProperties_saveNew() throws Exception { String sampleFileName = "OPCCompliance_NoCoreProperties.xlsx"; - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); try (OPCPackage pkg = OPCPackage.open(getSampleFile(sampleFileName).getPath())) { // Verify it has empty properties diff --git a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/internal/marshallers/TestZipPackagePropertiesMarshaller.java b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/internal/marshallers/TestZipPackagePropertiesMarshaller.java index 40345a029a..09ebcb20c2 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/internal/marshallers/TestZipPackagePropertiesMarshaller.java +++ b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/internal/marshallers/TestZipPackagePropertiesMarshaller.java @@ -17,7 +17,6 @@ package org.apache.poi.openxml4j.opc.internal.marshallers; -import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM; import static org.apache.poi.openxml4j.opc.PackagingURIHelper.PACKAGE_RELATIONSHIPS_ROOT_URI; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -27,6 +26,7 @@ import java.io.OutputStream; import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; +import org.apache.commons.io.output.NullOutputStream; import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.PackagePartName; @@ -39,7 +39,7 @@ class TestZipPackagePropertiesMarshaller { private final PartMarshaller marshaller = new ZipPackagePropertiesMarshaller(); private boolean marshall() throws OpenXML4JException { - return marshall(new ZipArchiveOutputStream(new UnsynchronizedByteArrayOutputStream())); + return marshall(new ZipArchiveOutputStream(UnsynchronizedByteArrayOutputStream.builder().get())); } private boolean marshall(OutputStream zos) throws OpenXML4JException { @@ -51,7 +51,7 @@ class TestZipPackagePropertiesMarshaller { @Test void nonZipOutputStream() { - assertThrows(IllegalArgumentException.class, () -> marshall(NULL_OUTPUT_STREAM)); + assertThrows(IllegalArgumentException.class, () -> marshall(NullOutputStream.INSTANCE)); } @Test @@ -61,7 +61,7 @@ class TestZipPackagePropertiesMarshaller { @Test void ioException() { - ZipArchiveOutputStream zos = new ZipArchiveOutputStream(new UnsynchronizedByteArrayOutputStream()) { + ZipArchiveOutputStream zos = new ZipArchiveOutputStream(UnsynchronizedByteArrayOutputStream.builder().get()) { @Override public void putArchiveEntry(final ArchiveEntry archiveEntry) throws IOException { throw new IOException("TestException"); diff --git a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/DummyKeystore.java b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/DummyKeystore.java index 10eaa22f38..3ad3dcfbe8 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/DummyKeystore.java +++ b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/DummyKeystore.java @@ -152,7 +152,7 @@ public class DummyKeystore { public DummyKeystore(String pfxInput, String storePass) throws GeneralSecurityException, IOException { CryptoFunctions.registerBouncyCastle(); keystore = KeyStore.getInstance("PKCS12"); - try (InputStream fis = new UnsynchronizedByteArrayInputStream(RawDataUtil.decompress(pfxInput))) { + try (InputStream fis = UnsynchronizedByteArrayInputStream.builder().setByteArray(RawDataUtil.decompress(pfxInput)).get()) { keystore.load(fis, storePass.toCharArray()); } } diff --git a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java index 2566f16388..932195193e 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java +++ b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java @@ -209,7 +209,7 @@ class TestSignatureInfo { SignatureInfo si = new SignatureInfo(); si.setSignatureConfig(signatureConfig); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(100000); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(100000).get(); try (XSSFWorkbook wb1 = new XSSFWorkbook()) { wb1.createSheet().createRow(1).createCell(1).setCellValue("Test"); wb1.write(bos); @@ -426,7 +426,7 @@ class TestSignatureInfo { void testSignEnvelopingDocument() throws Exception { String testFile = "hello-world-unsigned.xlsx"; File sigCopy = testdata.getFile(testFile); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(50000); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(50000).get(); final String execTimestr; @@ -698,7 +698,7 @@ class TestSignatureInfo { DummyKeystore ks = new DummyKeystore(STORE_PASS); KeyCertPair certPair = ks.createDummyKey(); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); try (XWPFDocument doc = new XWPFDocument()) { XWPFHyperlinkRun r = doc.createParagraph().createHyperlinkRun("http://poi.apache.org"); r.setText("Hyperlink"); @@ -743,7 +743,7 @@ class TestSignatureInfo { try (SXSSFWorkbook wb1 = new SXSSFWorkbook((XSSFWorkbook)WorkbookFactory.create(tpl), 10)) { wb1.setCompressTempFiles(true); wb1.removeSheetAt(0); - UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get(); wb1.write(os); try (OPCPackage pkg = OPCPackage.open(os.toInputStream())) { @@ -888,7 +888,7 @@ class TestSignatureInfo { throw e; } - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); try (XSSFWorkbook wb = new XSSFWorkbook()) { wb.createSheet().createRow(0).createCell(0).setCellValue("Test"); wb.write(bos); @@ -1075,7 +1075,7 @@ class TestSignatureInfo { throw e; } - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); try (XSSFWorkbook wb = new XSSFWorkbook()) { wb.createSheet().createRow(0).createCell(0).setCellValue("test"); wb.write(bos); diff --git a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestAgileEncryptionParameters.java b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestAgileEncryptionParameters.java index e0ad0febea..e4baf2b75c 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestAgileEncryptionParameters.java +++ b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestAgileEncryptionParameters.java @@ -93,7 +93,7 @@ class TestAgileEncryptionParameters { } // create a small sample workbook for encrypting - UnsynchronizedByteArrayOutputStream bosOrig = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bosOrig = UnsynchronizedByteArrayOutputStream.builder().get(); try (XSSFWorkbook workbook = new XSSFWorkbook()) { XSSFSheet sheet = workbook.createSheet(); XSSFRow row = sheet.createRow(0); @@ -136,7 +136,7 @@ class TestAgileEncryptionParameters { os.write(testData); } - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { fsEnc.writeFilesystem(bos); bos.close(); diff --git a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestDecryptor.java b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestDecryptor.java index 94392f00c4..c6d10af2b7 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestDecryptor.java +++ b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestDecryptor.java @@ -142,7 +142,7 @@ class TestDecryptor { Decryptor d = Decryptor.getInstance(info); d.verifyPassword("pwd123"); - final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(10000); + final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(10000).get(); try (final ZipArchiveInputStream zis = new ZipArchiveInputStream(d.getDataStream(fs))) { int[] sizes = { 3711, 1155, 445, 9376, 450, 588, 1337, 2593, 304, 7910 }; for (int size : sizes) { diff --git a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestEncryptor.java b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestEncryptor.java index 5e106b4202..f531631e38 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestEncryptor.java +++ b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestEncryptor.java @@ -16,7 +16,6 @@ ==================================================================== */ package org.apache.poi.poifs.crypt.tests; -import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM; import static org.apache.poi.poifs.crypt.CryptoFunctions.getMessageDigest; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -38,6 +37,7 @@ import java.util.Random; import javax.crypto.Cipher; +import org.apache.commons.io.output.NullOutputStream; import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; import org.apache.poi.POIDataSamples; import org.apache.poi.openxml4j.opc.ContentTypes; @@ -76,7 +76,7 @@ class TestEncryptor { payloadExpected = IOUtils.toByteArray(is); } - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); try (POIFSFileSystem fs = new POIFSFileSystem()) { EncryptionInfo ei = new EncryptionInfo(EncryptionMode.binaryRC4); Encryptor enc = ei.getEncryptor(); @@ -113,7 +113,7 @@ class TestEncryptor { payloadExpected = IOUtils.toByteArray(is); } - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); try (POIFSFileSystem fs = new TempFilePOIFSFileSystem()) { EncryptionInfo ei = new EncryptionInfo(EncryptionMode.agile); Encryptor enc = ei.getEncryptor(); @@ -200,7 +200,7 @@ class TestEncryptor { Encryptor e = Encryptor.getInstance(infoActual); e.confirmPassword(pass, keySpec, keySalt, verifierExpected, verifierSaltExpected, integritySalt); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); try (POIFSFileSystem fs = new POIFSFileSystem()) { try (OutputStream os = e.getDataStream(fs)) { os.write(payloadExpected); @@ -287,7 +287,7 @@ class TestEncryptor { // now we use a newly generated salt/verifier and check // if the file content is still the same - final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(50000); + final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(50000).get(); try (POIFSFileSystem fs = new POIFSFileSystem()) { final EncryptionInfo infoActual2 = new EncryptionInfo( @@ -331,7 +331,7 @@ class TestEncryptor { @Test void encryptPackageWithoutCoreProperties() throws Exception { // Open our file without core properties - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); try (InputStream is = POIDataSamples.getOpenXML4JInstance().openResourceAsStream("OPCCompliance_NoCoreProperties.xlsx"); OPCPackage pkg = OPCPackage.open(is)) { @@ -530,7 +530,7 @@ class TestEncryptor { os.write(zipInput); } - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); fsNew.writeFilesystem(bos); try (POIFSFileSystem fsReload = new POIFSFileSystem(bos.toInputStream())) { @@ -624,7 +624,7 @@ class TestEncryptor { try (InputStream is = dec.getDataStream(poifs); DigestInputStream dis = new DigestInputStream(is, md)) { - IOUtils.copy(dis, NULL_OUTPUT_STREAM); + IOUtils.copy(dis, NullOutputStream.INSTANCE); } } diff --git a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java index d51ac67e3b..518d44fda6 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java +++ b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java @@ -105,7 +105,7 @@ class TestHxxFEncryption { File f = sampleDir.getFile(file); Biff8EncryptionKey.setCurrentUserPassword(password); try (POITextExtractor te1 = ExtractorFactory.createExtractor(f); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { Biff8EncryptionKey.setCurrentUserPassword(newPass); try (POIDocument doc = (POIDocument) te1.getDocument()) { doc.write(bos); @@ -126,7 +126,7 @@ class TestHxxFEncryption { File f = sampleDir.getFile(file); Biff8EncryptionKey.setCurrentUserPassword(password); try (POITextExtractor te1 = ExtractorFactory.createExtractor(f); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { // first remove encryption Biff8EncryptionKey.setCurrentUserPassword(null); try (POIDocument doc = (POIDocument) te1.getDocument()) { @@ -174,7 +174,7 @@ class TestHxxFEncryption { @Test public void changeEncryptionMode() throws IOException { - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(10_000); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(10_000).get(); try (HSSFWorkbook wb = new HSSFWorkbook()) { wb.createSheet().createRow(1).createCell(1).setCellValue("Test"); diff --git a/poi-ooxml/src/test/java/org/apache/poi/sl/tests/TestOleShape.java b/poi-ooxml/src/test/java/org/apache/poi/sl/tests/TestOleShape.java index 8352e0061c..7370bd9c2c 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/sl/tests/TestOleShape.java +++ b/poi-ooxml/src/test/java/org/apache/poi/sl/tests/TestOleShape.java @@ -113,7 +113,7 @@ class TestOleShape { @ParameterizedTest @MethodSource("data") void embedData(Api api, ObjectMetaData.Application app) throws IOException, ReflectiveOperationException { - final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(50000); + final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(50000).get(); try (SlideShow<?,?> ppt = createSlideShow(api)) { final PictureData picData = ppt.addPicture(pictureFile, PictureType.EMF); final Slide<?,?> slide = ppt.createSlide(); diff --git a/poi-ooxml/src/test/java/org/apache/poi/sl/tests/TestSlide.java b/poi-ooxml/src/test/java/org/apache/poi/sl/tests/TestSlide.java index 06c358a459..49acd8d912 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/sl/tests/TestSlide.java +++ b/poi-ooxml/src/test/java/org/apache/poi/sl/tests/TestSlide.java @@ -55,7 +55,7 @@ class TestSlide { ppt1.createSlide().setHidden(true); ppt1.createSlide(); - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { ppt1.write(bos); try (InputStream is = bos.toInputStream(); diff --git a/poi-ooxml/src/test/java/org/apache/poi/sl/tests/TestTable.java b/poi-ooxml/src/test/java/org/apache/poi/sl/tests/TestTable.java index ccd6d86aa5..2f5b9c1335 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/sl/tests/TestTable.java +++ b/poi-ooxml/src/test/java/org/apache/poi/sl/tests/TestTable.java @@ -125,7 +125,7 @@ class TestTable { } } - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); ppt1.write(bos); try (SlideShow<?,?> ppt2 = SlideShowFactory.create(bos.toInputStream())) { diff --git a/poi-ooxml/src/test/java/org/apache/poi/ss/tests/usermodel/TestEmbedOLEPackage.java b/poi-ooxml/src/test/java/org/apache/poi/ss/tests/usermodel/TestEmbedOLEPackage.java index ca83289151..ea7067a149 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/ss/tests/usermodel/TestEmbedOLEPackage.java +++ b/poi-ooxml/src/test/java/org/apache/poi/ss/tests/usermodel/TestEmbedOLEPackage.java @@ -123,7 +123,7 @@ class TestEmbedOLEPackage { try (POIFSFileSystem scratchFS = new POIFSFileSystem(); POIFSFileSystem ole1FS = new POIFSFileSystem(new ByteArrayInputStream(oleShapes.get(0).getObjectData()))) { - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); scratch.writeOut(bos); scratchFS.createDocument(bos.toInputStream(), Ole10Native.OLE10_NATIVE); scratchFS.getRoot().setStorageClsid(ClassIDPredefined.OLE_V1_PACKAGE.getClassID()); @@ -222,7 +222,7 @@ class TestEmbedOLEPackage { sh1.setAnchor(new java.awt.Rectangle(50, 50, 100, 200)); sh1.setFillColor(java.awt.Color.red); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); ppt.write(bos); ppt.close(); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFBugs.java b/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFBugs.java index 0ff51a9d17..8d7a37dd7a 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFBugs.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFBugs.java @@ -964,7 +964,7 @@ class TestXSLFBugs { final List<Object> strings = new ArrayList<>(); - DummyGraphics2d dgfx = new DummyGraphics2d(new NullPrintStream()) { + DummyGraphics2d dgfx = new DummyGraphics2d(NullPrintStream.INSTANCE) { @Override public void drawString(AttributedCharacterIterator iterator, float x, float y) { // For the test file, common sl draws textruns one by one and not mixed @@ -1009,7 +1009,7 @@ class TestXSLFBugs { { 79.58198774450841, 53.20887318960063, 109.13118501448272, 9.40935058567127 }, }; - DummyGraphics2d dgfx = new DummyGraphics2d(new NullPrintStream()) { + DummyGraphics2d dgfx = new DummyGraphics2d(NullPrintStream.INSTANCE) { int idx = 0; @Override public void clip(java.awt.Shape s) { @@ -1065,7 +1065,7 @@ class TestXSLFBugs { assertNotNull(targetSlide); assertEquals(2, targetPresentation.getPictureData().size()); - targetPresentation.write(NullOutputStream.NULL_OUTPUT_STREAM); + targetPresentation.write(NullOutputStream.INSTANCE); } } @@ -1143,7 +1143,7 @@ class TestXSLFBugs { final ArrayList<LinearGradientPaint> linearGradients = new ArrayList<>(); final ArrayList<RadialGradientPaint> radialGradients = new ArrayList<>(); - final DummyGraphics2d dgfx = new DummyGraphics2d(new NullPrintStream()) + final DummyGraphics2d dgfx = new DummyGraphics2d(NullPrintStream.INSTANCE) { public void setPaint(final Paint paint) { if (paint instanceof LinearGradientPaint) { diff --git a/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideCopy.java b/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideCopy.java index 7e198d40b6..135bf5f833 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideCopy.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideCopy.java @@ -40,7 +40,7 @@ class TestXSLFSlideCopy { try ( InputStream stream = slTests.openResourceAsStream("copy-slide-demo.pptx"); XMLSlideShow slideShow = new XMLSlideShow(stream); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { XSLFSlide defaultSlide = getSlideByShapeName(slideShow, shapeName); int slideIndex = defaultSlide.getSlideNumber() - 1; diff --git a/poi-ooxml/src/test/java/org/apache/poi/xslf/XSLFTestDataSamples.java b/poi-ooxml/src/test/java/org/apache/poi/xslf/XSLFTestDataSamples.java index 0c531ccd48..1f78e24adf 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xslf/XSLFTestDataSamples.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xslf/XSLFTestDataSamples.java @@ -43,7 +43,7 @@ public class XSLFTestDataSamples { } public static XMLSlideShow writeOutAndReadBack(XMLSlideShow doc) throws IOException { - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(4096)) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(4096).get()) { doc.write(baos); try (InputStream bais = baos.toInputStream()) { return new XMLSlideShow(bais); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFShape.java b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFShape.java index 5e479e83c7..5b6a7229f8 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFShape.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFShape.java @@ -90,7 +90,7 @@ class TestXSLFShape { void testReplaceTextInShapes() throws IOException { try ( XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx"); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { assertEquals(6, ppt.getSlides().size()); XSLFSlide slide0 = ppt.getSlides().get(0); @@ -135,7 +135,7 @@ class TestXSLFShape { void testReplaceTextInShapesXDDF() throws IOException { try ( XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx"); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { assertEquals(6, ppt.getSlides().size()); XSLFSlide slide0 = ppt.getSlides().get(0); @@ -180,7 +180,7 @@ class TestXSLFShape { void testCloneSlideAndReplaceText() throws IOException { try ( XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx"); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { assertEquals(6, ppt.getSlides().size()); XSLFSlide slide0 = ppt.getSlides().get(0); @@ -245,7 +245,7 @@ class TestXSLFShape { void testCloneSlideAndReplaceTextXDDF() throws IOException { try ( XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx"); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { assertEquals(6, ppt.getSlides().size()); XSLFSlide slide0 = ppt.getSlides().get(0); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java index 5d73bdf1a4..f6c5570003 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java @@ -452,7 +452,7 @@ class TestXSLFTextParagraph { assertEquals("This is a highlight test", sh.getText()); - DummyGraphics2d dgfx = new DummyGraphics2d(new NullPrintStream()) { + DummyGraphics2d dgfx = new DummyGraphics2d(NullPrintStream.INSTANCE) { @Override public void drawString(AttributedCharacterIterator iterator, float x, float y) { // For the test file, common sl draws textruns one by one and not mixed diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/DeferredSXSSFITestDataProvider.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/DeferredSXSSFITestDataProvider.java index c915390dc2..59c1322fc6 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/DeferredSXSSFITestDataProvider.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/DeferredSXSSFITestDataProvider.java @@ -68,7 +68,7 @@ public final class DeferredSXSSFITestDataProvider implements ITestDataProvider { throw new IllegalArgumentException("Expected an instance of XSSFWorkbook"); } - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) { wb.write(baos); try (InputStream is = baos.toInputStream()) { return new XSSFWorkbook(is); @@ -82,7 +82,7 @@ public final class DeferredSXSSFITestDataProvider implements ITestDataProvider { * Returns an XSSFWorkbook since SXSSFWorkbook is write-only */ public XSSFWorkbook inMemoryWriteOutAndReadBack(SXSSFWorkbook wb) { - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) { wb.writeAvoidingTempFiles(baos); try (InputStream is = baos.toInputStream()) { return new XSSFWorkbook(is); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/SXSSFITestDataProvider.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/SXSSFITestDataProvider.java index c43a9cb38c..1b9d291aa6 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/SXSSFITestDataProvider.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/SXSSFITestDataProvider.java @@ -67,7 +67,7 @@ public class SXSSFITestDataProvider implements ITestDataProvider { throw new IllegalArgumentException("Expected an instance of SXSSFWorkbook"); } - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) { wb.write(baos); try (InputStream is = baos.toInputStream()) { return new XSSFWorkbook(is); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/TestSSUtilVsXSSFColor.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/TestSSUtilVsXSSFColor.java index 0aaceecd61..1a0b577281 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/TestSSUtilVsXSSFColor.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/TestSSUtilVsXSSFColor.java @@ -35,7 +35,7 @@ class TestSSUtilVsXSSFColor { try ( XSSFWorkbook workbook = new XSSFWorkbook(); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { XSSFCellStyle cellStyle = workbook.createCellStyle(); final String rgbS = "ffff00"; diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFMemoryLeak.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFMemoryLeak.java index 3b35c52ac9..16ca608c0d 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFMemoryLeak.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFMemoryLeak.java @@ -72,7 +72,7 @@ public class TestXSSFMemoryLeak { // not freed until we free up the Cell itself //verifier.addObject(ctCell); - try (OutputStream out = new UnsynchronizedByteArrayOutputStream(8192)) { + try (OutputStream out = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(8192).get()) { wb.write(out); } diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/XSSFTestDataSamples.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/XSSFTestDataSamples.java index 30cb09a09a..882ac23078 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/XSSFTestDataSamples.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/XSSFTestDataSamples.java @@ -116,7 +116,7 @@ public class XSSFTestDataSamples { * @throws IOException If writing the file fails */ public static <R extends Workbook> UnsynchronizedByteArrayOutputStream writeOut(R wb) throws IOException { - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(8192); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(8192).get(); wb.write(out); return out; } diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java index 96565866fb..8dd8a70e23 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java @@ -376,7 +376,7 @@ public final class TestXSSFReader { @Test void testBug65676() throws Exception { - try (UnsynchronizedByteArrayOutputStream output = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream output = UnsynchronizedByteArrayOutputStream.builder().get()) { try(Workbook wb = new SXSSFWorkbook()) { Row r = wb.createSheet("Sheet").createRow(0); r.createCell(0).setCellValue(1.2); /* A1: Number 1.2 */ diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java index 66c7ae39e5..8fbd2ad535 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java @@ -72,7 +72,7 @@ public final class TestXSSFExportToXML { XSSFMap map = mapInfo.getXSSFMapById(1); XSSFExportToXml exporter = new XSSFExportToXml(map); - UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get(); exporter.exportToXML(os, true); String xml = os.toString(StandardCharsets.UTF_8); @@ -120,7 +120,7 @@ public final class TestXSSFExportToXML { XSSFMap map = mapInfo.getXSSFMapById(1); XSSFExportToXml exporter = new XSSFExportToXml(map); - UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get(); exporter.exportToXML(os, true); String xml = os.toString(StandardCharsets.UTF_8); @@ -194,7 +194,7 @@ public final class TestXSSFExportToXML { XSSFExportToXml exporter = new XSSFExportToXml(map); String xml; - try (UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get()) { exporter.exportToXML(os, true); xml = os.toString(StandardCharsets.UTF_8); } @@ -231,7 +231,7 @@ public final class TestXSSFExportToXML { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXMLMapping-singleattributenamespace.xlsx")) { for (XSSFMap map : wb.getCustomXMLMappings()) { XSSFExportToXml exporter = new XSSFExportToXml(map); - UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get(); SAXParseException ex = assertThrows(SAXParseException.class, () -> exporter.exportToXML(os, true)); assertTrue(p.matcher(ex.getMessage()).find(), "Did not find pattern " + p + " in " + ex.getMessage()); @@ -256,7 +256,7 @@ public final class TestXSSFExportToXML { assertNotNull(map, "XSSFMap is null"); XSSFExportToXml exporter = new XSSFExportToXml(map); - UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get(); exporter.exportToXML(os, true); String xmlData = os.toString(StandardCharsets.UTF_8); @@ -300,7 +300,7 @@ public final class TestXSSFExportToXML { assertNotNull(map, "XSSFMap is null"); XSSFExportToXml exporter = new XSSFExportToXml(map); - UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get(); exporter.exportToXML(os, true); String xmlData = os.toString(StandardCharsets.UTF_8); @@ -335,7 +335,7 @@ public final class TestXSSFExportToXML { assertNotNull(map, "XSSFMap is null"); XSSFExportToXml exporter = new XSSFExportToXml(map); - UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get(); exporter.exportToXML(os, true); String xmlData = os.toString(StandardCharsets.UTF_8); @@ -374,7 +374,7 @@ public final class TestXSSFExportToXML { assertNotNull(map, "XSSFMap is null"); XSSFExportToXml exporter = new XSSFExportToXml(map); - UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get(); exporter.exportToXML(os, true); String xmlData = os.toString(StandardCharsets.UTF_8); @@ -400,7 +400,7 @@ public final class TestXSSFExportToXML { for (XSSFMap map : wb.getCustomXMLMappings()) { XSSFExportToXml exporter = new XSSFExportToXml(map); - UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get(); exporter.exportToXML(os, true); String xmlData = os.toString(StandardCharsets.UTF_8); @@ -478,7 +478,7 @@ public final class TestXSSFExportToXML { assertNotNull(map, "XSSFMap is null"); XSSFExportToXml exporter = new XSSFExportToXml(map); - UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get(); exporter.exportToXML(os, true); String xmlData = os.toString(StandardCharsets.UTF_8); @@ -556,7 +556,7 @@ public final class TestXSSFExportToXML { assertNotNull(map, "XSSFMap is null"); XSSFExportToXml exporter = new XSSFExportToXml(map); - UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get(); exporter.exportToXML(os, true); String xmlData = os.toString(StandardCharsets.UTF_8); @@ -587,7 +587,7 @@ public final class TestXSSFExportToXML { assertNotNull(map, "XSSFMap is null"); XSSFExportToXml exporter = new XSSFExportToXml(map); - UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get(); exporter.exportToXML(os, false); String xmlData = os.toString(StandardCharsets.UTF_8); @@ -619,7 +619,7 @@ public final class TestXSSFExportToXML { assertNotNull(map, "XSSFMap is null"); XSSFExportToXml exporter = new XSSFExportToXml(map); - UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get(); exporter.exportToXML(os, true); String xmlData = os.toString(StandardCharsets.UTF_8); @@ -645,7 +645,7 @@ public final class TestXSSFExportToXML { for (XSSFMap map : mappings) { XSSFExportToXml exporter = new XSSFExportToXml(map); - UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get(); exporter.exportToXML(os, false); assertNotNull(os.toString(StandardCharsets.UTF_8)); } @@ -657,7 +657,7 @@ public final class TestXSSFExportToXML { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("61281.xlsx")) { for (XSSFMap map : wb.getCustomXMLMappings()) { XSSFExportToXml exporter = new XSSFExportToXml(map); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); exporter.exportToXML(bos, true); assertNotNull(DocumentHelper.readDocument(bos.toInputStream())); String exportedXml = bos.toString(StandardCharsets.UTF_8); @@ -671,7 +671,7 @@ public final class TestXSSFExportToXML { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("xxe_in_schema.xlsx")) { for (XSSFMap map : wb.getCustomXMLMappings()) { XSSFExportToXml exporter = new XSSFExportToXml(map); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); assertThrows(SAXParseException.class, () -> exporter.exportToXML(bos, true)); } } diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/OpcZipTest.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/OpcZipTest.java index f0339a9165..1fe25dcf09 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/OpcZipTest.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/OpcZipTest.java @@ -34,8 +34,8 @@ class OpcZipTest { void compareOutput() throws Exception { Map<String, String> contents = createContents(); try ( - UnsynchronizedByteArrayOutputStream bos1 = new UnsynchronizedByteArrayOutputStream(); - UnsynchronizedByteArrayOutputStream bos2 = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos1 = UnsynchronizedByteArrayOutputStream.builder().get(); + UnsynchronizedByteArrayOutputStream bos2 = UnsynchronizedByteArrayOutputStream.builder().get() ) { try (OpcOutputStream zip = new OpcOutputStream(bos1)) { for (Map.Entry<String, String> entry : contents.entrySet()) { diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFSheet.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFSheet.java index 41df3b3384..015f608cf2 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFSheet.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFSheet.java @@ -119,7 +119,7 @@ public final class TestSXSSFSheet extends BaseTestXSheet { @Test void flushBufferedDaat() throws IOException { - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { try (SXSSFWorkbook wb = new SXSSFWorkbook(1)) { SXSSFSheet sheet = wb.createSheet("my-sheet"); @@ -193,7 +193,7 @@ public final class TestSXSSFSheet extends BaseTestXSheet { //one level sheet.groupRow(9, 10); - try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { workbook.write(bos); try(XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) { XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0); @@ -223,7 +223,7 @@ public final class TestSXSSFSheet extends BaseTestXSheet { //two level sheet.groupRow(10, 13); - try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { workbook.write(bos); try(XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) { XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java index c0011da4e2..6af4542525 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java @@ -19,7 +19,6 @@ package org.apache.poi.xssf.streaming; -import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM; import static org.apache.poi.POITestCase.assertEndsWith; import static org.apache.poi.POITestCase.assertStartsWith; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -37,6 +36,7 @@ import java.io.IOException; import java.time.LocalDate; import java.util.Arrays; +import org.apache.commons.io.output.NullOutputStream; import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; import org.apache.poi.POIDataSamples; import org.apache.poi.common.usermodel.HyperlinkType; @@ -358,12 +358,12 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook { void bug53515() throws Exception { try (Workbook wb1 = new SXSSFWorkbook(10)) { populateWorkbook(wb1); - assertDoesNotThrow(() -> wb1.write(NULL_OUTPUT_STREAM)); - assertDoesNotThrow(() -> wb1.write(NULL_OUTPUT_STREAM)); + assertDoesNotThrow(() -> wb1.write(NullOutputStream.INSTANCE)); + assertDoesNotThrow(() -> wb1.write(NullOutputStream.INSTANCE)); try (Workbook wb2 = new XSSFWorkbook()) { populateWorkbook(wb2); - assertDoesNotThrow(() -> wb2.write(NULL_OUTPUT_STREAM)); - assertDoesNotThrow(() -> wb2.write(NULL_OUTPUT_STREAM)); + assertDoesNotThrow(() -> wb2.write(NullOutputStream.INSTANCE)); + assertDoesNotThrow(() -> wb2.write(NullOutputStream.INSTANCE)); } } } @@ -481,7 +481,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook { } } - assertDoesNotThrow(() -> swb.write(NULL_OUTPUT_STREAM)); + assertDoesNotThrow(() -> swb.write(NullOutputStream.INSTANCE)); swb.dispose(); } } @@ -499,7 +499,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook { File input = XSSFTestDataSamples.getSampleFile("sample.xlsx"); try (OPCPackage pkg = OPCPackage.open(input, PackageAccess.READ)) { - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); try (XSSFWorkbook xssf = new XSSFWorkbook(pkg)) { try (SXSSFWorkbook wb = new SXSSFWorkbook(xssf, 2)) { Sheet s = wb.createSheet(sheetName); @@ -542,7 +542,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook { void addHyperlink() throws Exception { try ( SXSSFWorkbook wb = new SXSSFWorkbook(); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { SXSSFSheet sheet = wb.createSheet("s1"); SXSSFRow row = sheet.createRow(0); @@ -568,7 +568,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook { void addDimension() throws IOException { try ( SXSSFWorkbook wb = new SXSSFWorkbook(); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { SXSSFSheet sheet = wb.createSheet(); sheet.createRow(2).createCell(3).setCellValue("top left"); @@ -587,7 +587,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook { void addDimension1() throws IOException { try ( SXSSFWorkbook wb = new SXSSFWorkbook(1); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { SXSSFSheet sheet = wb.createSheet(); sheet.createRow(2).createCell(3).setCellValue("top left"); @@ -612,7 +612,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook { assertEquals(6, sheet.getLastRowNum()); try ( SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(wb); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { sxssfWorkbook.write(bos); try (XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) { @@ -627,7 +627,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook { void addDimensionDisabled() throws IOException { try ( SXSSFWorkbook wb = new SXSSFWorkbook(); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { wb.setShouldCalculateSheetDimensions(false); SXSSFSheet sheet = wb.createSheet(); @@ -655,7 +655,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook { void dateStyle() throws IOException { try ( SXSSFWorkbook workbook = new SXSSFWorkbook(); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { SXSSFSheet sheet = workbook.createSheet(); SXSSFRow row = sheet.createRow(0); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java index d5afe8ea15..d89ffbb2b3 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java @@ -20,7 +20,6 @@ package org.apache.poi.xssf.streaming; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -32,6 +31,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.List; +import org.apache.commons.io.output.NullOutputStream; import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.OPCPackage; @@ -58,7 +58,7 @@ public final class TestSXSSFWorkbookWithCustomZipEntrySource { // write an unencrypted workbook to disk, but any temporary files are encrypted @Test void customZipEntrySource() throws IOException { - UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(8192); + UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(8192).get(); try (SXSSFWorkbookWithCustomZipEntrySource workbook = new SXSSFWorkbookWithCustomZipEntrySource()) { SXSSFSheet sheet1 = workbook.createSheet(sheetName); SXSSFRow row1 = sheet1.createRow(1); @@ -113,7 +113,7 @@ public final class TestSXSSFWorkbookWithCustomZipEntrySource { SXSSFRow row1 = sheet1.createRow(1); SXSSFCell cell1 = row1.createCell(1); cell1.setCellValue(cellValue); - workbook.write(NULL_OUTPUT_STREAM); + workbook.write(NullOutputStream.INSTANCE); workbook.close(); List<File> tempFiles = workbook.getTempFiles(); assertEquals(1, tempFiles.size()); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithNullAutoSizeTracker.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithNullAutoSizeTracker.java index 1b2352b29d..797ed4acc2 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithNullAutoSizeTracker.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithNullAutoSizeTracker.java @@ -19,6 +19,7 @@ package org.apache.poi.xssf.streaming; +import org.apache.commons.io.output.NullOutputStream; import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; import org.apache.poi.POIDataSamples; import org.apache.poi.common.usermodel.HyperlinkType; @@ -44,7 +45,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.Arrays; -import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM; import static org.apache.poi.POITestCase.assertEndsWith; import static org.apache.poi.POITestCase.assertStartsWith; import static org.junit.jupiter.api.Assertions.*; @@ -337,12 +337,12 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook { void bug53515() throws Exception { try (Workbook wb1 = new SXSSFWorkbook(10)) { populateWorkbook(wb1); - assertDoesNotThrow(() -> wb1.write(NULL_OUTPUT_STREAM)); - assertDoesNotThrow(() -> wb1.write(NULL_OUTPUT_STREAM)); + assertDoesNotThrow(() -> wb1.write(NullOutputStream.INSTANCE)); + assertDoesNotThrow(() -> wb1.write(NullOutputStream.INSTANCE)); try (Workbook wb2 = new XSSFWorkbook()) { populateWorkbook(wb2); - assertDoesNotThrow(() -> wb2.write(NULL_OUTPUT_STREAM)); - assertDoesNotThrow(() -> wb2.write(NULL_OUTPUT_STREAM)); + assertDoesNotThrow(() -> wb2.write(NullOutputStream.INSTANCE)); + assertDoesNotThrow(() -> wb2.write(NullOutputStream.INSTANCE)); } } } @@ -460,7 +460,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook { } } - assertDoesNotThrow(() -> swb.write(NULL_OUTPUT_STREAM)); + assertDoesNotThrow(() -> swb.write(NullOutputStream.INSTANCE)); swb.dispose(); } } @@ -478,7 +478,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook { File input = XSSFTestDataSamples.getSampleFile("sample.xlsx"); try (OPCPackage pkg = OPCPackage.open(input, PackageAccess.READ)) { - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); try (XSSFWorkbook xssf = new XSSFWorkbook(pkg)) { try (SXSSFWorkbook wb = new SXSSFWorkbook(xssf, 2)) { Sheet s = wb.createSheet(sheetName); @@ -521,7 +521,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook { void addHyperlink() throws Exception { try ( SXSSFWorkbook wb = new SXSSFWorkbook(); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { SXSSFSheet sheet = wb.createSheet("s1"); SXSSFRow row = sheet.createRow(0); @@ -547,7 +547,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook { void addDimension() throws IOException { try ( SXSSFWorkbook wb = new SXSSFWorkbook(); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { SXSSFSheet sheet = wb.createSheet(); sheet.createRow(2).createCell(3).setCellValue("top left"); @@ -566,7 +566,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook { void addDimension1() throws IOException { try ( SXSSFWorkbook wb = new SXSSFWorkbook(1); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { SXSSFSheet sheet = wb.createSheet(); sheet.createRow(2).createCell(3).setCellValue("top left"); @@ -591,7 +591,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook { assertEquals(6, sheet.getLastRowNum()); try ( SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(wb); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { sxssfWorkbook.write(bos); try (XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) { @@ -606,7 +606,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook { void addDimensionDisabled() throws IOException { try ( SXSSFWorkbook wb = new SXSSFWorkbook(); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { wb.setShouldCalculateSheetDimensions(false); SXSSFSheet sheet = wb.createSheet(); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java index 1c3690f101..c269b7c913 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java @@ -253,7 +253,7 @@ public final class TestSXSSFBugs extends BaseTestBugzillaIssues { @Test void test65619() throws Exception { - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { try (SXSSFWorkbook workbook = new SXSSFWorkbook(100)) { SXSSFSheet sheet = workbook.createSheet("Test Sheet 1"); Font font = workbook.createFont(); @@ -308,7 +308,7 @@ public final class TestSXSSFBugs extends BaseTestBugzillaIssues { assertEquals(value, cell.getStringCellValue()); // so far so good - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { wb.write(bos); try (XSSFWorkbook testWb = new XSSFWorkbook(bos.toInputStream())) { @@ -356,7 +356,7 @@ public final class TestSXSSFBugs extends BaseTestBugzillaIssues { assertEquals(blueStyle.getIndex(), r3.getCell(4).getCellStyle().getIndex()); assertEquals(pinkStyle.getIndex(), r3.getCell(6).getCellStyle().getIndex()); - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { wb.write(bos); try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) { XSSFSheet wb2Sheet = wb2.getSheetAt(0); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java index 0b307277f5..9b26f2e0aa 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java @@ -278,7 +278,7 @@ public final class TestUnfixedBugs { checkRow57423(testSheet, 17, "17"); checkRow57423(testSheet, 18, "18"); - UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().get(); ((XSSFSheet)testSheet).write(stream); // verify that the resulting XML has the rows in correct order as required by Excel diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index a9240a6f0a..7b735206d4 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -19,7 +19,6 @@ package org.apache.poi.xssf.usermodel; import static java.time.Duration.between; import static java.time.Instant.now; -import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM; import static org.apache.logging.log4j.util.Unbox.box; import static org.apache.poi.extractor.ExtractorFactory.OOXML_PACKAGE; import static org.apache.poi.openxml4j.opc.TestContentType.isOldXercesActive; @@ -48,6 +47,7 @@ import java.util.*; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipFile; +import org.apache.commons.io.output.NullOutputStream; import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -1537,7 +1537,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { Thread.sleep(10); } - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(8096); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(8096).get(); wb.write(bos); byte[] firstSave = bos.toByteArray(); bos.reset(); @@ -2982,7 +2982,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { // we currently only populate the dimension during writing out // to avoid having to iterate all rows/cells in each add/remove of a row or cell - wb.write(NULL_OUTPUT_STREAM); + wb.write(NullOutputStream.INSTANCE); assertEquals("B2:H5", ((XSSFSheet) sheet).getCTWorksheet().getDimension().getRef()); } @@ -3003,7 +3003,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { // we currently only populate the dimension during writing out // to avoid having to iterate all rows/cells in each add/remove of a row or cell - wb.write(NULL_OUTPUT_STREAM); + wb.write(NullOutputStream.INSTANCE); assertEquals("B2:XFD5", ((XSSFSheet) sheet).getCTWorksheet().getDimension().getRef()); } @@ -3691,7 +3691,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { assertEquals(blueStyle.getIndex(), r3.getCell(4).getCellStyle().getIndex()); assertEquals(pinkStyle.getIndex(), r3.getCell(6).getCellStyle().getIndex()); - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { wb.write(bos); try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) { XSSFSheet wb2Sheet = wb2.getSheetAt(0); @@ -3778,13 +3778,13 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { } // read bytes of workbook before - UnsynchronizedByteArrayOutputStream bosOrig = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bosOrig = UnsynchronizedByteArrayOutputStream.builder().get(); try (FileInputStream fis = new FileInputStream(temp_excel_poi)) { IOUtils.copy(fis, bosOrig); } // for the encrypted bytes - UnsynchronizedByteArrayOutputStream bosEnc = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bosEnc = UnsynchronizedByteArrayOutputStream.builder().get(); /* encrypt excel by poi */ try (POIFSFileSystem fs = new POIFSFileSystem()) { @@ -3810,7 +3810,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { } // for the decrytped bytes - UnsynchronizedByteArrayOutputStream bosDec = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bosDec = UnsynchronizedByteArrayOutputStream.builder().get(); /* decrypt excel by poi */ try (POIFSFileSystem fileSystem = new POIFSFileSystem(temp_excel_poi_encrypt)) { diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFComment.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFComment.java index 8a5a17ce2c..a5e07eb5f3 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFComment.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFComment.java @@ -311,7 +311,7 @@ public final class TestXSSFComment extends BaseTestCellComment { @Test void bug59388CommentVisible() throws IOException { - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("59388.xlsx")) { Sheet sheet = wb.getSheetAt(0); Cell a1 = sheet.getRow(0).getCell(0); @@ -474,7 +474,7 @@ public final class TestXSSFComment extends BaseTestCellComment { } private void _testMoveIsSaved(Workbook workbook) throws Exception { - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { CreationHelper factory = workbook.getCreationHelper(); Sheet sheet = workbook.createSheet(); Row row = sheet.createRow(0); @@ -511,7 +511,7 @@ public final class TestXSSFComment extends BaseTestCellComment { } private void _testModificationIsSaved(Workbook workbook) throws Exception { - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { CreationHelper factory = workbook.getCreationHelper(); Sheet sheet = workbook.createSheet(); Row row = sheet.createRow(0); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java index 88f903179d..9504b20ac8 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java @@ -386,7 +386,7 @@ public final class TestXSSFSheet extends BaseTestXSheet { void saveGroupColumns() throws IOException { try ( XSSFWorkbook workbook = new XSSFWorkbook(); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { XSSFSheet sheet = workbook.createSheet(); XSSFRow row0 = sheet.createRow(0); @@ -2268,7 +2268,7 @@ public final class TestXSSFSheet extends BaseTestXSheet { void testBug64536() throws IOException { try ( XSSFWorkbook xssfWorkbook = (XSSFWorkbook) _testDataProvider.openSampleWorkbook("1_NoIden.xlsx"); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { XSSFSheet fileSheet = xssfWorkbook.getSheetAt(0); assertEquals(CellRangeAddress.valueOf("B1:D9"), fileSheet.getDimension()); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java index 2e3d1ec76e..8cdf4706f3 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java @@ -651,7 +651,7 @@ public final class TestXSSFTable { void testNamesWithNewLines() throws IOException { try ( XSSFWorkbook wb = new XSSFWorkbook(); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { XSSFSheet sheet = wb.createSheet(); @@ -739,7 +739,7 @@ public final class TestXSSFTable { void bug66213() throws IOException { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("table-sample.xlsx")) { wb.cloneSheet(0, "Test"); - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { wb.write(bos); try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) { XSSFSheet sheet0 = wb2.getSheetAt(0); @@ -757,7 +757,7 @@ public final class TestXSSFTable { void testCloneConditionalFormattingSamples() throws IOException { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("ConditionalFormattingSamples.xlsx")) { wb.cloneSheet(0, "Test"); - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { wb.write(bos); try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) { XSSFSheet sheet0 = wb2.getSheetAt(0); @@ -773,7 +773,7 @@ public final class TestXSSFTable { void testCloneSingleCellTable() throws IOException { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("SingleCellTable.xlsx")) { wb.cloneSheet(0, "Test"); - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { wb.write(bos); try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) { XSSFSheet sheet0 = wb2.getSheetAt(0); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java index 4ee8a83d3c..7822c97410 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java @@ -103,7 +103,7 @@ class TestXSSFVMLDrawing { assertEquals("[True]", cldata.getVisibleList().toString()); //serialize and read again - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); vml.write(out); XSSFVMLDrawing vml2 = new XSSFVMLDrawing(); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java index ac903cc661..10ccde01fa 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java @@ -17,6 +17,7 @@ package org.apache.poi.xssf.usermodel; +import org.apache.commons.io.output.NullOutputStream; import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; import org.apache.poi.POIDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples; @@ -80,7 +81,6 @@ import java.util.Iterator; import java.util.List; import java.util.zip.CRC32; -import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM; import static org.apache.poi.hssf.HSSFTestDataSamples.openSampleFileStream; import static org.apache.poi.xssf.XSSFTestDataSamples.openSampleWorkbook; import static org.apache.poi.xssf.XSSFTestDataSamples.writeOut; @@ -573,7 +573,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook { sheet.groupColumn((short) 4, (short) 5); accessWorkbook(workbook); - workbook.write(NULL_OUTPUT_STREAM); + workbook.write(NullOutputStream.INSTANCE); accessWorkbook(workbook); } } @@ -1240,7 +1240,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook { @Test void testNewWorkbookWithTempFilePackageParts() throws Exception { - try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { assertFalse(ZipPackage.useTempFilePackageParts(), "useTempFilePackageParts defaults to false?"); assertFalse(ZipPackage.encryptTempFilePackageParts(), "encryptTempFilePackageParts defaults to false?"); ZipPackage.setUseTempFilePackageParts(true); @@ -1264,7 +1264,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook { @Test void testNewWorkbookWithEncryptedTempFilePackageParts() throws Exception { - try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { assertFalse(ZipPackage.useTempFilePackageParts(), "useTempFilePackageParts defaults to false?"); assertFalse(ZipPackage.encryptTempFilePackageParts(), "encryptTempFilePackageParts defaults to false?"); ZipPackage.setUseTempFilePackageParts(true); @@ -1293,8 +1293,8 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook { String nameA = "link-external-workbook-a.xlsx"; try ( - UnsynchronizedByteArrayOutputStream bosA = new UnsynchronizedByteArrayOutputStream(); - UnsynchronizedByteArrayOutputStream bosB = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bosA = UnsynchronizedByteArrayOutputStream.builder().get(); + UnsynchronizedByteArrayOutputStream bosB = UnsynchronizedByteArrayOutputStream.builder().get(); XSSFWorkbook workbookA = new XSSFWorkbook(); XSSFWorkbook workbookB = new XSSFWorkbook() ) { @@ -1343,8 +1343,8 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook { String nameA = "cache-external-workbook-a.xlsx"; try ( - UnsynchronizedByteArrayOutputStream bosA = new UnsynchronizedByteArrayOutputStream(); - UnsynchronizedByteArrayOutputStream bosB = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bosA = UnsynchronizedByteArrayOutputStream.builder().get(); + UnsynchronizedByteArrayOutputStream bosB = UnsynchronizedByteArrayOutputStream.builder().get(); XSSFWorkbook workbookA = new XSSFWorkbook(); XSSFWorkbook workbookB = new XSSFWorkbook() ) { @@ -1381,7 +1381,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook { @Test void checkExistingFileForR1C1Refs() throws IOException { try ( - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); XSSFWorkbook wb = openSampleWorkbook("WithTable.xlsx") ) { assertEquals(CellReferenceType.A1, wb.getCellReferenceType()); @@ -1397,7 +1397,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook { @Test void checkNewFileForR1C1Refs() throws IOException { try ( - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); XSSFWorkbook wb = new XSSFWorkbook() ) { assertEquals(CellReferenceType.UNKNOWN, wb.getCellReferenceType()); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/charts/TestXSSFBubbleChartData.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/charts/TestXSSFBubbleChartData.java index 6eacb5be89..2d2271dbf6 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/charts/TestXSSFBubbleChartData.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/charts/TestXSSFBubbleChartData.java @@ -152,7 +152,7 @@ final class TestXSSFBubbleChartData { setRoundedCorners(chart, false); // Write the output to a file - try (UnsynchronizedByteArrayOutputStream outStream = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream outStream = UnsynchronizedByteArrayOutputStream.builder().get()) { wb.write(outStream); try (XSSFWorkbook wb2 = new XSSFWorkbook(outStream.toInputStream())) { // see if this fails diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/util/TestEvilUnclosedBRFixingInputStream.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/util/TestEvilUnclosedBRFixingInputStream.java index ec2b4cc5e6..27d478eed1 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/util/TestEvilUnclosedBRFixingInputStream.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/util/TestEvilUnclosedBRFixingInputStream.java @@ -69,7 +69,7 @@ public final class TestEvilUnclosedBRFixingInputStream { // overflow or only part in the buffer for(int i=5; i<orig.length; i++) { try (EvilUnclosedBRFixingInputStream inp = new EvilUnclosedBRFixingInputStream(orig); - UnsynchronizedByteArrayOutputStream bout = new UnsynchronizedByteArrayOutputStream()) { + UnsynchronizedByteArrayOutputStream bout = UnsynchronizedByteArrayOutputStream.builder().get()) { for (;;) { byte[] b = new byte[i]; int r = inp.read(b); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xwpf/XWPFTestDataSamples.java b/poi-ooxml/src/test/java/org/apache/poi/xwpf/XWPFTestDataSamples.java index e38b5b1e2d..510765d318 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xwpf/XWPFTestDataSamples.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xwpf/XWPFTestDataSamples.java @@ -32,7 +32,7 @@ public class XWPFTestDataSamples { } public static XWPFDocument writeOutAndReadBack(XWPFDocument doc) throws IOException { - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(4096); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(4096).get(); doc.write(baos); return new XWPFDocument(baos.toInputStream()); } diff --git a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestChangeTracking.java b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestChangeTracking.java index 0b74bfa5f1..960b6c5c7e 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestChangeTracking.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestChangeTracking.java @@ -58,7 +58,7 @@ class TestChangeTracking { r1.setText("Lorem ipsum dolor sit amet."); doc.setTrackRevisions(true); - try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) { doc.write(out); try (InputStream inputStream = out.toInputStream()) { |