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 | |
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
246 files changed, 550 insertions, 490 deletions
diff --git a/osgi/src/test/java/org/apache/poi/osgi/OSGiExtractorsIT.java b/osgi/src/test/java/org/apache/poi/osgi/OSGiExtractorsIT.java index 3bf58a2b61..0196bfb6f0 100755 --- a/osgi/src/test/java/org/apache/poi/osgi/OSGiExtractorsIT.java +++ b/osgi/src/test/java/org/apache/poi/osgi/OSGiExtractorsIT.java @@ -57,7 +57,7 @@ public class OSGiExtractorsIT extends BaseOSGiTestCase { box.setText("Hello, World!"); box.setAnchor(new Rectangle(36, 15, 648, 65)); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); ppt.write(out); return out.toByteArray(); } @@ -66,7 +66,7 @@ public class OSGiExtractorsIT extends BaseOSGiTestCase { Sheet s = wb.createSheet("OSGi"); s.createRow(0).createCell(0).setCellValue("Hello, World!"); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); wb.write(out); return out.toByteArray(); diff --git a/osgi/src/test/java/org/apache/poi/osgi/OSGiSlideShowIT.java b/osgi/src/test/java/org/apache/poi/osgi/OSGiSlideShowIT.java index 9744c36ca9..3e4ebdf96e 100755 --- a/osgi/src/test/java/org/apache/poi/osgi/OSGiSlideShowIT.java +++ b/osgi/src/test/java/org/apache/poi/osgi/OSGiSlideShowIT.java @@ -75,7 +75,7 @@ public class OSGiSlideShowIT extends BaseOSGiTestCase { } box2.setAnchor(new Rectangle(36, 80, 648, 400)); - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) { ppt.write(baos); try (InputStream bais = baos.toInputStream()) { ppt = SlideShowFactory.create(bais); diff --git a/osgi/src/test/java/org/apache/poi/osgi/OSGiSpreadsheetIT.java b/osgi/src/test/java/org/apache/poi/osgi/OSGiSpreadsheetIT.java index 618b76e36c..7793754bca 100644 --- a/osgi/src/test/java/org/apache/poi/osgi/OSGiSpreadsheetIT.java +++ b/osgi/src/test/java/org/apache/poi/osgi/OSGiSpreadsheetIT.java @@ -48,7 +48,7 @@ public class OSGiSpreadsheetIT extends BaseOSGiTestCase { s.createRow(0).createCell(0).setCellValue("With OSGi"); s.createRow(1).createCell(0).setCellFormula("SUM(A1:B3)"); - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) { wb.write(baos); try (InputStream bais = baos.toInputStream()) { wb = WorkbookFactory.create(bais); diff --git a/poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/OfficeDrawing.java b/poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/OfficeDrawing.java index 2cefd3d87f..c3a5b8c400 100644 --- a/poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/OfficeDrawing.java +++ b/poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/OfficeDrawing.java @@ -192,7 +192,7 @@ public final class OfficeDrawing { private static int loadPicture( String path, HSSFWorkbook wb ) throws IOException { int pictureIndex; try (FileInputStream fis = new FileInputStream(path); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { IOUtils.copy(fis, bos); pictureIndex = wb.addPicture(bos.toByteArray(), Workbook.PICTURE_TYPE_PNG); } diff --git a/poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/CustomXMLMapping.java b/poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/CustomXMLMapping.java index edba46bba3..e1a912e734 100644 --- a/poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/CustomXMLMapping.java +++ b/poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/CustomXMLMapping.java @@ -38,7 +38,7 @@ public final class CustomXMLMapping { for (XSSFMap map : wb.getCustomXMLMappings()) { 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); System.out.println(xml); diff --git a/poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java b/poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java index a9bed39008..b172b38295 100644 --- a/poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java +++ b/poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java @@ -35,7 +35,7 @@ import org.junit.jupiter.api.Test; public class TestXLSX2CSV { private PrintStream err; - private final UnsynchronizedByteArrayOutputStream errorBytes = new UnsynchronizedByteArrayOutputStream(); + private final UnsynchronizedByteArrayOutputStream errorBytes = UnsynchronizedByteArrayOutputStream.builder().get(); @BeforeEach public void setUp() throws UnsupportedEncodingException { @@ -77,7 +77,7 @@ public class TestXLSX2CSV { @Test public void testSampleFile() throws Exception { - final UnsynchronizedByteArrayOutputStream outputBytes = new UnsynchronizedByteArrayOutputStream(); + final UnsynchronizedByteArrayOutputStream outputBytes = UnsynchronizedByteArrayOutputStream.builder().get(); PrintStream out = new PrintStream(outputBytes, true, StandardCharsets.UTF_8.name()); // The package open is instantaneous, as it should be. @@ -96,7 +96,7 @@ public class TestXLSX2CSV { @Test public void testMinColumns() throws Exception { - final UnsynchronizedByteArrayOutputStream outputBytes = new UnsynchronizedByteArrayOutputStream(); + final UnsynchronizedByteArrayOutputStream outputBytes = UnsynchronizedByteArrayOutputStream.builder().get(); PrintStream out = new PrintStream(outputBytes, true, StandardCharsets.UTF_8.name()); // The package open is instantaneous, as it should be. diff --git a/poi-integration/src/test/java/org/apache/poi/stress/POIFSFileHandler.java b/poi-integration/src/test/java/org/apache/poi/stress/POIFSFileHandler.java index 5dd01bdff5..14b26c395d 100644 --- a/poi-integration/src/test/java/org/apache/poi/stress/POIFSFileHandler.java +++ b/poi-integration/src/test/java/org/apache/poi/stress/POIFSFileHandler.java @@ -57,7 +57,7 @@ public class POIFSFileHandler extends AbstractFileHandler { } protected void handlePOIDocument(POIDocument doc) throws Exception { - try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) { doc.write(out); try (InputStream in = out.toInputStream(); diff --git a/poi-integration/src/test/java/org/apache/poi/stress/SlideShowHandler.java b/poi-integration/src/test/java/org/apache/poi/stress/SlideShowHandler.java index ec291e1c0b..305793cd1e 100644 --- a/poi-integration/src/test/java/org/apache/poi/stress/SlideShowHandler.java +++ b/poi-integration/src/test/java/org/apache/poi/stress/SlideShowHandler.java @@ -49,7 +49,7 @@ public abstract class SlideShowHandler extends POIFSFileHandler { readPictures(ss); // write out the file - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); ss.write(out); readContent(ss); diff --git a/poi-integration/src/test/java/org/apache/poi/stress/SpreadsheetHandler.java b/poi-integration/src/test/java/org/apache/poi/stress/SpreadsheetHandler.java index 50212654c9..1e57bb856a 100644 --- a/poi-integration/src/test/java/org/apache/poi/stress/SpreadsheetHandler.java +++ b/poi-integration/src/test/java/org/apache/poi/stress/SpreadsheetHandler.java @@ -61,7 +61,7 @@ public abstract class SpreadsheetHandler extends AbstractFileHandler { } private UnsynchronizedByteArrayOutputStream writeToArray(Workbook wb) throws IOException { - UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().get(); wb.write(stream); return stream; } diff --git a/poi-integration/src/test/java/org/apache/poi/stress/XSSFBFileHandler.java b/poi-integration/src/test/java/org/apache/poi/stress/XSSFBFileHandler.java index f60752d6dd..fb130b9d72 100644 --- a/poi-integration/src/test/java/org/apache/poi/stress/XSSFBFileHandler.java +++ b/poi-integration/src/test/java/org/apache/poi/stress/XSSFBFileHandler.java @@ -41,11 +41,11 @@ public class XSSFBFileHandler extends AbstractFileHandler { public void handleFile(InputStream stream, String path) throws Exception { byte[] bytes = IOUtils.toByteArray(stream); - try (OPCPackage opcPackage = OPCPackage.open(new UnsynchronizedByteArrayInputStream(bytes))) { + try (OPCPackage opcPackage = OPCPackage.open(UnsynchronizedByteArrayInputStream.builder().setByteArray(bytes).get())) { testOne(opcPackage); } - testNotHandledByWorkbookException(OPCPackage.open(new UnsynchronizedByteArrayInputStream(bytes))); + testNotHandledByWorkbookException(OPCPackage.open(UnsynchronizedByteArrayInputStream.builder().setByteArray(bytes).get())); } private void testNotHandledByWorkbookException(OPCPackage pkg) throws IOException { diff --git a/poi-integration/src/test/java/org/apache/poi/stress/XSSFFileHandler.java b/poi-integration/src/test/java/org/apache/poi/stress/XSSFFileHandler.java index 314d5ed985..160d7059a2 100644 --- a/poi-integration/src/test/java/org/apache/poi/stress/XSSFFileHandler.java +++ b/poi-integration/src/test/java/org/apache/poi/stress/XSSFFileHandler.java @@ -16,7 +16,6 @@ ==================================================================== */ package org.apache.poi.stress; -import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM; import static org.apache.poi.xssf.XSSFTestDataSamples.getSampleFile; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -36,6 +35,7 @@ import java.util.Set; import javax.xml.transform.TransformerException; +import org.apache.commons.io.output.NullOutputStream; import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.examples.ss.ExcelComparator; @@ -72,7 +72,7 @@ public class XSSFFileHandler extends SpreadsheetHandler { // make sure the potentially large byte-array is freed up quickly again { - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); IOUtils.copy(stream, out); if (pass != null) { @@ -156,7 +156,7 @@ public class XSSFFileHandler extends SpreadsheetHandler { TransformerException { for (XSSFMap map : wb.getCustomXMLMappings()) { XSSFExportToXml exporter = new XSSFExportToXml(map); - exporter.exportToXML(NULL_OUTPUT_STREAM, true); + exporter.exportToXML(NullOutputStream.INSTANCE, true); } } 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()) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java b/poi-scratchpad/src/main/java/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java index 2485589e31..64c2c6fce0 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java @@ -185,7 +185,12 @@ public class OLE2ScratchpadExtractorFactory implements ExtractorProvider { for (AttachmentChunks attachment : msg.getAttachmentFiles()) { if (attachment.getAttachData() != null) { byte[] data = attachment.getAttachData().getValue(); - nonPOIFS.add( new UnsynchronizedByteArrayInputStream(data) ); + try { + nonPOIFS.add(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get() ); + } catch (IOException e) { + // is actually impossible with ByteArray, but still declared in the interface + throw new IllegalStateException(e); + } } else if (attachment.getAttachmentDirectory() != null) { dirs.add(attachment.getAttachmentDirectory().getDirectory()); } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/HDGFLZW.java b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/HDGFLZW.java index 5e70f033a2..1a961963fb 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/HDGFLZW.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/HDGFLZW.java @@ -53,7 +53,7 @@ public class HDGFLZW extends LZWDecompresser { * @throws IOException when the InputStream can't be read */ public byte[] compress(InputStream src) throws IOException { - UnsynchronizedByteArrayOutputStream res = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream res = UnsynchronizedByteArrayOutputStream.builder().get(); compress(src,res); return res.toByteArray(); } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/CompressedStreamStore.java b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/CompressedStreamStore.java index 0009a3d511..d4ca5c8bc9 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/CompressedStreamStore.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/CompressedStreamStore.java @@ -92,7 +92,7 @@ public final class CompressedStreamStore extends StreamStore { * Decompresses the given data, returning it as header + contents */ public static byte[][] decompress(byte[] data, int offset, int length) throws IOException { - try (UnsynchronizedByteArrayInputStream bais = new UnsynchronizedByteArrayInputStream(data, offset, length)) { + try (UnsynchronizedByteArrayInputStream bais = UnsynchronizedByteArrayInputStream.builder().setByteArray(data).setOffset(offset).setLength(length).get()) { // Decompress HDGFLZW lzw = new HDGFLZW(); byte[] decompressed = lzw.decompress(bais); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/draw/HemfImageRenderer.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/draw/HemfImageRenderer.java index 221c9d5a5a..27efbe18a9 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/draw/HemfImageRenderer.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/draw/HemfImageRenderer.java @@ -65,7 +65,7 @@ public class HemfImageRenderer implements ImageRenderer, EmbeddedExtractor { if (!PictureData.PictureType.EMF.contentType.equals(contentType)) { throw new IOException("Invalid picture type"); } - image = new HemfPicture(new UnsynchronizedByteArrayInputStream(data)); + image = new HemfPicture(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get()); } @Override diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfFill.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfFill.java index f1b668e3f0..4930959fde 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfFill.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfFill.java @@ -792,7 +792,7 @@ public final class HemfFill { return (long)undefinedSpace1 + bitmap.init(leis, dibSize); } - final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(cbBmi+cbBits); + final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(cbBmi+cbBits).get(); final long cbBmiSrcAct = IOUtils.copy(leis, bos, cbBmi); assert (cbBmiSrcAct == cbBmi); leis.skipFully(undefinedSpace2); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java index 09c17d054b..6c34385070 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java @@ -396,7 +396,7 @@ public class HemfPlusBrush { public EmfPlusBrushData getBrushData(List<? extends EmfPlusObjectData> continuedObjectData) { EmfPlusBrushData brushData = brushType.constructor.get(); byte[] buf = getRawData(continuedObjectData); - try (UnsynchronizedByteArrayInputStream bis = new UnsynchronizedByteArrayInputStream(buf)){ + try (UnsynchronizedByteArrayInputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(buf).get()){ brushData.init(new LittleEndianInputStream(bis), buf.length); } catch (IOException e) { throw new IllegalStateException(e); @@ -410,7 +410,7 @@ public class HemfPlusBrush { * @throws IllegalStateException if the data cannot be processed */ public byte[] getRawData(List<? extends EmfPlusObjectData> continuedObjectData) { - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { bos.write(getBrushBytes()); if (continuedObjectData != null) { for (EmfPlusObjectData od : continuedObjectData) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java index 6afb53cdd3..76436f697d 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java @@ -419,13 +419,13 @@ public class HemfPlusImage { if (getBitmapType() == EmfPlusBitmapDataType.PIXEL) { return new Rectangle2D.Double(0, 0, bitmapWidth, bitmapHeight); } else { - try(UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(getRawData(continuedObjectData))) { + try(UnsynchronizedByteArrayInputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(getRawData(continuedObjectData)).get()) { BufferedImage bi = ImageIO.read(is); return new Rectangle2D.Double(bi.getMinX(), bi.getMinY(), bi.getWidth(), bi.getHeight()); } } case METAFILE: - try(UnsynchronizedByteArrayInputStream bis = new UnsynchronizedByteArrayInputStream(getRawData(continuedObjectData))) { + try(UnsynchronizedByteArrayInputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(getRawData(continuedObjectData)).get()) { switch (getMetafileType()) { case Wmf: case WmfPlaceable: @@ -453,7 +453,7 @@ public class HemfPlusImage { * @throws IllegalStateException if the data cannot be read */ public byte[] getRawData(List<? extends EmfPlusObjectData> continuedObjectData) { - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { bos.write(getImageData()); if (continuedObjectData != null) { for (EmfPlusObjectData od : continuedObjectData) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java index d6d2b536f4..c0c2763ac8 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java @@ -293,7 +293,7 @@ public class HemfEmbeddedIterator implements Iterator<HwmfEmbedded> { private void compressGDIBitmap(EmfPlusImage img, HwmfEmbedded emb, HwmfEmbeddedType et) { BufferedImage bi = img.readGDIImage(emb.getRawData()); try { - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); // use HwmfEmbeddedType literal for conversion ImageIO.write(bi, et.toString(), bos); emb.setData(bos.toByteArray()); @@ -318,7 +318,7 @@ public class HemfEmbeddedIterator implements Iterator<HwmfEmbedded> { : epo.getTotalObjectSize(); IOUtils.safelyAllocateCheck(totalSize, MAX_RECORD_LENGTH); - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(totalSize)) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(totalSize).get()) { boolean hasNext = false; do { EmfPlusImage img = epo.getObjectData(); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hmef/attribute/MAPIAttribute.java b/poi-scratchpad/src/main/java/org/apache/poi/hmef/attribute/MAPIAttribute.java index f851526ea3..de08c4fc49 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hmef/attribute/MAPIAttribute.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hmef/attribute/MAPIAttribute.java @@ -116,7 +116,7 @@ public class MAPIAttribute { "instead received a " + parent.getProperty() + " one" ); } - try(UnsynchronizedByteArrayInputStream inp = new UnsynchronizedByteArrayInputStream(parent.getData())) { + try(UnsynchronizedByteArrayInputStream inp = UnsynchronizedByteArrayInputStream.builder().setByteArray(parent.getData()).get()) { // First up, get the number of attributes int count = LittleEndian.readInt(inp); List<MAPIAttribute> attrs = new ArrayList<>(); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hmef/attribute/MAPIRtfAttribute.java b/poi-scratchpad/src/main/java/org/apache/poi/hmef/attribute/MAPIRtfAttribute.java index f8b2d19522..6683beb878 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hmef/attribute/MAPIRtfAttribute.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hmef/attribute/MAPIRtfAttribute.java @@ -46,7 +46,7 @@ public final class MAPIRtfAttribute extends MAPIAttribute { // Decompress it, removing any trailing padding as needed CompressedRTF rtf = new CompressedRTF(); byte[] tmp; - try (InputStream is = new UnsynchronizedByteArrayInputStream(data)) { + try (InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get()) { tmp = rtf.decompress(is); } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/HPBFPart.java b/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/HPBFPart.java index f727360b34..a723fc2cc1 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/HPBFPart.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/HPBFPart.java @@ -83,7 +83,7 @@ public abstract class HPBFPart { generateData(); // Write out - try (UnsynchronizedByteArrayInputStream bais = new UnsynchronizedByteArrayInputStream(data)) { + try (UnsynchronizedByteArrayInputStream bais = UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get()) { dir.createDocument(path[path.length-1], bais); } } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/Bitmap.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/Bitmap.java index 9d6a3ba773..a1b90a8e7e 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/Bitmap.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/Bitmap.java @@ -91,7 +91,7 @@ public abstract class Bitmap extends HSLFPictureData { @Override public Dimension getImageDimension() { - try (InputStream is = new UnsynchronizedByteArrayInputStream(getData())){ + try (InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(getData()).get()){ BufferedImage bi = ImageIO.read(is); return new Dimension( (int)Units.pixelToPoints(bi.getWidth()), diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/EMF.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/EMF.java index fd1df89ca6..d8d9231f49 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/EMF.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/EMF.java @@ -69,9 +69,9 @@ public final class EMF extends Metafile { header.read(rawdata, CHECKSUM_SIZE); try ( - InputStream is = new UnsynchronizedByteArrayInputStream(rawdata); + InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(rawdata).get(); InflaterInputStream inflater = new InflaterInputStream(is); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get() ) { long len = IOUtils.skipFully(is,header.getSize() + (long)CHECKSUM_SIZE); assert(len == header.getSize() + CHECKSUM_SIZE); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/Metafile.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/Metafile.java index acb3e849a2..e449f13506 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/Metafile.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/Metafile.java @@ -91,7 +91,7 @@ public abstract class Metafile extends HSLFPictureData { public void read(byte[] data, int offset) { try ( LittleEndianInputStream leis = new LittleEndianInputStream( - new UnsynchronizedByteArrayInputStream(data, offset, RECORD_LENGTH)) + UnsynchronizedByteArrayInputStream.builder().setByteArray(data).setOffset(offset).setLength(RECORD_LENGTH).get()) ) { wmfsize = leis.readInt(); @@ -204,7 +204,7 @@ public abstract class Metafile extends HSLFPictureData { } protected static byte[] compress(byte[] bytes, int offset, int length) { - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); try (DeflaterOutputStream deflater = new DeflaterOutputStream(out)) { deflater.write(bytes, offset, length); } catch (IOException ignored) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/PICT.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/PICT.java index 3e5042af46..fdc23e9e3e 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/PICT.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/PICT.java @@ -72,7 +72,7 @@ public final class PICT extends Metafile { @Override public byte[] getData(){ byte[] rawdata = getRawData(); - try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) { byte[] macheader = new byte[512]; out.write(macheader); int pos = CHECKSUM_SIZE*getUIDInstanceCount(); @@ -88,13 +88,13 @@ public final class PICT extends Metafile { Header header = new Header(); header.read(data, pos); long bs_exp = (long)pos + header.getSize(); - try (InputStream bis = new UnsynchronizedByteArrayInputStream(data)) { + try (InputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get()) { long bs_act = IOUtils.skipFully(bis, bs_exp); if (bs_exp != bs_act) { throw new EOFException(); } byte[] chunk = new byte[4096]; - try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(header.getWmfSize())) { + try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(header.getWmfSize()).get()) { try (InflaterInputStream inflater = new InflaterInputStream(bis)) { int count; while ((count = inflater.read(chunk)) >= 0) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/WMF.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/WMF.java index 73da07c9b4..16e7d5f294 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/WMF.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/WMF.java @@ -65,7 +65,7 @@ public final class WMF extends Metafile { @Override public byte[] getData(){ byte[] rawdata = getRawData(); - try (InputStream is = new UnsynchronizedByteArrayInputStream(rawdata)) { + try (InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(rawdata).get()) { Header header = new Header(); @@ -75,7 +75,7 @@ public final class WMF extends Metafile { assert(skipped == skipLen); ImageHeaderWMF aldus = new ImageHeaderWMF(header.getBounds()); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); aldus.write(out); try (InflaterInputStream inflater = new InflaterInputStream( is )) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java index 3dca0340d1..7940dae77d 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java @@ -65,7 +65,7 @@ public final class PPTXMLDump { return null; } try (InputStream is = dn.createDocumentInputStream(entry); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { IOUtils.copy(is, bos); return bos.toByteArray(); } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideIdListing.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideIdListing.java index b335752e9c..6f8c596450 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideIdListing.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideIdListing.java @@ -147,7 +147,7 @@ public final class SlideIdListing { } // Increase the position by the on disk size - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); r.writeOut(baos); pos += baos.size(); } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideShowRecordDumper.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideShowRecordDumper.java index f1898ccd88..005da13472 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideShowRecordDumper.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideShowRecordDumper.java @@ -146,7 +146,7 @@ public final class SlideShowRecordDumper { public int getDiskLen(org.apache.poi.hslf.record.Record r) throws IOException { int diskLen = 0; if (r != null) { - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); r.writeOut(baos); diskLen = baos.size(); } @@ -158,7 +158,7 @@ public final class SlideShowRecordDumper { return "<<null>>"; } - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); r.writeOut(baos); byte[] b = baos.toByteArray(); return HexDump.dump(b, 0, 0); @@ -258,7 +258,7 @@ public final class SlideShowRecordDumper { if (optEscher && cname.equals("PPDrawing")) { DefaultEscherRecordFactory factory = new HSLFEscherRecordFactory(); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); r.writeOut(baos); byte[] b = baos.toByteArray(); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/UserEditAndPersistListing.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/UserEditAndPersistListing.java index 5803b42588..f0aeaff126 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/UserEditAndPersistListing.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/UserEditAndPersistListing.java @@ -79,7 +79,7 @@ public final class UserEditAndPersistListing { } // Increase the position by the on disk size - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); r.writeOut(baos); pos += baos.size(); } @@ -99,7 +99,7 @@ public final class UserEditAndPersistListing { } // Increase the position by the on disk size - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); r.writeOut(baos); pos += baos.size(); } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/model/textproperties/TextPropCollection.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/model/textproperties/TextPropCollection.java index 814c82e788..fa9618483f 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/model/textproperties/TextPropCollection.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/model/textproperties/TextPropCollection.java @@ -379,7 +379,7 @@ public class TextPropCollection implements GenericRecord, Duplicatable { out.append(" bytes that would be written: \n"); try { - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); writeOut(baos); byte[] b = baos.toByteArray(); out.append(HexDump.dump(b, 0, 0)); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ColorSchemeAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ColorSchemeAtom.java index 6664b76676..2b4561c2f5 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ColorSchemeAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ColorSchemeAtom.java @@ -154,7 +154,7 @@ public final class ColorSchemeAtom extends RecordAtom { byte[] ret = new byte[3]; // Serialise to bytes, then grab the right ones out - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); try { writeLittleEndian(rgb,baos); } catch(IOException ie) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/CurrentUserAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/CurrentUserAtom.java index 9d54004166..70e422b838 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/CurrentUserAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/CurrentUserAtom.java @@ -264,7 +264,7 @@ public class CurrentUserAtom { */ public void writeToFS(POIFSFileSystem fs) throws IOException { // Grab contents - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) { writeOut(baos); try (InputStream is = baos.toInputStream()) { // Write out diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/EscherTextboxWrapper.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/EscherTextboxWrapper.java index 4164158e5f..f2f909d999 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/EscherTextboxWrapper.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/EscherTextboxWrapper.java @@ -89,7 +89,7 @@ public final class EscherTextboxWrapper extends RecordContainer { // Write out our children, and stuff them into the Escher layer // Grab the children's data - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) { for (org.apache.poi.hslf.record.Record r : _children) { r.writeOut(baos); } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExOleObjStg.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExOleObjStg.java index d4366fa436..2849601612 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExOleObjStg.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExOleObjStg.java @@ -124,7 +124,7 @@ public class ExOleObjStg extends PositionDependentRecordAtom implements PersistR * @param data the embedded data. */ public void setData(byte[] data) throws IOException { - try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); DeflaterOutputStream def = new DeflaterOutputStream(out)) { //first four bytes is the length of the raw data byte[] b = new byte[4]; diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/HSLFEscherClientDataRecord.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/HSLFEscherClientDataRecord.java index 14751254d6..9ee2d60c83 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/HSLFEscherClientDataRecord.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/HSLFEscherClientDataRecord.java @@ -93,7 +93,7 @@ public class HSLFEscherClientDataRecord extends EscherClientDataRecord { @Override public byte[] getRemainingData() { - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { for (org.apache.poi.hslf.record.Record r : _childRecords) { r.writeOut(bos); } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PPDrawingGroup.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PPDrawingGroup.java index 957edcb945..08ab371e63 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PPDrawingGroup.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PPDrawingGroup.java @@ -82,8 +82,8 @@ public final class PPDrawingGroup extends RecordAtom { public void writeOut(OutputStream out) throws IOException { byte[] bstorehead = new byte[8]; byte[] recordBytes = new byte[36 + 8]; - try (UnsynchronizedByteArrayOutputStream bout = new UnsynchronizedByteArrayOutputStream(); - UnsynchronizedByteArrayOutputStream recordBuf = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bout = UnsynchronizedByteArrayOutputStream.builder().get(); + UnsynchronizedByteArrayOutputStream recordBuf = UnsynchronizedByteArrayOutputStream.builder().get()) { for (EscherRecord r : dggContainer) { if (r.getRecordId() == EscherContainerRecord.BSTORE_CONTAINER) { EscherContainerRecord bstore = (EscherContainerRecord) r; diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/RecordContainer.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/RecordContainer.java index abd3a22ced..f970b8d5f1 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/RecordContainer.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/RecordContainer.java @@ -227,7 +227,7 @@ public abstract class RecordContainer extends Record */ public void writeOut(byte headerA, byte headerB, long type, Record[] children, OutputStream out) throws IOException { // Create a UnsynchronizedByteArrayOutputStream to hold everything in - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) { // Write out our header, less the size baos.write(new byte[]{headerA, headerB}); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/StyleTextPropAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/StyleTextPropAtom.java index 62773615e0..eb683b42aa 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/StyleTextPropAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/StyleTextPropAtom.java @@ -308,7 +308,7 @@ public final class StyleTextPropAtom extends RecordAtom { private void updateRawContents() throws IOException { if (initialised) { // Only update the style bytes, if the styles have been potentially changed - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) { // First up, we need to serialise the paragraph properties for (TextPropCollection tpc : paragraphStyles) { tpc.writeOut(baos); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextRulerAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextRulerAtom.java index d9e18a30d0..df9db94f86 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextRulerAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextRulerAtom.java @@ -117,7 +117,7 @@ public final class TextRulerAtom extends RecordAtom { */ @Override public void writeOut(final OutputStream out) throws IOException { - final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(200); + final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(200).get(); final LittleEndianOutputStream lbos = new LittleEndianOutputStream(bos); int mask = 0; mask |= writeIf(lbos, numLevels, C_LEVELS); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextSpecInfoAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextSpecInfoAtom.java index aa71d41540..01f3dc9d8e 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextSpecInfoAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextSpecInfoAtom.java @@ -109,7 +109,7 @@ public final class TextSpecInfoAtom extends RecordAtom { */ public void reset(int size){ TextSpecInfoRun sir = new TextSpecInfoRun(size); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); try { sir.writeOut(bos); } catch (IOException e) { @@ -128,7 +128,7 @@ public final class TextSpecInfoAtom extends RecordAtom { public void setParentSize(int size) { assert(size > 0); - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { TextSpecInfoRun[] runs = getTextSpecInfoRuns(); int remaining = size; int idx = 0; diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TxMasterStyleAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TxMasterStyleAtom.java index ca94a6acfd..610ad27c39 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TxMasterStyleAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TxMasterStyleAtom.java @@ -187,7 +187,7 @@ public final class TxMasterStyleAtom extends RecordAtom { int type = getTextType(); try { - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); LittleEndianOutputStream leos = new LittleEndianOutputStream(bos); int levels = paragraphStyles.size(); leos.writeShort(levels); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java index 1239fe686f..15476e48f3 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java @@ -1080,7 +1080,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh ExOleObjStg exOleObjStg = new ExOleObjStg(); try { Ole10Native.createOleMarkerEntry(poiData); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); poiData.writeFilesystem(bos); exOleObjStg.setData(bos.toByteArray()); } catch (IOException e) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java index 953ef3733a..54edf47faa 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java @@ -811,7 +811,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { // Write out the Property Streams writeProperties(outFS, writtenEntries); - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) { // For position dependent records, hold where they were and now are // As we go along, update, and hand over, to any Position Dependent @@ -852,7 +852,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { } private static InputStream encryptOnePicture(HSLFSlideShowEncrypted encryptedSS, HSLFPictureData data) { - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) { data.write(baos); byte[] pictBytes = baos.toByteArray(); encryptedSS.encryptPicture(pictBytes, 0); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/PropertiesChunk.java b/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/PropertiesChunk.java index cdc146d980..64a3a31c21 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/PropertiesChunk.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/PropertiesChunk.java @@ -319,7 +319,7 @@ public abstract class PropertiesChunk extends Chunk { * If an I/O error occurs. */ public void writeProperties(DirectoryEntry directory) throws IOException { - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) { List<PropertyValue> values = writeProperties(baos); // write the header data with the properties declaration diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwmf/usermodel/HwmfEmbeddedIterator.java b/poi-scratchpad/src/main/java/org/apache/poi/hwmf/usermodel/HwmfEmbeddedIterator.java index 03dfdec402..cf15734217 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwmf/usermodel/HwmfEmbeddedIterator.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwmf/usermodel/HwmfEmbeddedIterator.java @@ -114,7 +114,7 @@ public class HwmfEmbeddedIterator implements Iterator<HwmfEmbedded> { final HwmfEmbedded emb = new HwmfEmbedded(); emb.setEmbeddedType(HwmfEmbeddedType.EMF); - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { WmfEscapeEMF img; do { final HwmfEscape esc = (HwmfEscape)current; diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java index 52ae97a3ed..214af0afa1 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java @@ -256,7 +256,7 @@ public final class HWPFLister { private static HWPFDocumentCore writeOutAndReadBack( HWPFDocumentCore original ) { - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) { original.write( baos ); try (InputStream is = baos.toInputStream()) { return loadDoc(is); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/usermodel/Picture.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/usermodel/Picture.java index 05b22ccd00..7ba7892b28 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/usermodel/Picture.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/usermodel/Picture.java @@ -140,9 +140,10 @@ public final class Picture { */ if ( matchSignature( rawContent, COMPRESSED1, 32 ) || matchSignature( rawContent, COMPRESSED2, 32 ) ) { - try (UnsynchronizedByteArrayInputStream bis = new UnsynchronizedByteArrayInputStream( rawContent, 33, rawContent.length - 33 ); + try (UnsynchronizedByteArrayInputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(rawContent). + setOffset(33).setLength(rawContent.length - 33).get(); InflaterInputStream in = new InflaterInputStream(bis); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) { + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) { IOUtils.copy(in, out); content = out.toByteArray(); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hdgf/dev/TestVSDDumper.java b/poi-scratchpad/src/test/java/org/apache/poi/hdgf/dev/TestVSDDumper.java index 6a1a830a0b..a192125081 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hdgf/dev/TestVSDDumper.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hdgf/dev/TestVSDDumper.java @@ -33,7 +33,7 @@ public class TestVSDDumper { @Test void main() { PrintStream oldStdOut = System.out; - System.setOut(new NullPrintStream()); + System.setOut(NullPrintStream.INSTANCE); try { File file = POIDataSamples.getDiagramInstance().getFile("Test_Visio-Some_Random_Text.vsd"); String[] args = { file.getAbsolutePath() }; diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hemf/usermodel/TestHemfPicture.java b/poi-scratchpad/src/test/java/org/apache/poi/hemf/usermodel/TestHemfPicture.java index 1fbc303d78..22740b0cf6 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hemf/usermodel/TestHemfPicture.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hemf/usermodel/TestHemfPicture.java @@ -221,7 +221,7 @@ public class TestHemfPicture { @Test void testInfiniteLoopOnByteArray() throws Exception { try (InputStream is = ss_samples.openResourceAsStream("61294.emf")) { - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); IOUtils.copy(is, bos); HemfPicture pic = new HemfPicture(bos.toInputStream()); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hmef/TestHMEFMessage.java b/poi-scratchpad/src/test/java/org/apache/poi/hmef/TestHMEFMessage.java index 5717e5157d..5a12ac6426 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hmef/TestHMEFMessage.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hmef/TestHMEFMessage.java @@ -169,7 +169,7 @@ public final class TestHMEFMessage { @Test void testNoData() throws Exception { - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); // Header LittleEndian.putInt(HMEFMessage.HEADER_SIGNATURE, out); @@ -184,7 +184,7 @@ public final class TestHMEFMessage { @Test void testInvalidLevel() throws Exception { - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); // Header LittleEndian.putInt(HMEFMessage.HEADER_SIGNATURE, out); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hmef/dev/TestHMEFDumper.java b/poi-scratchpad/src/test/java/org/apache/poi/hmef/dev/TestHMEFDumper.java index 49ef65cb83..df27e801a6 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hmef/dev/TestHMEFDumper.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hmef/dev/TestHMEFDumper.java @@ -52,7 +52,7 @@ public class TestHMEFDumper { private static void doMain(String... args) throws Exception { PrintStream ps = System.out; try { - System.setOut(new NullPrintStream()); + System.setOut(NullPrintStream.INSTANCE); HMEFDumper.main(args); } finally { System.setOut(ps); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hmef/extractor/TestHMEFContentsExtractor.java b/poi-scratchpad/src/test/java/org/apache/poi/hmef/extractor/TestHMEFContentsExtractor.java index 81912bbba5..9f41088668 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hmef/extractor/TestHMEFContentsExtractor.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hmef/extractor/TestHMEFContentsExtractor.java @@ -62,7 +62,7 @@ public class TestHMEFContentsExtractor { POIDataSamples samples = POIDataSamples.getHMEFInstance(); File winmailTNEFFile = samples.getFile("quick-winmail.dat"); HMEFContentsExtractor extractor = new HMEFContentsExtractor(winmailTNEFFile); - try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) { extractor.extractMessageBody(out); assertTrue(out.size() > 0); byte[] expectedMagic = new byte[]{'{', '\\', 'r', 't', 'f'}; diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/HSLFTestDataSamples.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/HSLFTestDataSamples.java index 881d543b0d..39d5a32482 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/HSLFTestDataSamples.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/HSLFTestDataSamples.java @@ -54,7 +54,7 @@ public class HSLFTestDataSamples { * Useful for verifying that the serialisation round trip */ public static HSLFSlideShowImpl writeOutAndReadBack(HSLFSlideShowImpl original) { - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) { original.write(baos); try (InputStream is = baos.toInputStream()) { return new HSLFSlideShowImpl(is); @@ -70,7 +70,7 @@ public class HSLFTestDataSamples { * Useful for verifying that the serialisation round trip */ public static HSLFSlideShow writeOutAndReadBack(HSLFSlideShow original) { - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(4096)) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(4096).get()) { original.write(baos); return new HSLFSlideShow(baos.toInputStream()); } catch (IOException e) { diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWrite.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWrite.java index 687888a69a..48e2666aa1 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWrite.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWrite.java @@ -55,7 +55,7 @@ public final class TestReWrite { HSLFSlideShowImpl hss = new HSLFSlideShowImpl(pfs)) { // Write out to a byte array, and to a temp file - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); hss.write(baos); final File file = TempFile.createTempFile("TestHSLF", ".ppt"); @@ -95,7 +95,7 @@ public final class TestReWrite { assertNotNull(pfsC.getRoot().getEntry("Macros")); // Write out normally, will loose the macro stream - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); hssC.write(baos); try (POIFSFileSystem pfsNew = new POIFSFileSystem(baos.toInputStream())) { assertFalse(pfsNew.getRoot().hasEntry("Macros")); @@ -134,7 +134,7 @@ public final class TestReWrite { assertDoesNotThrow(ss::getNotes); // Now write out to a byte array - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); hss.write(baos); // Use POIFS to query that lot diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWriteSanity.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWriteSanity.java index b2991c1533..dbf1866da2 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWriteSanity.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWriteSanity.java @@ -18,7 +18,6 @@ package org.apache.poi.hslf; -import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM; import static org.apache.poi.POITestCase.assertContains; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -26,6 +25,7 @@ import java.util.HashMap; import java.util.Map; import org.apache.commons.io.output.CountingOutputStream; +import org.apache.commons.io.output.NullOutputStream; import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; import org.apache.poi.POIDataSamples; import org.apache.poi.hslf.record.CurrentUserAtom; @@ -64,7 +64,7 @@ public final class TestReWriteSanity { @Test void testUserEditAtomsRight() throws Exception { // Write out to a byte array - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); ss.write(baos); // Create a new one from that @@ -78,7 +78,7 @@ public final class TestReWriteSanity { ue.put(0, 0); // Will show 0 if first int lastUEPos = -1; - CountingOutputStream cos = new CountingOutputStream(NULL_OUTPUT_STREAM); + CountingOutputStream cos = new CountingOutputStream(NullOutputStream.INSTANCE); for (final Record rec : r) { int pos = cos.getCount(); if (rec instanceof PersistPtrHolder) { diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/BaseTestPPTIterating.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/BaseTestPPTIterating.java index 4a0036b010..0ce99759c1 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/BaseTestPPTIterating.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/BaseTestPPTIterating.java @@ -79,7 +79,7 @@ public abstract class BaseTestPPTIterating { IOUtils.setByteArrayMaxOverride(5*1024*1024); // redirect standard out during the test to avoid spamming the console with output - System.setOut(new NullPrintStream()); + System.setOut(NullPrintStream.INSTANCE); } @AfterEach diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/TestSLWTListing.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/TestSLWTListing.java index 3ac7adb84d..b828d4745d 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/TestSLWTListing.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/TestSLWTListing.java @@ -34,7 +34,7 @@ public class TestSLWTListing extends BaseTestPPTIterating { @BeforeAll public static void muteStdErr() { oldStdErr = System.err; - System.setErr(new NullPrintStream()); + System.setErr(NullPrintStream.INSTANCE); } @AfterAll diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestMovieShape.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestMovieShape.java index 336f6bc4f2..982c870043 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestMovieShape.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestMovieShape.java @@ -57,7 +57,7 @@ public final class TestMovieShape { shape.setAutoPlay(false); assertFalse(shape.isAutoPlay()); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); ppt.write(out); ppt = new HSLFSlideShow(out.toInputStream()); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestOleEmbedding.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestOleEmbedding.java index 1a443d1e18..059fffa299 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestOleEmbedding.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestOleEmbedding.java @@ -145,7 +145,7 @@ public final class TestOleEmbedding { slide2.addShape(oleShape2); oleShape2.setAnchor(new Rectangle2D.Double(100,100,100,100)); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); ppt.write(bos); ppt = new HSLFSlideShow(bos.toInputStream()); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestAnimationInfoAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestAnimationInfoAtom.java index dac20b569b..afb18e09fa 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestAnimationInfoAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestAnimationInfoAtom.java @@ -65,7 +65,7 @@ public final class TestAnimationInfoAtom { @Test void testWrite() throws Exception { AnimationInfoAtom record = new AnimationInfoAtom(data, 0, data.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); record.writeOut(baos); byte[] b = baos.toByteArray(); @@ -81,7 +81,7 @@ public final class TestAnimationInfoAtom { record.setFlag(AnimationInfoAtom.Play, true); record.setFlag(AnimationInfoAtom.Synchronous, true); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); record.writeOut(baos); byte[] b = baos.toByteArray(); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestCString.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestCString.java index 57af6afcb5..db7e206541 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestCString.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestCString.java @@ -70,13 +70,13 @@ public final class TestCString { @Test void testWrite() throws Exception { CString ca = new CString(data_a, 0, data_a.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); ca.writeOut(baos); byte[] b = baos.toByteArray(); assertArrayEquals(data_a, b); CString cb = new CString(data_b, 0, data_a.length); - UnsynchronizedByteArrayOutputStream baosB = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baosB = UnsynchronizedByteArrayOutputStream.builder().get(); cb.writeOut(baosB); b = baosB.toByteArray(); assertArrayEquals(data_b, b); @@ -99,7 +99,7 @@ public final class TestCString { } assertFalse(equals, "Arrays should not be equals"); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); ca.writeOut(baos); byte[] b = baos.toByteArray(); assertArrayEquals(data_b, b); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestColorSchemeAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestColorSchemeAtom.java index 03d657a42f..d465118a33 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestColorSchemeAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestColorSchemeAtom.java @@ -81,7 +81,7 @@ public final class TestColorSchemeAtom { @Test void testWrite() throws Exception { ColorSchemeAtom csa = new ColorSchemeAtom(data_a,0,data_a.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); csa.writeOut(baos); byte[] b = baos.toByteArray(); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestComment2000.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestComment2000.java index 32213d0e4d..3c94ef7319 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestComment2000.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestComment2000.java @@ -144,7 +144,7 @@ public final class TestComment2000 { @Test void testWrite() throws Exception { Comment2000 ca = new Comment2000(data_a, 0, data_a.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); ca.writeOut(baos); byte[] b = baos.toByteArray(); assertArrayEquals(data_a, b); @@ -196,8 +196,8 @@ public final class TestComment2000 { assertFalse(equals, "Arrays should not be equals"); // Check bytes are now the same - UnsynchronizedByteArrayOutputStream baosa = new UnsynchronizedByteArrayOutputStream(); - UnsynchronizedByteArrayOutputStream baosn = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baosa = UnsynchronizedByteArrayOutputStream.builder().get(); + UnsynchronizedByteArrayOutputStream baosn = UnsynchronizedByteArrayOutputStream.builder().get(); ca.writeOut(baosa); cn.writeOut(baosn); byte[] ba = baosa.toByteArray(); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestComment2000Atom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestComment2000Atom.java index 734f3b73ad..225d0b5e05 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestComment2000Atom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestComment2000Atom.java @@ -106,7 +106,7 @@ public final class TestComment2000Atom { @Test void testWrite() throws Exception { Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); ca.writeOut(baos); byte[] b = baos.toByteArray(); assertArrayEquals(data_a, b); @@ -127,7 +127,7 @@ public final class TestComment2000Atom { a.setDate(date_a); // Check it's now the same as a - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); a.writeOut(baos); byte[] b = baos.toByteArray(); assertArrayEquals(data_a, b); @@ -150,7 +150,7 @@ public final class TestComment2000Atom { ca.setYOffset(0x0E); // Check bytes are now the same - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); ca.writeOut(baos); byte[] b = baos.toByteArray(); assertArrayEquals(data_b, b); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestCurrentUserAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestCurrentUserAtom.java index c8c0cc2eac..a1ee955fd3 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestCurrentUserAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestCurrentUserAtom.java @@ -89,7 +89,7 @@ public final class TestCurrentUserAtom { cu.setCurrentEditOffset(0x2942); // Check it matches - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); cu.writeOut(baos); byte[] out = baos.toByteArray(); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestDocumentAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestDocumentAtom.java index 9cdf6f62c4..861f43ad85 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestDocumentAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestDocumentAtom.java @@ -81,7 +81,7 @@ public final class TestDocumentAtom { @Test void testWrite() throws Exception { DocumentAtom da = new DocumentAtom(data_a, 0, data_a.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); da.writeOut(baos); assertArrayEquals(data_a, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestDocumentEncryption.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestDocumentEncryption.java index 26c00b64a1..926a3e3ede 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestDocumentEncryption.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestDocumentEncryption.java @@ -87,7 +87,7 @@ public class TestDocumentEncryption { EncryptionInfo ei = documentEncryptionAtom.getEncryptionInfo(); ei.getHeader().setKeySize(0x78); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); hss.write(bos); try (POIFSFileSystem fs2 = new POIFSFileSystem(bos.toInputStream()); @@ -108,9 +108,9 @@ public class TestDocumentEncryption { void cryptoAPIEncryption() throws Exception { /* documents with multiple edits need to be normalized for encryption */ String pptFile = "57272_corrupted_usereditatom.ppt"; - UnsynchronizedByteArrayOutputStream encrypted = new UnsynchronizedByteArrayOutputStream(); - UnsynchronizedByteArrayOutputStream expected = new UnsynchronizedByteArrayOutputStream(); - UnsynchronizedByteArrayOutputStream actual = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream encrypted = UnsynchronizedByteArrayOutputStream.builder().get(); + UnsynchronizedByteArrayOutputStream expected = UnsynchronizedByteArrayOutputStream.builder().get(); + UnsynchronizedByteArrayOutputStream actual = UnsynchronizedByteArrayOutputStream.builder().get(); try { try (POIFSFileSystem fs = new POIFSFileSystem(slTests.getFile(pptFile), true); HSLFSlideShowImpl hss = new HSLFSlideShowImpl(fs)) { diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExControl.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExControl.java index fc8c353e33..b8b8a44427 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExControl.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExControl.java @@ -92,7 +92,7 @@ public final class TestExControl { @Test void testWrite() throws Exception { ExControl record = new ExControl(data, 0, data.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); record.writeOut(baos); assertArrayEquals(data, baos.toByteArray()); } @@ -115,7 +115,7 @@ public final class TestExControl { record.setProgId("ShockwaveFlash.ShockwaveFlash.9"); record.setClipboardName("Shockwave Flash Object"); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); record.writeOut(baos); assertArrayEquals(data, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExHyperlink.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExHyperlink.java index d67a9db105..4eca038dcc 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExHyperlink.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExHyperlink.java @@ -53,7 +53,7 @@ public final class TestExHyperlink { assertEquals(expURL, exHyperlink._getDetailsA()); assertEquals(expURL, exHyperlink._getDetailsB()); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); exHyperlink.writeOut(baos); assertArrayEquals(exHyperlinkBytes, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExHyperlinkAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExHyperlinkAtom.java index f738f44ec8..a9d900f2c9 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExHyperlinkAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExHyperlinkAtom.java @@ -56,7 +56,7 @@ public class TestExHyperlinkAtom { @Test void testWrite() throws Exception { ExHyperlinkAtom eha = new ExHyperlinkAtom(data_a, 0, data_a.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); eha.writeOut(baos); assertArrayEquals(data_a, baos.toByteArray()); } @@ -70,7 +70,7 @@ public class TestExHyperlinkAtom { eha.setNumber(1); // Check it's now the same as a - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); eha.writeOut(baos); assertArrayEquals(data_a, baos.toByteArray()); } @@ -84,7 +84,7 @@ public class TestExHyperlinkAtom { eha.setNumber(4); // Check bytes are now the same - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); eha.writeOut(baos); assertArrayEquals(data_b, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExMediaAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExMediaAtom.java index 6d7e08c6a9..ff73e5b846 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExMediaAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExMediaAtom.java @@ -49,7 +49,7 @@ public final class TestExMediaAtom { @Test void testWrite() throws Exception { ExMediaAtom record = new ExMediaAtom(data, 0, data.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); record.writeOut(baos); byte[] b = baos.toByteArray(); @@ -67,7 +67,7 @@ public final class TestExMediaAtom { record.setFlag(HeadersFootersAtom.fHasTodayDate, false); record.setFlag(HeadersFootersAtom.fHasFooter, false); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); record.writeOut(baos); byte[] b = baos.toByteArray(); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExObjListAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExObjListAtom.java index d8a5229aba..addc164d88 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExObjListAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExObjListAtom.java @@ -56,7 +56,7 @@ public class TestExObjListAtom { @Test void testWrite() throws Exception { ExObjListAtom eoa = new ExObjListAtom(data_a, 0, data_a.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); eoa.writeOut(baos); assertArrayEquals(data_a, baos.toByteArray()); } @@ -70,7 +70,7 @@ public class TestExObjListAtom { eoa.setObjectIDSeed(1); // Check it's now the same as a - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); eoa.writeOut(baos); assertArrayEquals(data_a, baos.toByteArray()); } @@ -84,7 +84,7 @@ public class TestExObjListAtom { eoa.setObjectIDSeed(4); // Check bytes are now the same - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); eoa.writeOut(baos); assertArrayEquals(data_b, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjAtom.java index 337f6f5307..a28be1bdef 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjAtom.java @@ -50,7 +50,7 @@ public final class TestExOleObjAtom { @Test void testWrite() throws Exception { ExOleObjAtom record = new ExOleObjAtom(data, 0, data.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); record.writeOut(baos); assertArrayEquals(data, baos.toByteArray()); } @@ -65,7 +65,7 @@ public final class TestExOleObjAtom { record.setObjStgDataRef(2); record.setOptions(1283584); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); record.writeOut(baos); assertArrayEquals(data, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjStg.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjStg.java index f9d282a095..46d607e729 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjStg.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjStg.java @@ -70,7 +70,7 @@ public final class TestExOleObjStg { @Test void testWrite() throws Exception { ExOleObjStg record = new ExOleObjStg(data, 0, data.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); record.writeOut(baos); byte[] b = baos.toByteArray(); @@ -88,7 +88,7 @@ public final class TestExOleObjStg { assertEquals(src.getDataLength(), tgt.getDataLength()); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); tgt.writeOut(out); byte[] b = out.toByteArray(); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExVideoContainer.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExVideoContainer.java index ce02202335..a4c2a31401 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExVideoContainer.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExVideoContainer.java @@ -67,7 +67,7 @@ public final class TestExVideoContainer { @Test void testWrite() throws Exception { ExVideoContainer record = new ExVideoContainer(data, 0, data.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); record.writeOut(baos); assertArrayEquals(data, baos.toByteArray()); } @@ -78,7 +78,7 @@ public final class TestExVideoContainer { record.getExMediaAtom().setObjectId(1); record.getPathAtom().setText("D:\\projects\\SchulerAG\\mcom_v_1_0_4\\view\\data\\tests\\images\\cards.mpg"); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); record.writeOut(baos); assertArrayEquals(data, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestFontCollection.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestFontCollection.java index a15fa80016..bb7eab1dbb 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestFontCollection.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestFontCollection.java @@ -94,7 +94,7 @@ public final class TestFontCollection { @Test void testWrite() throws Exception { FontCollection fonts = new FontCollection(data, 0, data.length); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); fonts.writeOut(out); byte[] recdata = out.toByteArray(); assertArrayEquals(recdata, data); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestHeadersFootersAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestHeadersFootersAtom.java index 71ea592da2..f5cf552a5f 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestHeadersFootersAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestHeadersFootersAtom.java @@ -54,7 +54,7 @@ public final class TestHeadersFootersAtom { @Test void testWrite() throws Exception { HeadersFootersAtom record = new HeadersFootersAtom(data, 0, data.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); record.writeOut(baos); assertArrayEquals(data, baos.toByteArray()); } @@ -66,7 +66,7 @@ public final class TestHeadersFootersAtom { record.setFlag(HeadersFootersAtom.fHasTodayDate, true); record.setFlag(HeadersFootersAtom.fHasFooter, true); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); record.writeOut(baos); assertArrayEquals(data, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestHeadersFootersContainer.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestHeadersFootersContainer.java index 21d7a83d16..209409e425 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestHeadersFootersContainer.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestHeadersFootersContainer.java @@ -75,7 +75,7 @@ public final class TestHeadersFootersContainer { @Test void testWriteSlideHeadersFootersContainer() throws Exception { HeadersFootersContainer record = new HeadersFootersContainer(slideData, 0, slideData.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); record.writeOut(baos); assertArrayEquals(slideData, baos.toByteArray()); } @@ -99,7 +99,7 @@ public final class TestHeadersFootersContainer { assertEquals(HeadersFootersContainer.FOOTERATOM, csFooter.getOptions() >> 4); csFooter.setText("My Footer - 1"); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); record.writeOut(baos); assertArrayEquals(slideData, baos.toByteArray()); } @@ -128,7 +128,7 @@ public final class TestHeadersFootersContainer { @Test void testWriteNotesHeadersFootersContainer() throws Exception { HeadersFootersContainer record = new HeadersFootersContainer(notesData, 0, notesData.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); record.writeOut(baos); assertArrayEquals(notesData, baos.toByteArray()); } @@ -160,7 +160,7 @@ public final class TestHeadersFootersContainer { assertEquals(HeadersFootersContainer.FOOTERATOM, csFooter.getOptions() >> 4); csFooter.setText("Note Footer"); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); record.writeOut(baos); assertArrayEquals(notesData, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestInteractiveInfo.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestInteractiveInfo.java index 3e003969a9..8845e285fa 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestInteractiveInfo.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestInteractiveInfo.java @@ -56,7 +56,7 @@ public class TestInteractiveInfo { @Test void testWrite() throws Exception { InteractiveInfo ii = new InteractiveInfo(data_a, 0, data_a.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); ii.writeOut(baos); assertArrayEquals(data_a, baos.toByteArray()); } @@ -74,7 +74,7 @@ public class TestInteractiveInfo { ia.setHyperlinkType((byte)8); // Check it's now the same as a - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); ii.writeOut(baos); assertArrayEquals(data_a, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestInteractiveInfoAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestInteractiveInfoAtom.java index 824cfce1fd..1ef63efbde 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestInteractiveInfoAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestInteractiveInfoAtom.java @@ -73,7 +73,7 @@ public class TestInteractiveInfoAtom { @Test void testWrite() throws Exception { InteractiveInfoAtom ia = new InteractiveInfoAtom(data_a, 0, data_a.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); ia.writeOut(baos); assertArrayEquals(data_a, baos.toByteArray()); } @@ -90,7 +90,7 @@ public class TestInteractiveInfoAtom { ia.setHyperlinkType((byte)8); // Check it's now the same as a - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); ia.writeOut(baos); assertArrayEquals(data_a, baos.toByteArray()); } @@ -104,7 +104,7 @@ public class TestInteractiveInfoAtom { ia.setHyperlinkID(4); // Check bytes are now the same - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); ia.writeOut(baos); assertArrayEquals(data_b, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestNotesAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestNotesAtom.java index 5528d26293..b6d7c644e7 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestNotesAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestNotesAtom.java @@ -51,7 +51,7 @@ public final class TestNotesAtom { @Test void testWrite() throws Exception { NotesAtom na = new NotesAtom(data_a, 0, data_a.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); na.writeOut(baos); assertArrayEquals(data_a, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestSlideAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestSlideAtom.java index 366f85310f..2f5dac443f 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestSlideAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestSlideAtom.java @@ -75,7 +75,7 @@ public final class TestSlideAtom { @Test void testWrite() throws IOException { SlideAtom sa = new SlideAtom(data_a, 0, data_a.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); sa.writeOut(baos); assertArrayEquals(data_a, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestSlidePersistAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestSlidePersistAtom.java index 4e0386d1ca..7393888034 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestSlidePersistAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestSlidePersistAtom.java @@ -52,7 +52,7 @@ public final class TestSlidePersistAtom { @Test void testWrite() throws Exception { SlidePersistAtom spa = new SlidePersistAtom(data_a, 0, data_a.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); spa.writeOut(baos); assertArrayEquals(data_a, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestStyleTextPropAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestStyleTextPropAtom.java index 1e57798caf..e155df07b8 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestStyleTextPropAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestStyleTextPropAtom.java @@ -466,7 +466,7 @@ public final class TestStyleTextPropAtom { tpc.setValue(0xFE0033FF); // Should now be the same as data_a - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); stpa.writeOut(baos); assertArrayEquals(data_a, baos.toByteArray()); } @@ -615,8 +615,8 @@ public final class TestStyleTextPropAtom { assertEquals(tpa.getValue(), tpb.getValue()); } - UnsynchronizedByteArrayOutputStream ba = new UnsynchronizedByteArrayOutputStream(); - UnsynchronizedByteArrayOutputStream bb = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream ba = UnsynchronizedByteArrayOutputStream.builder().get(); + UnsynchronizedByteArrayOutputStream bb = UnsynchronizedByteArrayOutputStream.builder().get(); ca.writeOut(ba); cb.writeOut(bb); @@ -626,7 +626,7 @@ public final class TestStyleTextPropAtom { } // Check byte level with b - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); stpa.writeOut(baos); assertArrayEquals(data_b, baos.toByteArray()); } @@ -674,7 +674,7 @@ public final class TestStyleTextPropAtom { StyleTextPropAtom stpb = new StyleTextPropAtom(data, 0,data.length); if(textlen != -1) stpb.setParentTextSize(textlen); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); stpb.writeOut(out); assertArrayEquals(expected, out.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextBytesAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextBytesAtom.java index d50fc18a92..a39f4d3c42 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextBytesAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextBytesAtom.java @@ -64,7 +64,7 @@ public final class TestTextBytesAtom { TextBytesAtom tba = new TextBytesAtom(data,0,data.length); tba.setText(alt_text.getBytes(StandardCharsets.ISO_8859_1)); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); tba.writeOut(baos); assertArrayEquals(alt_data, baos.toByteArray()); } @@ -72,7 +72,7 @@ public final class TestTextBytesAtom { @Test void testWrite() throws Exception { TextBytesAtom tba = new TextBytesAtom(data,0,data.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); tba.writeOut(baos); assertArrayEquals(data, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextCharsAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextCharsAtom.java index d2357a8fdc..d1b79f2234 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextCharsAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextCharsAtom.java @@ -59,7 +59,7 @@ public final class TestTextCharsAtom { TextCharsAtom tca = new TextCharsAtom(data,0,data.length); tca.setText(alt_text); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); tca.writeOut(baos); assertArrayEquals(alt_data, baos.toByteArray()); } @@ -67,7 +67,7 @@ public final class TestTextCharsAtom { @Test void testWrite() throws Exception { TextCharsAtom tca = new TextCharsAtom(data,0,data.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); tca.writeOut(baos); assertArrayEquals(data, baos.toByteArray()); } @@ -81,7 +81,7 @@ public final class TestTextCharsAtom { assertEquals(data_text, tca.getText()); // Check it's now like data - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); tca.writeOut(baos); assertArrayEquals(data, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextHeaderAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextHeaderAtom.java index 22bce9375b..213db5f080 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextHeaderAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextHeaderAtom.java @@ -53,7 +53,7 @@ public final class TestTextHeaderAtom { @Test void testWrite() throws Exception { TextHeaderAtom tha = new TextHeaderAtom(notes_data,0,12); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); tha.writeOut(baos); assertArrayEquals(notes_data, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextRulerAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextRulerAtom.java index e1a08b6e09..c9067d594e 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextRulerAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextRulerAtom.java @@ -61,7 +61,7 @@ public final class TestTextRulerAtom { @Test void testWriteRuler() throws Exception { TextRulerAtom ruler = new TextRulerAtom(data_1, 0, data_1.length); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); ruler.writeOut(out); byte[] result = out.toByteArray(); @@ -72,7 +72,7 @@ public final class TestTextRulerAtom { void testRead2() throws Exception { TextRulerAtom ruler = TextRulerAtom.getParagraphInstance(); ruler.setParagraphIndent((short)249, (short)321); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); ruler.writeOut(out); byte[] result = out.toByteArray(); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextSpecInfoAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextSpecInfoAtom.java index c3cd26d1ce..8902d31882 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextSpecInfoAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextSpecInfoAtom.java @@ -53,7 +53,7 @@ public final class TestTextSpecInfoAtom { @Test void testWrite() throws Exception { TextSpecInfoAtom spec = new TextSpecInfoAtom(data_1, 0, data_1.length); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); spec.writeOut(out); assertArrayEquals(data_1, out.toByteArray()); } @@ -69,7 +69,7 @@ public final class TestTextSpecInfoAtom { assertEquals(32, run[0].getLength()); //serialize and read again - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); spec.writeOut(out); byte[] result = out.toByteArray(); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTxInteractiveInfoAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTxInteractiveInfoAtom.java index 4671e7a8aa..488e5172ad 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTxInteractiveInfoAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTxInteractiveInfoAtom.java @@ -57,7 +57,7 @@ public final class TestTxInteractiveInfoAtom { @Test void testWrite() throws Exception { TxInteractiveInfoAtom atom = new TxInteractiveInfoAtom(data_a, 0, data_a.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); atom.writeOut(baos); assertArrayEquals(data_a, baos.toByteArray()); } @@ -72,7 +72,7 @@ public final class TestTxInteractiveInfoAtom { ia.setEndIndex(56); // Check it's now the same as a - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); ia.writeOut(baos); assertArrayEquals(data_a, baos.toByteArray()); } @@ -87,7 +87,7 @@ public final class TestTxInteractiveInfoAtom { ia.setEndIndex(78); // Check bytes are now the same - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); ia.writeOut(baos); assertArrayEquals(data_b, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestUserEditAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestUserEditAtom.java index a7defb0e38..be72848ee4 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestUserEditAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestUserEditAtom.java @@ -56,7 +56,7 @@ public final class TestUserEditAtom { @Test void testWrite() throws Exception { UserEditAtom uea = new UserEditAtom(data_a, 0, data_a.length); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); uea.writeOut(baos); assertArrayEquals(data_a, baos.toByteArray()); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java index 343c1117d9..bfadc5e474 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java @@ -40,7 +40,7 @@ public class TestHSLFSlideShow extends BaseTestSlideShow<HSLFShape, HSLFTextPara @Override public HSLFSlideShow reopen(SlideShow<HSLFShape, HSLFTextParagraph> show) throws IOException { - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { show.write(bos); try (InputStream is = bos.toInputStream()) { return new HSLFSlideShow(is); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestPictures.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestPictures.java index ebda0b8afa..2b90916775 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestPictures.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestPictures.java @@ -17,7 +17,6 @@ package org.apache.poi.hslf.usermodel; -import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM; import static org.apache.poi.hslf.HSLFTestDataSamples.getSlideShow; import static org.apache.poi.hslf.HSLFTestDataSamples.writeOutAndReadBack; import static org.junit.jupiter.api.Assertions.assertArrayEquals; @@ -38,6 +37,7 @@ import java.util.List; import javax.imageio.ImageIO; import org.apache.commons.io.output.CountingOutputStream; +import org.apache.commons.io.output.NullOutputStream; import org.apache.poi.POIDataSamples; import org.apache.poi.ddf.EscherBSERecord; import org.apache.poi.ddf.EscherContainerRecord; @@ -315,7 +315,7 @@ public final class TestPictures { assertEquals(PictureType.WMF, pdata.getType()); //add a new picture, it should be correctly appended to the Pictures stream - CountingOutputStream out = new CountingOutputStream(NULL_OUTPUT_STREAM); + CountingOutputStream out = new CountingOutputStream(NullOutputStream.INSTANCE); for (HSLFPictureData p : pictures) p.write(out); int streamSize = out.getCount(); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestRichTextRun.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestRichTextRun.java index 87fb7e0033..08d0e0e8bf 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestRichTextRun.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestRichTextRun.java @@ -409,7 +409,7 @@ public final class TestRichTextRun { // Now write out the slideshow byte[] raw_ss; - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); s.write(baos); try (POIFSFileSystem fs = new POIFSFileSystem(baos.toInputStream()); InputStream is = fs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT)) { @@ -424,7 +424,7 @@ public final class TestRichTextRun { } private byte[] writeRecord( org.apache.poi.hslf.record.Record r) throws IOException { - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); r.writeOut(baos); return baos.toByteArray(); } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestExtractEmbeddedMSG.java b/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestExtractEmbeddedMSG.java index c5395232dc..b7613be2da 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestExtractEmbeddedMSG.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestExtractEmbeddedMSG.java @@ -81,7 +81,7 @@ public class TestExtractEmbeddedMSG { testFixedAndVariableLengthPropertiesOfAttachedMSG(attachedMsg); // rebuild top level message from embedded message try (POIFSFileSystem extractedAttachedMsg = rebuildFromAttached(attachedMsg)) { - try (UnsynchronizedByteArrayOutputStream extractedAttachedMsgOut = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream extractedAttachedMsgOut = UnsynchronizedByteArrayOutputStream.builder().get()) { extractedAttachedMsg.writeFilesystem(extractedAttachedMsgOut); MAPIMessage extractedMsgTopLevel = new MAPIMessage(extractedAttachedMsgOut.toInputStream()); // test properties of rebuilt embedded message @@ -171,7 +171,7 @@ public class TestExtractEmbeddedMSG { MAPIType type = Types.getById(iType); if (type != null && type != Types.UNKNOWN) { MAPIProperty mprop = MAPIProperty.createCustom(chunk.getChunkId(), type, chunk.getEntryName()); - UnsynchronizedByteArrayOutputStream data = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream data = UnsynchronizedByteArrayOutputStream.builder().get(); chunk.writeValue(data); PropertyValue pval = new PropertyValue(mprop, MessagePropertiesChunk.PROPERTIES_FLAG_READABLE | MessagePropertiesChunk.PROPERTIES_FLAG_WRITEABLE, data.toByteArray(), type); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java b/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java index 068fa10883..28d02df0a0 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java @@ -119,7 +119,7 @@ public class TestFileWithAttachmentsRead { assertEquals("test-unicode.doc", attachment.getAttachLongFileName().getValue()); assertEquals(".doc", attachment.getAttachExtension().getValue()); assertNull(attachment.getAttachMimeTag()); - UnsynchronizedByteArrayOutputStream attachmentstream = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream attachmentstream = UnsynchronizedByteArrayOutputStream.builder().get(); attachment.getAttachData().writeValue(attachmentstream); assertEquals(24064, attachmentstream.size()); // or compare the hashes of the attachment data diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFixedSizedProperties.java b/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFixedSizedProperties.java index 74d6d27ec2..9d8aa55dde 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFixedSizedProperties.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFixedSizedProperties.java @@ -168,7 +168,7 @@ public final class TestFixedSizedProperties { @Test void testReadMessageDateSucceedsWithHSMFDump() { HSMFDump dump = new HSMFDump(fsMessageSucceeds); - assertDoesNotThrow(() -> dump.dump(new NullPrintStream())); + assertDoesNotThrow(() -> dump.dump(NullPrintStream.INSTANCE)); } /** @@ -177,7 +177,7 @@ public final class TestFixedSizedProperties { @Test void testReadMessageDateFailsWithHSMFDump() { HSMFDump dump = new HSMFDump(fsMessageFails); - assertDoesNotThrow(() -> dump.dump(new NullPrintStream())); + assertDoesNotThrow(() -> dump.dump(NullPrintStream.INSTANCE)); } /** diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestCase.java b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestCase.java index fba8bc97c0..9a0808d286 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestCase.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestCase.java @@ -49,7 +49,7 @@ public abstract class HWPFTestCase { } public HWPFDocument writeOutAndRead(HWPFDocument doc) { - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) { doc.write(baos); try (InputStream is = baos.toInputStream()) { return new HWPFDocument(is); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestDataSamples.java b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestDataSamples.java index 0d6ce9bc8c..082b4866d4 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestDataSamples.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestDataSamples.java @@ -48,7 +48,7 @@ public class HWPFTestDataSamples { * Useful for verifying that the serialisation round trip */ public static HWPFDocument writeOutAndReadBack(HWPFDocument original) { - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(4096)) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(4096).get()) { original.write(baos); return new HWPFDocument(baos.toInputStream()); } catch (IOException e) { diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/dev/TestHWPFLister.java b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/dev/TestHWPFLister.java index c7cd45c1cc..2c9fc68520 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/dev/TestHWPFLister.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/dev/TestHWPFLister.java @@ -42,7 +42,7 @@ public class TestHWPFLister { String fileArgs = SAMPLES.getFile("SampleDoc.doc").getAbsolutePath() + args; PrintStream oldStdOut = System.out; - System.setOut(new NullPrintStream()); + System.setOut(NullPrintStream.INSTANCE); try { assertDoesNotThrow(() -> HWPFLister.main(fileArgs.split(" "))); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestHWPFWrite.java b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestHWPFWrite.java index 36ad393a51..936b84317c 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestHWPFWrite.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestHWPFWrite.java @@ -47,7 +47,7 @@ public final class TestHWPFWrite extends HWPFTestCase { */ @Test void testWriteStream() throws IOException { - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); try (HWPFDocument doc = HWPFTestDataSamples.openSampleFile("SampleDoc.doc")) { Range r = doc.getRange(); assertEquals("I am a test document\r", r.getParagraph(0).text()); diff --git a/poi/src/main/java/org/apache/poi/POIDocument.java b/poi/src/main/java/org/apache/poi/POIDocument.java index 608c14be6d..c7e4536b3b 100644 --- a/poi/src/main/java/org/apache/poi/POIDocument.java +++ b/poi/src/main/java/org/apache/poi/POIDocument.java @@ -336,7 +336,7 @@ public abstract class POIDocument implements Closeable { * {@link POIFSFileSystem} occurs */ private void writePropertySet(String name, PropertySet set, POIFSFileSystem outFS) throws IOException { - try (UnsynchronizedByteArrayOutputStream bOut = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bOut = UnsynchronizedByteArrayOutputStream.builder().get()) { PropertySet mSet = new PropertySet(set); mSet.write(bOut); diff --git a/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java b/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java index d5dceb43fc..cc44cf91ba 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java @@ -192,8 +192,8 @@ public final class EscherMetafileBlip extends EscherBlipRecord { * @return the inflated picture data. */ private static byte[] inflatePictureData(byte[] data) { - try (InflaterInputStream in = new InflaterInputStream(new UnsynchronizedByteArrayInputStream(data)); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) { + try (InflaterInputStream in = new InflaterInputStream(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get()); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) { IOUtils.copy(in, out); return out.toByteArray(); } catch (IOException e) { @@ -410,7 +410,7 @@ public final class EscherMetafileBlip extends EscherBlipRecord { // "... LZ compression algorithm in the format used by GNU Zip deflate/inflate with a 32k window ..." // not sure what to do, when lookup tables exceed 32k ... - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { try (DeflaterOutputStream dos = new DeflaterOutputStream(bos)) { dos.write(pictureData); } diff --git a/poi/src/main/java/org/apache/poi/hpsf/Property.java b/poi/src/main/java/org/apache/poi/hpsf/Property.java index 5587042f0c..1981f8b6e5 100644 --- a/poi/src/main/java/org/apache/poi/hpsf/Property.java +++ b/poi/src/main/java/org/apache/poi/hpsf/Property.java @@ -272,7 +272,7 @@ public class Property { /* Variable length: */ if (type == Variant.VT_LPSTR || type == Variant.VT_LPWSTR) { - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); try { length = write(bos, property) - 2*LittleEndianConsts.INT_SIZE; /* Pad to multiples of 4. */ @@ -399,7 +399,7 @@ public class Property { if (value instanceof String) { b.append((String)value); b.append("\n"); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); try { write(bos, codepage); } catch (Exception e) { diff --git a/poi/src/main/java/org/apache/poi/hpsf/PropertySet.java b/poi/src/main/java/org/apache/poi/hpsf/PropertySet.java index acef3d7d36..5bd4cd6b44 100644 --- a/poi/src/main/java/org/apache/poi/hpsf/PropertySet.java +++ b/poi/src/main/java/org/apache/poi/hpsf/PropertySet.java @@ -514,7 +514,7 @@ public class PropertySet { } private byte[] toBytes() throws WritingNotSupportedException, IOException { - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); LittleEndianOutputStream leos = new LittleEndianOutputStream(bos)) { /* Write the number of sections in this property set stream. */ @@ -599,7 +599,7 @@ public class PropertySet { * @throws IOException if an I/O exception occurs. */ public InputStream toInputStream() throws WritingNotSupportedException, IOException { - return new UnsynchronizedByteArrayInputStream(toBytes()); + return UnsynchronizedByteArrayInputStream.builder().setByteArray(toBytes()).get(); } /** diff --git a/poi/src/main/java/org/apache/poi/hpsf/Section.java b/poi/src/main/java/org/apache/poi/hpsf/Section.java index 09ce055d34..1f127fb48a 100644 --- a/poi/src/main/java/org/apache/poi/hpsf/Section.java +++ b/poi/src/main/java/org/apache/poi/hpsf/Section.java @@ -64,7 +64,7 @@ public class Section { * established when the section's size is calculated and can be reused * later. If the array is empty, the section was modified and the bytes need to be regenerated. */ - private final UnsynchronizedByteArrayOutputStream sectionBytes = new UnsynchronizedByteArrayOutputStream(); + private final UnsynchronizedByteArrayOutputStream sectionBytes = UnsynchronizedByteArrayOutputStream.builder().get(); /** * The offset of the section in the stream. @@ -733,7 +733,7 @@ public class Section { } final int[][] offsets = new int[properties.size()][2]; - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); LittleEndianOutputStream leos = new LittleEndianOutputStream(bos)) { /* Write the section's length - dummy value, fixed later */ diff --git a/poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java index 2ef4f34cfb..74a6dee371 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java @@ -18,6 +18,7 @@ */ package org.apache.poi.hssf.record; +import java.io.IOException; import java.util.Arrays; import java.util.Map; import java.util.function.Supplier; @@ -278,7 +279,13 @@ public class DConRefRecord extends StandardRecord { } private static RecordInputStream bytesToRIStream(byte[] data) { - RecordInputStream ric = new RecordInputStream(new UnsynchronizedByteArrayInputStream(data)); + RecordInputStream ric = null; + try { + ric = new RecordInputStream(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get()); + } catch (IOException e) { + // not possible with ByteArray but still declared in the API + throw new IllegalStateException(e); + } ric.nextRecord(); return ric; } diff --git a/poi/src/main/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java b/poi/src/main/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java index a4cb805e03..ae88715975 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java @@ -19,6 +19,7 @@ package org.apache.poi.hssf.record; import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream; +import java.io.IOException; import java.util.Map; import java.util.function.Supplier; @@ -48,9 +49,15 @@ public final class DrawingRecordForBiffViewer extends AbstractEscherHolderRecord private static RecordInputStream convertToInputStream(DrawingRecord r) { byte[] data = r.serialize(); - RecordInputStream rinp = new RecordInputStream( - new UnsynchronizedByteArrayInputStream(data) - ); + RecordInputStream rinp = null; + try { + rinp = new RecordInputStream( + UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get() + ); + } catch (IOException e) { + // not possible with ByteArray but still declared in the API + throw new IllegalStateException(e); + } rinp.nextRecord(); return rinp; } diff --git a/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java index ec1dce3ffb..92c5fa799a 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java @@ -180,7 +180,7 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord { private static Ptg readRefPtg(byte[] formulaRawBytes) { try (LittleEndianInputStream in = new LittleEndianInputStream( - new UnsynchronizedByteArrayInputStream(formulaRawBytes))) { + UnsynchronizedByteArrayInputStream.builder().setByteArray(formulaRawBytes).get())) { byte ptgSid = in.readByte(); switch(ptgSid) { case AreaPtg.sid: return new AreaPtg(in); diff --git a/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java b/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java index 717b866c85..2c71372ee9 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java @@ -1034,7 +1034,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { private static class ShapeCollector extends DefaultEscherRecordFactory { final List<EscherRecord> objShapes = new ArrayList<>(); - final UnsynchronizedByteArrayOutputStream buffer = new UnsynchronizedByteArrayOutputStream(); + final UnsynchronizedByteArrayOutputStream buffer = UnsynchronizedByteArrayOutputStream.builder().get(); void addBytes(byte[] data) { try { diff --git a/poi/src/main/java/org/apache/poi/hssf/record/FilePassRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/FilePassRecord.java index 833310d495..91cfded863 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/FilePassRecord.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/FilePassRecord.java @@ -122,7 +122,7 @@ public final class FilePassRecord extends StandardRecord { @Override protected int getDataSize() { - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); LittleEndianOutputStream leos = new LittleEndianOutputStream(bos); serialize(leos); return bos.size(); diff --git a/poi/src/main/java/org/apache/poi/hssf/record/Record.java b/poi/src/main/java/org/apache/poi/hssf/record/Record.java index 3ae5c1b312..2178577bf0 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/Record.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/Record.java @@ -17,6 +17,8 @@ package org.apache.poi.hssf.record; +import java.io.IOException; + import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream; import org.apache.poi.common.Duplicatable; import org.apache.poi.common.usermodel.GenericRecord; @@ -75,7 +77,13 @@ public abstract class Record extends RecordBase implements Duplicatable, Generic // Do it via a re-serialization // It's a cheat, but it works... byte[] b = serialize(); - RecordInputStream rinp = new RecordInputStream(new UnsynchronizedByteArrayInputStream(b)); + RecordInputStream rinp = null; + try { + rinp = new RecordInputStream(UnsynchronizedByteArrayInputStream.builder().setByteArray(b).get()); + } catch (IOException e) { + // not possible with ByteArray but still declared in the API + throw new IllegalStateException(e); + } rinp.nextRecord(); Record[] r = RecordFactory.createRecord(rinp); diff --git a/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java b/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java index b41c2b9146..caeac85d66 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java @@ -453,7 +453,7 @@ public final class RecordInputStream implements LittleEndianInput { */ @Deprecated public byte[] readAllContinuedRemainder() { - try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(2 * MAX_RECORD_DATA_SIZE)) { + try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(2 * MAX_RECORD_DATA_SIZE).get()) { while (true) { byte[] b = readRemainder(); diff --git a/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java index 0c18b2b2ec..230e47b16c 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java @@ -136,7 +136,7 @@ public abstract class SubRecord implements Duplicatable, GenericRecord { protected abstract int getDataSize(); public byte[] serialize() { int size = getDataSize() + 4; - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(size); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(size).get(); serialize(new LittleEndianOutputStream(baos)); if (baos.size() != size) { throw new IllegalStateException("write size mismatch"); diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPicture.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPicture.java index 42fa643a36..ccc8eef44e 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPicture.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPicture.java @@ -18,6 +18,7 @@ package org.apache.poi.hssf.usermodel; import java.awt.Dimension; +import java.io.IOException; import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream; import org.apache.poi.ddf.DefaultEscherRecordFactory; @@ -191,7 +192,12 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { EscherBSERecord bse = iwb.getBSERecord(getPictureIndex()); byte[] data = bse.getBlipRecord().getPicturedata(); int type = bse.getBlipTypeWin32(); - return ImageUtils.getImageDimension(new UnsynchronizedByteArrayInputStream(data), type); + try { + return ImageUtils.getImageDimension(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get(), type); + } catch (IOException e) { + // not possible with ByteArray but still declared in the API + throw new IllegalStateException(e); + } } /** diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index 12a4ff008a..b303d3d7da 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -1353,7 +1353,7 @@ public final class HSSFWorkbook extends POIDocument implements Workbook { DocumentNode workbookNode = (DocumentNode) dir.getEntry( getWorkbookDirEntryName(dir)); POIFSDocument workbookDoc = new POIFSDocument(workbookNode); - workbookDoc.replaceContents(new UnsynchronizedByteArrayInputStream(getBytes())); + workbookDoc.replaceContents(UnsynchronizedByteArrayInputStream.builder().setByteArray(getBytes()).get()); // Update the properties streams in the file writeProperties(); @@ -1415,7 +1415,7 @@ public final class HSSFWorkbook extends POIDocument implements Workbook { List<String> excepts = new ArrayList<>(1); // Write out the Workbook stream - fs.createDocument(new UnsynchronizedByteArrayInputStream(getBytes()), "Workbook"); + fs.createDocument(UnsynchronizedByteArrayInputStream.builder().setByteArray(getBytes()).get(), "Workbook"); // Write out our HPFS properties, if we have them writeProperties(fs, excepts); @@ -2110,7 +2110,7 @@ public final class HSSFWorkbook extends POIDocument implements Workbook { } } - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { poiData.writeFilesystem(bos); return addOlePackage(bos.toByteArray(), label, fileName, command); } @@ -2138,7 +2138,7 @@ public final class HSSFWorkbook extends POIDocument implements Workbook { Ole10Native.createOleMarkerEntry(oleDir); Ole10Native oleNative = new Ole10Native(label, fileName, command, oleData); - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { oleNative.writeOut(bos); oleDir.createDocument(Ole10Native.OLE10_NATIVE, bos.toInputStream()); } diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/DocumentOutputStream.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/DocumentOutputStream.java index e848859a00..3efcb1055c 100644 --- a/poi/src/main/java/org/apache/poi/poifs/filesystem/DocumentOutputStream.java +++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/DocumentOutputStream.java @@ -43,7 +43,7 @@ public final class DocumentOutputStream extends OutputStream { /** our buffer, when null we're into normal blocks */ private UnsynchronizedByteArrayOutputStream _buffer = - new UnsynchronizedByteArrayOutputStream(POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE); + UnsynchronizedByteArrayOutputStream.builder().setBufferSize(POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE).get(); /** our main block stream, when we're into normal blocks */ private POIFSStream _stream; @@ -105,7 +105,7 @@ public final class DocumentOutputStream extends OutputStream { } // Have an empty one created for now - return parent.createDocument(name, new UnsynchronizedByteArrayInputStream(new byte[0])); + return parent.createDocument(name, UnsynchronizedByteArrayInputStream.builder().setByteArray(new byte[0]).get()); } private void checkBufferSize() throws IOException { diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java index 762038b3c4..90fbc2433e 100644 --- a/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java +++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java @@ -254,7 +254,7 @@ public class Ole10Native { */ public static void createOleMarkerEntry(final DirectoryEntry parent) throws IOException { if (!parent.hasEntry(OLE_MARKER_NAME)) { - parent.createDocument(OLE_MARKER_NAME, new UnsynchronizedByteArrayInputStream(OLE_MARKER_BYTES)); + parent.createDocument(OLE_MARKER_NAME, UnsynchronizedByteArrayInputStream.builder().setByteArray(OLE_MARKER_BYTES).get()); } } @@ -402,7 +402,7 @@ public class Ole10Native { switch (mode) { case parsed: { - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); try (LittleEndianOutputStream leos = new LittleEndianOutputStream(bos)) { // total size, will be determined later .. diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java index 727030bf15..f70edb9044 100644 --- a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java +++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java @@ -780,9 +780,9 @@ public class POIFSFileSystem extends BlockStore // _header.setPropertyStart has been updated on write ... // HeaderBlock - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream( + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize( _header.getBigBlockSize().getBigBlockSize() - ); + ).get(); _header.writeData(baos); getBlockAt(-1).put(baos.toByteArray()); diff --git a/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java b/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java index 9dec8e6ca6..c89b650452 100644 --- a/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java +++ b/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java @@ -233,7 +233,11 @@ public class VBAMacroReader implements Closeable { } else { // Decompress a previously found module and store the decompressed result into module.buf InputStream stream = new RLEDecompressingInputStream( - new UnsynchronizedByteArrayInputStream(module.buf, moduleOffset, module.buf.length - moduleOffset) + UnsynchronizedByteArrayInputStream.builder(). + setByteArray(module.buf). + setOffset(moduleOffset). + setLength(module.buf.length - moduleOffset). + get() ); module.read(stream); stream.close(); @@ -275,7 +279,7 @@ public class VBAMacroReader implements Closeable { } if (decompressedBytes != null) { - module.read(new UnsynchronizedByteArrayInputStream(decompressedBytes)); + module.read(UnsynchronizedByteArrayInputStream.builder().setByteArray(decompressedBytes).get()); } } @@ -668,7 +672,7 @@ public class VBAMacroReader implements Closeable { private static String readUnicode(InputStream is) throws IOException { //reads null-terminated unicode string - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { int b0 = IOUtils.readByte(is); int b1 = IOUtils.readByte(is); @@ -688,7 +692,7 @@ public class VBAMacroReader implements Closeable { } private static String readMBCS(int firstByte, InputStream is, Charset charset) throws IOException { - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { int len = 0; int b = firstByte; while (b > 0 && len < MAX_STRING_LENGTH) { @@ -802,7 +806,11 @@ public class VBAMacroReader implements Closeable { if (w <= 0 || (w & 0x7000) != 0x3000) { continue; } - decompressed = tryToDecompress(new UnsynchronizedByteArrayInputStream(compressed, i, compressed.length - i)); + decompressed = tryToDecompress(UnsynchronizedByteArrayInputStream.builder(). + setByteArray(compressed). + setOffset(i). + setLength(compressed.length - i). + get()); if (decompressed != null) { if (decompressed.length > 9) { //this is a complete hack. The challenge is that there diff --git a/poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java b/poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java index 14bd636e84..b7ea54ddf5 100644 --- a/poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java +++ b/poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java @@ -85,7 +85,7 @@ public class BitmapImageRenderer implements ImageRenderer { public void loadImage(InputStream data, String contentType) throws IOException { InputStream in = data; if (doCache) { - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { IOUtils.copy(data, bos); cachedImage = bos.toByteArray(); cachedContentType = contentType; @@ -104,7 +104,7 @@ public class BitmapImageRenderer implements ImageRenderer { cachedImage = data.clone(); cachedContentType = contentType; } - img = readImage(new UnsynchronizedByteArrayInputStream(data), contentType); + img = readImage(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get(), contentType); } /** diff --git a/poi/src/main/java/org/apache/poi/sl/image/ImageHeaderBitmap.java b/poi/src/main/java/org/apache/poi/sl/image/ImageHeaderBitmap.java index 9f7564cfe2..f16fe436e1 100644 --- a/poi/src/main/java/org/apache/poi/sl/image/ImageHeaderBitmap.java +++ b/poi/src/main/java/org/apache/poi/sl/image/ImageHeaderBitmap.java @@ -38,7 +38,7 @@ public class ImageHeaderBitmap { public ImageHeaderBitmap(byte[] data, int offset) { BufferedImage img = null; try { - img = ImageIO.read(new UnsynchronizedByteArrayInputStream(data, offset, data.length-offset)); + img = ImageIO.read(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).setOffset(offset).setLength(data.length-offset).get()); } catch (IOException e) { LOG.atWarn().withThrowable(e).log("Can't determine image dimensions"); } diff --git a/poi/src/main/java/org/apache/poi/sl/usermodel/ObjectShape.java b/poi/src/main/java/org/apache/poi/sl/usermodel/ObjectShape.java index 3c36c77827..8f6bd803e4 100644 --- a/poi/src/main/java/org/apache/poi/sl/usermodel/ObjectShape.java +++ b/poi/src/main/java/org/apache/poi/sl/usermodel/ObjectShape.java @@ -96,7 +96,7 @@ public interface ObjectShape< final Application app = Application.lookup(progId); - try (final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + try (final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); final InputStream is = FileMagic.prepareToCheckMagic(readObjectDataRaw())) { final FileMagic fm = FileMagic.valueOf(is); diff --git a/poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java b/poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java index bdaccb7d6c..31c6632c07 100644 --- a/poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java +++ b/poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java @@ -177,7 +177,7 @@ public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> { protected EmbeddedData extract(DirectoryNode dn) throws IOException { assert(canExtract(dn)); - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(20000); + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(20000).get(); POIFSFileSystem dest = new POIFSFileSystem()) { copyNodes(dn, dest.getRoot()); // start with a reasonable big size @@ -218,7 +218,7 @@ public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> { @Override public EmbeddedData extract(DirectoryNode dn) throws IOException { - try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); InputStream is = dn.createDocumentInputStream("CONTENTS")) { IOUtils.copy(is, bos); return new EmbeddedData(dn.getName() + ".pdf", bos.toByteArray(), CONTENT_TYPE_PDF); diff --git a/poi/src/main/java/org/apache/poi/ss/util/ImageUtils.java b/poi/src/main/java/org/apache/poi/ss/util/ImageUtils.java index adb426d358..18f162395f 100644 --- a/poi/src/main/java/org/apache/poi/ss/util/ImageUtils.java +++ b/poi/src/main/java/org/apache/poi/ss/util/ImageUtils.java @@ -143,6 +143,7 @@ public final class ImageUtils { * @param scaleY the amount by which image height is multiplied relative to the original height. * @return the new Dimensions of the scaled picture in EMUs * @throws IllegalArgumentException if scale values lead to negative or infinite results + * @throws IllegalStateException if the picture data is corrupt */ public static Dimension setPreferredSize(Picture picture, double scaleX, double scaleY) { ClientAnchor anchor = picture.getClientAnchor(); @@ -151,9 +152,15 @@ public final class ImageUtils { Sheet sheet = picture.getSheet(); // in pixel - final Dimension imgSize = (scaleX == Double.MAX_VALUE || scaleY == Double.MAX_VALUE) - ? getImageDimension(new UnsynchronizedByteArrayInputStream(data.getData()), data.getPictureType()) - : new Dimension(); + final Dimension imgSize; + try { + imgSize = (scaleX == Double.MAX_VALUE || scaleY == Double.MAX_VALUE) + ? getImageDimension(UnsynchronizedByteArrayInputStream.builder().setByteArray(data.getData()).get(), data.getPictureType()) + : new Dimension(); + } catch (IOException e) { + // is actually impossible with ByteArray, but still declared in the interface + throw new IllegalStateException(e); + } // in emus final Dimension anchorSize = (scaleX != Double.MAX_VALUE || scaleY != Double.MAX_VALUE) @@ -192,7 +199,12 @@ public final class ImageUtils { Dimension imgSize = null; if (anchor.getCol2() < anchor.getCol1() || anchor.getRow2() < anchor.getRow1()) { PictureData data = picture.getPictureData(); - imgSize = getImageDimension(new UnsynchronizedByteArrayInputStream(data.getData()), data.getPictureType()); + try { + imgSize = getImageDimension(UnsynchronizedByteArrayInputStream.builder().setByteArray(data.getData()).get(), data.getPictureType()); + } catch (IOException e) { + // not possible with ByteArray but still declared in the API + throw new IllegalStateException(e); + } } int w = getDimFromCell(imgSize == null ? 0 : imgSize.getWidth(), anchor.getCol1(), anchor.getDx1(), anchor.getCol2(), anchor.getDx2(), diff --git a/poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java b/poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java index 370a02f672..7b24b774f6 100644 --- a/poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java +++ b/poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java @@ -19,8 +19,6 @@ package org.apache.poi.util; -import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM; - import java.awt.Color; import java.awt.geom.AffineTransform; import java.awt.geom.Dimension2D; @@ -55,6 +53,7 @@ import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.io.output.NullOutputStream; import org.apache.poi.common.usermodel.GenericRecord; import org.apache.poi.util.GenericRecordUtil.AnnotatedFlag; @@ -117,7 +116,7 @@ public class GenericRecordJsonWriter implements Closeable { protected int childIndex = 0; public GenericRecordJsonWriter(File fileName) throws IOException { - OutputStream os = ("null".equals(fileName.getName())) ? NULL_OUTPUT_STREAM : new FileOutputStream(fileName); + OutputStream os = ("null".equals(fileName.getName())) ? NullOutputStream.INSTANCE : new FileOutputStream(fileName); aw = new AppendableWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8)); fw = new PrintWriter(aw); } diff --git a/poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java b/poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java index b812a3d31c..ba098965d3 100644 --- a/poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java +++ b/poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java @@ -19,8 +19,6 @@ package org.apache.poi.util; -import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM; - import java.awt.Color; import java.awt.geom.AffineTransform; import java.awt.geom.Dimension2D; @@ -50,6 +48,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.apache.commons.io.output.NullOutputStream; import org.apache.poi.common.usermodel.GenericRecord; import org.apache.poi.util.GenericRecordJsonWriter.AppendableWriter; @@ -109,7 +108,7 @@ public class GenericRecordXmlWriter implements Closeable { private boolean attributePhase = true; public GenericRecordXmlWriter(File fileName) throws IOException { - OutputStream os = ("null".equals(fileName.getName())) ? NULL_OUTPUT_STREAM : new FileOutputStream(fileName); + OutputStream os = ("null".equals(fileName.getName())) ? NullOutputStream.INSTANCE : new FileOutputStream(fileName); fw = new PrintWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8)); } diff --git a/poi/src/main/java/org/apache/poi/util/IOUtils.java b/poi/src/main/java/org/apache/poi/util/IOUtils.java index 6dd510fe39..51281d4bba 100644 --- a/poi/src/main/java/org/apache/poi/util/IOUtils.java +++ b/poi/src/main/java/org/apache/poi/util/IOUtils.java @@ -141,7 +141,7 @@ public final class IOUtils { checkByteSizeLimit(limit); stream.mark(limit); - try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(limit)) { + try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(limit).get()) { copy(new BoundedInputStream(stream, limit), bos); int readBytes = bos.size(); @@ -238,7 +238,7 @@ public final class IOUtils { final int derivedLen = isLengthKnown ? Math.min(length, derivedMaxLength) : derivedMaxLength; final int byteArrayInitLen = calculateByteArrayInitLength(isLengthKnown, length, derivedMaxLength); final int internalBufferLen = DEFAULT_BUFFER_SIZE; - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(byteArrayInitLen)) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(byteArrayInitLen).get()) { byte[] buffer = new byte[internalBufferLen]; int totalBytes = 0, readBytes; do { diff --git a/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java b/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java index a883ee3abb..3bbec57f50 100644 --- a/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java +++ b/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java @@ -102,7 +102,7 @@ public abstract class LZWDecompresser { * of the decompressed input. */ public byte[] decompress(InputStream src) throws IOException { - UnsynchronizedByteArrayOutputStream res = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream res = UnsynchronizedByteArrayOutputStream.builder().get(); decompress(src, res); return res.toByteArray(); } diff --git a/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java b/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java index b59950b96c..55ba486407 100644 --- a/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java +++ b/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java @@ -277,8 +277,8 @@ public class RLEDecompressingInputStream extends InputStream { } public static byte[] decompress(byte[] compressed, int offset, int length) throws IOException { - try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); - InputStream instream = new UnsynchronizedByteArrayInputStream(compressed, offset, length); + try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); + InputStream instream = UnsynchronizedByteArrayInputStream.builder().setByteArray(compressed).setOffset(offset).setLength(length).get(); InputStream stream = new RLEDecompressingInputStream(instream)) { IOUtils.copy(stream, out); diff --git a/poi/src/test/java/org/apache/poi/POIDataSamples.java b/poi/src/test/java/org/apache/poi/POIDataSamples.java index 3e04fc8976..d96e2f264e 100644 --- a/poi/src/test/java/org/apache/poi/POIDataSamples.java +++ b/poi/src/test/java/org/apache/poi/POIDataSamples.java @@ -264,7 +264,7 @@ public final class POIDataSamples { */ public byte[] readFile(String fileName) { try (InputStream fis = openResourceAsStream(fileName); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { IOUtils.copy(fis, bos); return bos.toByteArray(); } catch (IOException e) { @@ -273,7 +273,7 @@ public final class POIDataSamples { } public static POIFSFileSystem writeOutAndReadBack(POIFSFileSystem original) throws IOException { - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) { original.writeFilesystem(baos); return new POIFSFileSystem(baos.toInputStream()); } diff --git a/poi/src/test/java/org/apache/poi/TestPOIDocumentMain.java b/poi/src/test/java/org/apache/poi/TestPOIDocumentMain.java index 78fd9db41b..24f0063916 100644 --- a/poi/src/test/java/org/apache/poi/TestPOIDocumentMain.java +++ b/poi/src/test/java/org/apache/poi/TestPOIDocumentMain.java @@ -87,7 +87,7 @@ final class TestPOIDocumentMain { @Test void WriteReadProperties() throws IOException { - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); // Write them out try (POIDocument xls = openSampleWorkbook("DateFormats.xls"); diff --git a/poi/src/test/java/org/apache/poi/ddf/TestEscherDump.java b/poi/src/test/java/org/apache/poi/ddf/TestEscherDump.java index 07c67c4c10..635af68dde 100644 --- a/poi/src/test/java/org/apache/poi/ddf/TestEscherDump.java +++ b/poi/src/test/java/org/apache/poi/ddf/TestEscherDump.java @@ -64,7 +64,7 @@ class TestEscherDump { "eJr+iZEHAAA="; private final EscherDump dumper = new EscherDump(); - private final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + private final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); private PrintStream stream; @BeforeEach diff --git a/poi/src/test/java/org/apache/poi/hpsf/basic/TestHPSFBugs.java b/poi/src/test/java/org/apache/poi/hpsf/basic/TestHPSFBugs.java index bd86d39cc2..e3fb4d30b1 100644 --- a/poi/src/test/java/org/apache/poi/hpsf/basic/TestHPSFBugs.java +++ b/poi/src/test/java/org/apache/poi/hpsf/basic/TestHPSFBugs.java @@ -121,7 +121,7 @@ final class TestHPSFBugs { // Write out and read back, should still be valid - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); try (POIDocument doc = new HPSFPropertiesOnlyDocument(fs)) { doc.write(baos); } diff --git a/poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java b/poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java index 0bf0b99ce7..0f7d88939d 100644 --- a/poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java +++ b/poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java @@ -527,7 +527,7 @@ final class TestMetaDataIPI { dsi.write(poifs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME); si.write(poifs.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME); - UnsynchronizedByteArrayOutputStream bout = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bout = UnsynchronizedByteArrayOutputStream.builder().get(); poifs.writeFilesystem(bout); poifs.close(); diff --git a/poi/src/test/java/org/apache/poi/hpsf/basic/TestReadAllFiles.java b/poi/src/test/java/org/apache/poi/hpsf/basic/TestReadAllFiles.java index 057e16ae87..4cf5a31eb7 100644 --- a/poi/src/test/java/org/apache/poi/hpsf/basic/TestReadAllFiles.java +++ b/poi/src/test/java/org/apache/poi/hpsf/basic/TestReadAllFiles.java @@ -101,7 +101,7 @@ class TestReadAllFiles { /* Create a new POI filesystem containing the origin file's * property set streams: */ - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); try (POIFSFileSystem poiFs = new POIFSFileSystem()) { for (POIFile poifile : Util.readPropertySets(file)) { final InputStream in = new ByteArrayInputStream(poifile.getBytes()); diff --git a/poi/src/test/java/org/apache/poi/hpsf/basic/TestWrite.java b/poi/src/test/java/org/apache/poi/hpsf/basic/TestWrite.java index 5af30cd978..48b8b594ec 100644 --- a/poi/src/test/java/org/apache/poi/hpsf/basic/TestWrite.java +++ b/poi/src/test/java/org/apache/poi/hpsf/basic/TestWrite.java @@ -110,7 +110,7 @@ class TestWrite { /* Write it to a POIFS and the latter to disk: */ try (OutputStream out = new FileOutputStream(filename); POIFSFileSystem poiFs = new POIFSFileSystem(); - UnsynchronizedByteArrayOutputStream psStream = new UnsynchronizedByteArrayOutputStream()) { + UnsynchronizedByteArrayOutputStream psStream = UnsynchronizedByteArrayOutputStream.builder().get()) { assertThrows(NoFormatIDException.class, () -> ps.write(psStream)); poiFs.createDocument(psStream.toInputStream(), SummaryInformation.DEFAULT_STREAM_NAME); poiFs.writeFilesystem(out); @@ -132,7 +132,7 @@ class TestWrite { /* Create a mutable property set and write it to a POIFS: */ try (OutputStream out = new FileOutputStream(filename); POIFSFileSystem poiFs = new POIFSFileSystem(); - UnsynchronizedByteArrayOutputStream psStream = new UnsynchronizedByteArrayOutputStream()) { + UnsynchronizedByteArrayOutputStream psStream = UnsynchronizedByteArrayOutputStream.builder().get()) { final PropertySet ps = new PropertySet(); final Section s = ps.getSections().get(0); s.setFormatID(SummaryInformation.FORMAT_ID); @@ -343,7 +343,7 @@ class TestWrite { p.setValue(TITLE); ms.setProperty(p); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); mps.write(out); byte[] bytes = out.toByteArray(); @@ -373,7 +373,7 @@ class TestWrite { private void check(final long variantType, final Object value, final int codepage) throws UnsupportedVariantTypeException, IOException { - final UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + final UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); VariantSupport.write(out, variantType, value, codepage); final byte[] b = out.toByteArray(); final Object objRead = @@ -526,9 +526,9 @@ class TestWrite { doufStream.close(); // And also write to some bytes for checking - UnsynchronizedByteArrayOutputStream sinfBytes = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream sinfBytes = UnsynchronizedByteArrayOutputStream.builder().get(); sinf.write(sinfBytes); - UnsynchronizedByteArrayOutputStream dinfBytes = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream dinfBytes = UnsynchronizedByteArrayOutputStream.builder().get(); dinf.write(dinfBytes); diff --git a/poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java b/poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java index 29cf6852aa..e85ff044ab 100644 --- a/poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java +++ b/poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java @@ -55,7 +55,7 @@ public final class HSSFTestDataSamples { * Useful for verifying that the serialisation round trip */ public static HSSFWorkbook writeOutAndReadBack(HSSFWorkbook original) { - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) { original.write(baos); try (InputStream is = baos.toInputStream()) { return new HSSFWorkbook(is); diff --git a/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java b/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java index f36e24d562..0d42a7ba42 100644 --- a/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java +++ b/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java @@ -135,7 +135,7 @@ final class TestEventRecordFactory { */ @Test void testContinuedUnknownRecord() throws IOException { - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); for (byte[] b : CONTINUE_DATA) { bos.write(b); } diff --git a/poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java b/poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java index 3121ee039d..91c7a36513 100644 --- a/poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java +++ b/poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java @@ -314,7 +314,7 @@ final class TestOldExcelExtractor { SecurityManager sm = System.getSecurityManager(); System.setSecurityManager(new NoExitSecurityManager()); try { - System.setErr(new NullPrintStream()); + System.setErr(NullPrintStream.INSTANCE); // calls System.exit() assertThrows(ExitException.class, () -> OldExcelExtractor.main(new String[]{})); } finally { @@ -328,7 +328,7 @@ final class TestOldExcelExtractor { void testMain() throws IOException { File file = HSSFTestDataSamples.getSampleFile("testEXCEL_3.xls"); PrintStream save = System.out; - try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); PrintStream str = new PrintStream(out, false, StandardCharsets.UTF_8.displayName(LocaleUtil.getUserLocale()))) { System.setOut(str); OldExcelExtractor.main(new String[] {file.getAbsolutePath()}); diff --git a/poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java b/poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java index 6b99428aea..b904af8808 100644 --- a/poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java +++ b/poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java @@ -114,7 +114,7 @@ class TestDrawingAggregate { * @return the raw data being aggregated */ byte[] getRawBytes(){ - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); for (RecordBase rb : aggRecords) { Record r = (org.apache.poi.hssf.record.Record) rb; try { @@ -222,7 +222,7 @@ class TestDrawingAggregate { assertEquals(dgBytes.length, pos, "data was not fully read"); // serialize to byte array - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); for(EscherRecord r : records) { out.write(r.serialize()); } @@ -248,7 +248,7 @@ class TestDrawingAggregate { } private static byte[] toByteArray(List<RecordBase> records) { - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); for (RecordBase rb : records) { Record r = (org.apache.poi.hssf.record.Record) rb; try { diff --git a/poi/src/test/java/org/apache/poi/hssf/model/TestEscherRecordFactory.java b/poi/src/test/java/org/apache/poi/hssf/model/TestEscherRecordFactory.java index 69566e59f5..091802098c 100644 --- a/poi/src/test/java/org/apache/poi/hssf/model/TestEscherRecordFactory.java +++ b/poi/src/test/java/org/apache/poi/hssf/model/TestEscherRecordFactory.java @@ -39,7 +39,7 @@ import org.junit.jupiter.api.Test; class TestEscherRecordFactory { private static byte[] toByteArray(List<RecordBase> records) { - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); for (RecordBase rb : records) { Record r = (org.apache.poi.hssf.record.Record) rb; try { diff --git a/poi/src/test/java/org/apache/poi/hssf/record/TestDConRefRecord.java b/poi/src/test/java/org/apache/poi/hssf/record/TestDConRefRecord.java index 466f596650..91bf456816 100644 --- a/poi/src/test/java/org/apache/poi/hssf/record/TestDConRefRecord.java +++ b/poi/src/test/java/org/apache/poi/hssf/record/TestDConRefRecord.java @@ -209,7 +209,7 @@ class TestDConRefRecord { private void testReadWrite(byte[] data, String message) throws IOException { RecordInputStream is = TestcaseRecordInputStream.create(81, data); DConRefRecord d = new DConRefRecord(is); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(data.length); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(data.length).get(); LittleEndianOutputStream o = new LittleEndianOutputStream(bos); d.serialize(o); o.flush(); diff --git a/poi/src/test/java/org/apache/poi/hssf/record/TestDrawingRecord.java b/poi/src/test/java/org/apache/poi/hssf/record/TestDrawingRecord.java index d519393c8c..f0df67af50 100644 --- a/poi/src/test/java/org/apache/poi/hssf/record/TestDrawingRecord.java +++ b/poi/src/test/java/org/apache/poi/hssf/record/TestDrawingRecord.java @@ -38,7 +38,7 @@ final class TestDrawingRecord { void testReadContinued() throws IOException { //simulate a continues drawing record - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); //main part DrawingRecord dg = new DrawingRecord(); byte[] data1 = new byte[8224]; diff --git a/poi/src/test/java/org/apache/poi/hssf/record/TestLbsDataSubRecord.java b/poi/src/test/java/org/apache/poi/hssf/record/TestLbsDataSubRecord.java index 005d03d6ef..53e1229537 100644 --- a/poi/src/test/java/org/apache/poi/hssf/record/TestLbsDataSubRecord.java +++ b/poi/src/test/java/org/apache/poi/hssf/record/TestLbsDataSubRecord.java @@ -166,7 +166,7 @@ final class TestLbsDataSubRecord { try (LittleEndianInputStream in = new LittleEndianInputStream(new ByteArrayInputStream(data))) { LbsDataSubRecord.LbsDropData lbs = new LbsDataSubRecord.LbsDropData(in); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); try (LittleEndianOutputStream out = new LittleEndianOutputStream(baos)) { lbs.serialize(out); diff --git a/poi/src/test/java/org/apache/poi/hssf/record/TestRecordFactory.java b/poi/src/test/java/org/apache/poi/hssf/record/TestRecordFactory.java index e9737324e8..26793e1930 100644 --- a/poi/src/test/java/org/apache/poi/hssf/record/TestRecordFactory.java +++ b/poi/src/test/java/org/apache/poi/hssf/record/TestRecordFactory.java @@ -185,7 +185,7 @@ final class TestRecordFactory { assertTrue(records.get(4) instanceof ObjRecord); //serialize and verify that the serialized data is the same as the original - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); for(org.apache.poi.hssf.record.Record rec : records){ out.write(rec.serialize()); } @@ -204,7 +204,7 @@ final class TestRecordFactory { BOFRecord.createSheetBOF(), EOFRecord.instance, }; - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); for (org.apache.poi.hssf.record.Record rec : recs) { try { baos.write(rec.serialize()); diff --git a/poi/src/test/java/org/apache/poi/hssf/record/TestSSTRecord.java b/poi/src/test/java/org/apache/poi/hssf/record/TestSSTRecord.java index eed605b661..da90507400 100644 --- a/poi/src/test/java/org/apache/poi/hssf/record/TestSSTRecord.java +++ b/poi/src/test/java/org/apache/poi/hssf/record/TestSSTRecord.java @@ -49,7 +49,7 @@ final class TestSSTRecord { */ private static byte[] concatHexDumps(String... hexDumpFileNames) throws IOException { int nFiles = hexDumpFileNames.length; - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(nFiles * 8228); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(nFiles * 8228).get(); for (String sampleFileName : hexDumpFileNames) { try (InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName)) { BufferedReader br = new BufferedReader(new InputStreamReader(is, LocaleUtil.CHARSET_1252)); diff --git a/poi/src/test/java/org/apache/poi/hssf/record/common/TestUnicodeString.java b/poi/src/test/java/org/apache/poi/hssf/record/common/TestUnicodeString.java index 57b344bd25..8abd514c6c 100644 --- a/poi/src/test/java/org/apache/poi/hssf/record/common/TestUnicodeString.java +++ b/poi/src/test/java/org/apache/poi/hssf/record/common/TestUnicodeString.java @@ -185,7 +185,7 @@ final class TestUnicodeString { assertEquals(4, fr.getCharacterPos()); assertEquals(0x15c, fr.getFontIndex()); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); LittleEndianOutputStream out = new LittleEndianOutputStream(baos); fr.serialize(out); @@ -216,7 +216,7 @@ final class TestUnicodeString { assertEquals(0, ext.getPhRuns().length); assertEquals(10, ext.getDataSize()); // Excludes 4 byte header - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); LittleEndianOutputStream out = new LittleEndianOutputStream(baos); ContinuableRecordOutput cout = new ContinuableRecordOutput(out, 0xffff); diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestBugs.java b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestBugs.java index b29c4bc3ee..b836e3269c 100644 --- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestBugs.java @@ -1175,9 +1175,9 @@ final class TestBugs extends BaseTestBugzillaIssues { @Test void bug32191() throws IOException { try (HSSFWorkbook wb = openSampleWorkbook("27394.xls"); - UnsynchronizedByteArrayOutputStream out1 = new UnsynchronizedByteArrayOutputStream(); - UnsynchronizedByteArrayOutputStream out2 = new UnsynchronizedByteArrayOutputStream(); - UnsynchronizedByteArrayOutputStream out3 = new UnsynchronizedByteArrayOutputStream()) { + UnsynchronizedByteArrayOutputStream out1 = UnsynchronizedByteArrayOutputStream.builder().get(); + UnsynchronizedByteArrayOutputStream out2 = UnsynchronizedByteArrayOutputStream.builder().get(); + UnsynchronizedByteArrayOutputStream out3 = UnsynchronizedByteArrayOutputStream.builder().get()) { wb.write(out1); wb.write(out2); wb.write(out3); @@ -2331,7 +2331,7 @@ final class TestBugs extends BaseTestBugzillaIssues { } // Convert BufferedImage to byte[] - UnsynchronizedByteArrayOutputStream imageBAOS = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream imageBAOS = UnsynchronizedByteArrayOutputStream.builder().get(); ImageIO.write(bimage, "jpeg", imageBAOS); imageBAOS.flush(); byte[] imageBytes = imageBAOS.toByteArray(); @@ -2614,7 +2614,7 @@ final class TestBugs extends BaseTestBugzillaIssues { void test66319() throws IOException { try ( HSSFWorkbook workbook = openSampleWorkbook("bug66319.xls"); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { for (Sheet sheet : workbook) { for (Row row : sheet) { @@ -2631,7 +2631,7 @@ final class TestBugs extends BaseTestBugzillaIssues { void test66319WithRemove() throws IOException { try ( HSSFWorkbook workbook = openSampleWorkbook("bug66319.xls"); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { for (Sheet sheet : workbook) { for (Row row : sheet) { diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestDataValidation.java b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestDataValidation.java index b978581ee2..f5a0f1620d 100644 --- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestDataValidation.java +++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestDataValidation.java @@ -61,7 +61,7 @@ final class TestDataValidation extends BaseTestDataValidation { void assertDataValidation(Workbook wb) { byte[] generatedContent; - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(22000)) { + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(22000).get()) { wb.write(baos); generatedContent = baos.toByteArray(); } catch (IOException e) { @@ -133,7 +133,7 @@ final class TestDataValidation extends BaseTestDataValidation { sheet.addValidationData(dv); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); wb.write(baos); byte[] wbData = baos.toByteArray(); diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFCell.java b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFCell.java index b4ea25eddc..48ef715a92 100644 --- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFCell.java +++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFCell.java @@ -422,7 +422,7 @@ final class TestHSSFCell extends BaseTestCell { void setFillForegroundColor() throws IOException { try ( HSSFWorkbook wb = new HSSFWorkbook(); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get() ) { Cell cell = wb.createSheet().createRow(0).createCell(0); HSSFCellStyle cellStyle = wb.createCellStyle(); diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java index 3cd5b70382..6b9a1575f6 100644 --- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java +++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java @@ -559,7 +559,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { HSSFWorkbook wb = new HSSFWorkbook(fs1)) { ClassID clsid1 = fs1.getRoot().getStorageClsid(); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(4096); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(4096).get(); wb.write(out); try (POIFSFileSystem fs2 = new POIFSFileSystem(out.toInputStream())) { ClassID clsid2 = fs2.getRoot().getStorageClsid(); @@ -974,7 +974,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { assertNotNull(name); assertEquals("ASheet!A1", name.getRefersToFormula()); - UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().get(); wb.write(stream); assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3", "ASheet"); @@ -985,7 +985,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { assertSheetOrder(wb, "Sheet1", "Sheet3", "ASheet"); assertEquals("ASheet!A1", name.getRefersToFormula()); - UnsynchronizedByteArrayOutputStream stream2 = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream stream2 = UnsynchronizedByteArrayOutputStream.builder().get(); wb.write(stream2); assertSheetOrder(wb, "Sheet1", "Sheet3", "ASheet"); @@ -1074,7 +1074,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { private void writeAndCloseWorkbook(Workbook workbook, File file) throws IOException { - final UnsynchronizedByteArrayOutputStream bytesOut = new UnsynchronizedByteArrayOutputStream(); + final UnsynchronizedByteArrayOutputStream bytesOut = UnsynchronizedByteArrayOutputStream.builder().get(); workbook.write(bytesOut); workbook.close(); @@ -1182,7 +1182,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { @Test void checkExistingFileForR1C1Refs() throws IOException { try ( - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); HSSFWorkbook wb = openSampleWorkbook("49423.xls") ) { assertEquals(CellReferenceType.A1, wb.getCellReferenceType()); @@ -1198,7 +1198,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { @Test void checkNewFileForR1C1Refs() throws IOException { try ( - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); HSSFWorkbook wb = new HSSFWorkbook() ) { assertEquals(CellReferenceType.UNKNOWN, wb.getCellReferenceType()); diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestOLE2Embedding.java b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestOLE2Embedding.java index ca892b9ca8..cd96d6c605 100644 --- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestOLE2Embedding.java +++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestOLE2Embedding.java @@ -105,7 +105,7 @@ final class TestOLE2Embedding { circle.setNoFill(true); try (HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1)) { - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); HSSFObjectData od = wb2.getAllEmbeddedObjects().get(0); Ole10Native ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode) od.getDirectory()); bos.reset(); @@ -135,7 +135,7 @@ final class TestOLE2Embedding { } static POIFSFileSystem getSampleXLS() throws IOException { - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); try (HSSFWorkbook wb = new HSSFWorkbook()) { HSSFSheet sheet = wb.createSheet(); sheet.createRow(5).createCell(2).setCellValue("yo dawg i herd you like embeddet objekts, so we put an ole in your ole so you can save a file while you save a file"); diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java index 5ff7c4e5ca..2bc2da0a1c 100644 --- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java +++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java @@ -42,7 +42,7 @@ class TestPOIFSProperties { @Test void testFail() throws IOException, NoPropertySetStreamException, WritingNotSupportedException { - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); // read the workbook, adjust the SummaryInformation and write the data to a byte array try (POIFSFileSystem fs = openFileSystem(); HSSFWorkbook wb = new HSSFWorkbook(fs)) { @@ -61,7 +61,7 @@ class TestPOIFSProperties { @Test void testOK() throws Exception { - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); // read the workbook, adjust the SummaryInformation and write the data to a byte array try (POIFSFileSystem fs = openFileSystem()) { diff --git a/poi/src/test/java/org/apache/poi/poifs/crypt/agile/TestAgileDecryptor.java b/poi/src/test/java/org/apache/poi/poifs/crypt/agile/TestAgileDecryptor.java index 0d08b232bf..2ee6ba30e1 100644 --- a/poi/src/test/java/org/apache/poi/poifs/crypt/agile/TestAgileDecryptor.java +++ b/poi/src/test/java/org/apache/poi/poifs/crypt/agile/TestAgileDecryptor.java @@ -69,7 +69,7 @@ class TestAgileDecryptor { os.write(testData); } - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); fsEnc.writeFilesystem(bos); bos.close(); diff --git a/poi/src/test/java/org/apache/poi/poifs/dev/TestPOIFSDump.java b/poi/src/test/java/org/apache/poi/poifs/dev/TestPOIFSDump.java index ad58573764..e13f205c40 100644 --- a/poi/src/test/java/org/apache/poi/poifs/dev/TestPOIFSDump.java +++ b/poi/src/test/java/org/apache/poi/poifs/dev/TestPOIFSDump.java @@ -51,7 +51,7 @@ public class TestPOIFSDump { @BeforeAll public static void setUp() throws UnsupportedEncodingException { SYSTEM = System.out; - System.setOut(new NullPrintStream()); + System.setOut(NullPrintStream.INSTANCE); } @AfterAll diff --git a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocument.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocument.java index 4994d5db98..94bc700be3 100644 --- a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocument.java +++ b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocument.java @@ -68,7 +68,7 @@ class TestDocument { // verify that output is correct POIFSDocument document = checkDocument(poifs, LARGER_BIG_BLOCK_SIZE + 1); DocumentProperty property = document.getDocumentProperty(); - UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().get(); property.writeData(stream); byte[] output = stream.toByteArray(); @@ -135,7 +135,7 @@ class TestDocument { assertEquals(blockCountExp, blockCountAct); - UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().get(); try (DocumentInputStream dis = document.getFileSystem().createDocumentInputStream( document.getDocumentProperty().getName())) { IOUtils.copy(dis, stream); diff --git a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java index 8674a41d15..bd1da88a7c 100644 --- a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java +++ b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java @@ -97,7 +97,7 @@ final class TestDocumentOutputStream { root.createDocument("foo", expected.length, l); try (DocumentInputStream is = root.createDocumentInputStream("foo")) { - final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(expected.length); + final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(expected.length).get(); IOUtils.copy(is, bos); assertArrayEquals(expected, bos.toByteArray()); } diff --git a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEmptyDocument.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEmptyDocument.java index a2da085b01..f60ce5bc3b 100644 --- a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEmptyDocument.java +++ b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEmptyDocument.java @@ -82,7 +82,7 @@ final class TestEmptyDocument { DirectoryEntry dir = fs.getRoot(); emptyDoc.handle(dir); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); fs.writeFilesystem(out); assertDoesNotThrow(() -> new POIFSFileSystem(out.toInputStream())); } @@ -92,7 +92,7 @@ final class TestEmptyDocument { void testEmptyDocumentBug11744() throws Exception { byte[] testData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); try (POIFSFileSystem fs = new POIFSFileSystem()) { fs.createDocument(new ByteArrayInputStream(new byte[0]), "Empty"); fs.createDocument(new ByteArrayInputStream(testData), "NotEmpty"); diff --git a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEntryUtils.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEntryUtils.java index e2abb090ab..16fa1fd240 100644 --- a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEntryUtils.java +++ b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEntryUtils.java @@ -125,7 +125,7 @@ class TestEntryUtils { // Can work with POIFS - try (UnsynchronizedByteArrayOutputStream tmpO = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream tmpO = UnsynchronizedByteArrayOutputStream.builder().get()) { fs.writeFilesystem(tmpO); try (InputStream tmpI = tmpO.toInputStream(); diff --git a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java index dd52a10a58..a162dd8346 100644 --- a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java +++ b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java @@ -140,7 +140,7 @@ final class TestFileSystemBugs { EntryUtils.copyNodes(root, dest); // Re-load - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); root.getFileSystem().writeFilesystem(baos); POIFSFileSystem read = new POIFSFileSystem(baos.toInputStream()); diff --git a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestOle10Native.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestOle10Native.java index 3a3f2fa8dc..7a39eb4779 100644 --- a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestOle10Native.java +++ b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestOle10Native.java @@ -67,14 +67,14 @@ class TestOle10Native { findOle10(entries, fs.getRoot(), "/"); for (Entry e : entries) { - UnsynchronizedByteArrayOutputStream bosExp = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bosExp = UnsynchronizedByteArrayOutputStream.builder().get(); try (InputStream is = ((DirectoryNode) e.getParent()).createDocumentInputStream(e)) { IOUtils.copy(is, bosExp); } Ole10Native ole = Ole10Native.createFromEmbeddedOleObject((DirectoryNode) e.getParent()); - UnsynchronizedByteArrayOutputStream bosAct = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bosAct = UnsynchronizedByteArrayOutputStream.builder().get(); ole.writeOut(bosAct); assertThat(bosExp.toByteArray(), equalTo(bosAct.toByteArray())); diff --git a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java index 886340091c..c7135da492 100644 --- a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java +++ b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java @@ -142,7 +142,7 @@ final class TestPOIFSFileSystem { try (POIFSFileSystem fs = new POIFSFileSystem(_samples.openResourceAsStream(file))) { // Write it into a temp output array - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); fs.writeFilesystem(baos); // Check sizes @@ -181,7 +181,7 @@ final class TestPOIFSFileSystem { "BIG", new ByteArrayInputStream(hugeStream) ); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); fs.writeFilesystem(baos); byte[] fsData = baos.toByteArray(); diff --git a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java index 430cd8e5d2..4efcc80983 100644 --- a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java +++ b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java @@ -1190,7 +1190,7 @@ final class TestPOIFSStream { } private static HeaderBlock writeOutAndReadHeader(POIFSFileSystem fs) throws IOException { - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); fs.writeFilesystem(baos); return new HeaderBlock(baos.toInputStream()); } diff --git a/poi/src/test/java/org/apache/poi/poifs/property/TestDirectoryProperty.java b/poi/src/test/java/org/apache/poi/poifs/property/TestDirectoryProperty.java index c200bbdee0..b503472db7 100644 --- a/poi/src/test/java/org/apache/poi/poifs/property/TestDirectoryProperty.java +++ b/poi/src/test/java/org/apache/poi/poifs/property/TestDirectoryProperty.java @@ -188,7 +188,7 @@ final class TestDirectoryProperty { } private void verifyProperty() throws IOException { - UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(512); + UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(512).get(); _property.writeData(stream); byte[] output = stream.toByteArray(); @@ -254,7 +254,7 @@ final class TestDirectoryProperty { private static void verifyReadingProperty(int index, byte[] input, int offset, String name) { DirectoryProperty property = new DirectoryProperty(index, input, offset); - UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(128); + UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(128).get(); byte[] expected = Arrays.copyOfRange(input, offset, offset+128); try { property.writeData(stream); diff --git a/poi/src/test/java/org/apache/poi/poifs/property/TestDocumentProperty.java b/poi/src/test/java/org/apache/poi/poifs/property/TestDocumentProperty.java index 1bda3ab462..c72f0bdbfa 100644 --- a/poi/src/test/java/org/apache/poi/poifs/property/TestDocumentProperty.java +++ b/poi/src/test/java/org/apache/poi/poifs/property/TestDocumentProperty.java @@ -83,7 +83,7 @@ final class TestDocumentProperty { throws IOException { DocumentProperty property = new DocumentProperty(index, input, offset); - UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(128); + UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(128).get(); byte[] expected = Arrays.copyOfRange(input, offset, offset+128); property.writeData(stream); byte[] output = stream.toByteArray(); @@ -145,7 +145,7 @@ final class TestDocumentProperty { { testblock[ index * 2 ] = name_bytes[ index ]; } - UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(512); + UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(512).get(); property.writeData(stream); byte[] output = stream.toByteArray(); diff --git a/poi/src/test/java/org/apache/poi/poifs/property/TestPropertyTable.java b/poi/src/test/java/org/apache/poi/poifs/property/TestPropertyTable.java index 64577b0c7c..b79a002f69 100644 --- a/poi/src/test/java/org/apache/poi/poifs/property/TestPropertyTable.java +++ b/poi/src/test/java/org/apache/poi/poifs/property/TestPropertyTable.java @@ -45,7 +45,7 @@ import org.junit.jupiter.api.Test; final class TestPropertyTable { private static void confirmBlockEncoding(String expectedDataStr, PropertyTable table) throws IOException { - final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); byte[] expectedData = RawDataUtil.decompress(expectedDataStr); POIFSStream stream = new POIFSStream(null) { diff --git a/poi/src/test/java/org/apache/poi/poifs/property/TestRootProperty.java b/poi/src/test/java/org/apache/poi/poifs/property/TestRootProperty.java index a210ac8d7c..3ab7e67561 100644 --- a/poi/src/test/java/org/apache/poi/poifs/property/TestRootProperty.java +++ b/poi/src/test/java/org/apache/poi/poifs/property/TestRootProperty.java @@ -42,7 +42,7 @@ final class TestRootProperty { void testConstructor() throws IOException { createBasicRootProperty(); - UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(512); + UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(512).get(); _property.writeData(stream); assertArrayEquals(_testblock, stream.toByteArray()); @@ -105,7 +105,7 @@ final class TestRootProperty { int offset = 0; RootProperty property = new RootProperty(index, input, offset); - UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(128); + UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(128).get(); byte[] expected = Arrays.copyOfRange(input, offset, offset+128); property.writeData(stream); byte[] output = stream.toByteArray(); diff --git a/poi/src/test/java/org/apache/poi/poifs/storage/RawDataUtil.java b/poi/src/test/java/org/apache/poi/poifs/storage/RawDataUtil.java index af7ec4eaa1..7382c65778 100644 --- a/poi/src/test/java/org/apache/poi/poifs/storage/RawDataUtil.java +++ b/poi/src/test/java/org/apache/poi/poifs/storage/RawDataUtil.java @@ -37,7 +37,7 @@ public final class RawDataUtil { public static byte[] decode(String[] hexDataLines) { try (UnsynchronizedByteArrayOutputStream baos = - new UnsynchronizedByteArrayOutputStream(hexDataLines.length * 32 + 32)) { + UnsynchronizedByteArrayOutputStream.builder().setBufferSize(hexDataLines.length * 32 + 32).get()) { for (String hexDataLine : hexDataLines) { byte[] lineData = HexRead.readFromString(hexDataLine); baos.write(lineData, 0, lineData.length); @@ -58,7 +58,7 @@ public final class RawDataUtil { public static byte[] decompress(String data) throws IOException { byte[] base64Bytes = Base64.getDecoder().decode(data); try ( - InputStream is = new UnsynchronizedByteArrayInputStream(base64Bytes); + InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(base64Bytes).get(); GZIPInputStream gzis = new GZIPInputStream(is); ) { return IOUtils.toByteArray(gzis); @@ -74,7 +74,7 @@ public final class RawDataUtil { */ public static String compress(byte[] data) throws IOException { try ( - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); java.util.zip.GZIPOutputStream gz = new java.util.zip.GZIPOutputStream(bos) ) { gz.write(data); diff --git a/poi/src/test/java/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java b/poi/src/test/java/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java index 02d84fac03..3073189952 100644 --- a/poi/src/test/java/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java +++ b/poi/src/test/java/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java @@ -133,7 +133,7 @@ public abstract class BaseTestSlideShowFactory { } private static byte[] readExternalFile(String path) { - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); try (InputStream fis = new FileInputStream(path)) { byte[] buf = new byte[512]; diff --git a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java index 94db023cc1..ebcdb5baf2 100644 --- a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java +++ b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java @@ -1815,8 +1815,8 @@ public abstract class BaseTestBugzillaIssues { cell.setCellValue("Ernie & Bert are cool!"); cell.setCellFormula("A1 & \" are cool!\""); - try (UnsynchronizedByteArrayOutputStream out1 = new UnsynchronizedByteArrayOutputStream(); - UnsynchronizedByteArrayOutputStream out2 = new UnsynchronizedByteArrayOutputStream()) { + try (UnsynchronizedByteArrayOutputStream out1 = UnsynchronizedByteArrayOutputStream.builder().get(); + UnsynchronizedByteArrayOutputStream out2 = UnsynchronizedByteArrayOutputStream.builder().get()) { wb.write(out1); wb.write(out2); diff --git a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestPicture.java b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestPicture.java index af3c773d00..8502bbfcd1 100644 --- a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestPicture.java +++ b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestPicture.java @@ -272,7 +272,7 @@ public abstract class BaseTestPicture { g.draw(ell); g.dispose(); - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(2000); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(2000).get(); ImageIO.write(bi, "PNG", bos); return bos.toByteArray(); } diff --git a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestWorkbook.java b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestWorkbook.java index 349e5427fc..0dc0bafbf6 100644 --- a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestWorkbook.java +++ b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestWorkbook.java @@ -17,7 +17,6 @@ package org.apache.poi.ss.usermodel; -import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -33,6 +32,7 @@ import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.Spliterator; +import org.apache.commons.io.output.NullOutputStream; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType; @@ -784,7 +784,7 @@ public abstract class BaseTestWorkbook { c.setCellStyle(cs); c.setCellValue("AAA"); } - assertDoesNotThrow(() -> workbook.write(NULL_OUTPUT_STREAM)); + assertDoesNotThrow(() -> workbook.write(NullOutputStream.INSTANCE)); } } diff --git a/poi/src/test/java/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java b/poi/src/test/java/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java index 62b83ffaf9..d80d23990c 100644 --- a/poi/src/test/java/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java +++ b/poi/src/test/java/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java @@ -150,7 +150,7 @@ public class NumberRenderingSpreadsheetGenerator { File outputFile = new File("ExcelNumberRendering.xls"); - try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); FileOutputStream os = new FileOutputStream(outputFile)) { wb.write(baos); @@ -212,7 +212,7 @@ public class NumberRenderingSpreadsheetGenerator { } private static String interpretLong(byte[] fileContent, int offset) { - try (InputStream is = new UnsynchronizedByteArrayInputStream(fileContent, offset, 8)) { + try (InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(fileContent).setOffset(offset).setLength(8).get()) { long l = new DataInputStream(is).readLong(); return "0x" + Long.toHexString(l).toUpperCase(Locale.ROOT); } catch (IOException e) { diff --git a/poi/src/test/java/org/apache/poi/ss/util/TestCellRangeAddress.java b/poi/src/test/java/org/apache/poi/ss/util/TestCellRangeAddress.java index 4d729d6006..321e67fe77 100644 --- a/poi/src/test/java/org/apache/poi/ss/util/TestCellRangeAddress.java +++ b/poi/src/test/java/org/apache/poi/ss/util/TestCellRangeAddress.java @@ -67,7 +67,7 @@ final class TestCellRangeAddress { CellRangeAddress ref = new CellRangeAddress(0, 0, 0, 0); byte[] recordBytes; - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); try (LittleEndianOutputStream out = new LittleEndianOutputStream(baos)) { // With nothing set ref.serialize(out); diff --git a/poi/src/test/java/org/apache/poi/ss/util/TestDateFormatConverter.java b/poi/src/test/java/org/apache/poi/ss/util/TestDateFormatConverter.java index 0faf865e5a..059426289e 100644 --- a/poi/src/test/java/org/apache/poi/ss/util/TestDateFormatConverter.java +++ b/poi/src/test/java/org/apache/poi/ss/util/TestDateFormatConverter.java @@ -22,7 +22,6 @@ package org.apache.poi.ss.util; import static java.text.DateFormat.getDateInstance; import static java.text.DateFormat.getDateTimeInstance; import static java.text.DateFormat.getTimeInstance; -import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM; import static org.apache.poi.ss.util.DateFormatConverter.getPrefixForLocale; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -43,6 +42,7 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; +import org.apache.commons.io.output.NullOutputStream; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; @@ -122,7 +122,7 @@ final class TestDateFormatConverter { cell[6].setCellValue(excelFormatPattern); } - assertDoesNotThrow(() -> workbook.write(NULL_OUTPUT_STREAM)); + assertDoesNotThrow(() -> workbook.write(NullOutputStream.INSTANCE)); } } diff --git a/poi/src/test/java/org/apache/poi/util/TestHexDump.java b/poi/src/test/java/org/apache/poi/util/TestHexDump.java index 16b1b334d5..5864041706 100644 --- a/poi/src/test/java/org/apache/poi/util/TestHexDump.java +++ b/poi/src/test/java/org/apache/poi/util/TestHexDump.java @@ -41,7 +41,7 @@ class TestHexDump { @BeforeAll public static void setUp() throws UnsupportedEncodingException { SYSTEM_OUT = System.out; - System.setOut(new NullPrintStream()); + System.setOut(NullPrintStream.INSTANCE); } @AfterAll @@ -52,7 +52,7 @@ class TestHexDump { @Test void testDump() throws IOException { byte[] testArray = testArray(); - UnsynchronizedByteArrayOutputStream streamAct = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream streamAct = UnsynchronizedByteArrayOutputStream.builder().get(); HexDump.dump(testArray, 0, streamAct, 0); byte[] bytesAct = streamAct.toByteArray(); byte[] bytesExp = toHexDump(0, 0); diff --git a/poi/src/test/java/org/apache/poi/util/TestIOUtils.java b/poi/src/test/java/org/apache/poi/util/TestIOUtils.java index 481afd28be..bb12f9932e 100644 --- a/poi/src/test/java/org/apache/poi/util/TestIOUtils.java +++ b/poi/src/test/java/org/apache/poi/util/TestIOUtils.java @@ -229,7 +229,7 @@ final class TestIOUtils { @Test void testSkipFullyByteArray() throws IOException { - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); try (InputStream is = new FileInputStream(TMP)) { assertEquals(LENGTH, IOUtils.copy(is, bos)); long skipped = IOUtils.skipFully(bos.toInputStream(), 20000L); @@ -239,7 +239,7 @@ final class TestIOUtils { @Test void testSkipFullyByteArrayGtIntMax() throws IOException { - UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get(); try (InputStream is = new FileInputStream(TMP)) { assertEquals(LENGTH, IOUtils.copy(is, bos)); long skipped = IOUtils.skipFully(bos.toInputStream(), Integer.MAX_VALUE + 20000L); diff --git a/poi/src/test/java/org/apache/poi/util/TestLittleEndianInputStream.java b/poi/src/test/java/org/apache/poi/util/TestLittleEndianInputStream.java index d7b9ad7b5f..00240378dc 100644 --- a/poi/src/test/java/org/apache/poi/util/TestLittleEndianInputStream.java +++ b/poi/src/test/java/org/apache/poi/util/TestLittleEndianInputStream.java @@ -34,7 +34,7 @@ class TestLittleEndianInputStream { assertEquals(4, fr.getCharacterPos()); assertEquals(0x15c, fr.getFontIndex()); - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); LittleEndianOutputStream out = new LittleEndianOutputStream(baos); fr.serialize(out); diff --git a/poi/src/test/java/org/apache/poi/util/TestLittleEndianStreams.java b/poi/src/test/java/org/apache/poi/util/TestLittleEndianStreams.java index d1c58f9278..8f505f793c 100644 --- a/poi/src/test/java/org/apache/poi/util/TestLittleEndianStreams.java +++ b/poi/src/test/java/org/apache/poi/util/TestLittleEndianStreams.java @@ -35,7 +35,7 @@ final class TestLittleEndianStreams { @Test void testRead() throws IOException { - UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get(); try (LittleEndianOutputStream leo = new LittleEndianOutputStream(baos)) { leo.writeInt(12345678); leo.writeShort(12345); diff --git a/poi/src/test/java/org/apache/poi/util/TestRLEDecompressingInputStream.java b/poi/src/test/java/org/apache/poi/util/TestRLEDecompressingInputStream.java index 0c8fad889e..3d63d930f3 100644 --- a/poi/src/test/java/org/apache/poi/util/TestRLEDecompressingInputStream.java +++ b/poi/src/test/java/org/apache/poi/util/TestRLEDecompressingInputStream.java @@ -148,7 +148,7 @@ class TestRLEDecompressingInputStream { private static void checkRLEDecompression(String expected, byte[] runLengthEncodedData) throws IOException { InputStream compressedStream = new ByteArrayInputStream(runLengthEncodedData); - UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get(); try (InputStream stream = new RLEDecompressingInputStream(compressedStream)) { IOUtils.copy(stream, out); } |