]> source.dussan.org Git - poi.git/commitdiff
Remove deprecation warnings reported with newer commons-io
authorDominik Stadler <centic@apache.org>
Thu, 8 Jun 2023 08:53:08 +0000 (08:53 +0000)
committerDominik Stadler <centic@apache.org>
Thu, 8 Jun 2023 08:53:08 +0000 (08:53 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1910300 13f79535-47bb-0310-9956-ffa450edef68

246 files changed:
osgi/src/test/java/org/apache/poi/osgi/OSGiExtractorsIT.java
osgi/src/test/java/org/apache/poi/osgi/OSGiSlideShowIT.java
osgi/src/test/java/org/apache/poi/osgi/OSGiSpreadsheetIT.java
poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/OfficeDrawing.java
poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/CustomXMLMapping.java
poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java
poi-integration/src/test/java/org/apache/poi/stress/POIFSFileHandler.java
poi-integration/src/test/java/org/apache/poi/stress/SlideShowHandler.java
poi-integration/src/test/java/org/apache/poi/stress/SpreadsheetHandler.java
poi-integration/src/test/java/org/apache/poi/stress/XSSFBFileHandler.java
poi-integration/src/test/java/org/apache/poi/stress/XSSFFileHandler.java
poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/MemoryPackagePart.java
poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/MemoryPackagePartOutputStream.java
poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipArchiveFakeEntry.java
poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/DigestOutputStream.java
poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/OOXMLURIDereferencer.java
poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/SignatureLine.java
poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java
poi-ooxml/src/main/java/org/apache/poi/xslf/draw/SVGImageRenderer.java
poi-ooxml/src/main/java/org/apache/poi/xslf/draw/SVGRenderExtension.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFMetroShape.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
poi-ooxml/src/main/java/org/apache/poi/xslf/util/DummyFormat.java
poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFBuiltinTableStyle.java
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFChartSheet.java
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
poi-ooxml/src/test/java/org/apache/poi/ooxml/TestPOIXMLDocument.java
poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackage.java
poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java
poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestRelationships.java
poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/ZipFileAssert.java
poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java
poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/internal/marshallers/TestZipPackagePropertiesMarshaller.java
poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/DummyKeystore.java
poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java
poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestAgileEncryptionParameters.java
poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestDecryptor.java
poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestEncryptor.java
poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java
poi-ooxml/src/test/java/org/apache/poi/sl/tests/TestOleShape.java
poi-ooxml/src/test/java/org/apache/poi/sl/tests/TestSlide.java
poi-ooxml/src/test/java/org/apache/poi/sl/tests/TestTable.java
poi-ooxml/src/test/java/org/apache/poi/ss/tests/usermodel/TestEmbedOLEPackage.java
poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFBugs.java
poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideCopy.java
poi-ooxml/src/test/java/org/apache/poi/xslf/XSLFTestDataSamples.java
poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFShape.java
poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java
poi-ooxml/src/test/java/org/apache/poi/xssf/DeferredSXSSFITestDataProvider.java
poi-ooxml/src/test/java/org/apache/poi/xssf/SXSSFITestDataProvider.java
poi-ooxml/src/test/java/org/apache/poi/xssf/TestSSUtilVsXSSFColor.java
poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFMemoryLeak.java
poi-ooxml/src/test/java/org/apache/poi/xssf/XSSFTestDataSamples.java
poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java
poi-ooxml/src/test/java/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java
poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/OpcZipTest.java
poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFSheet.java
poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java
poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java
poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithNullAutoSizeTracker.java
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFComment.java
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/charts/TestXSSFBubbleChartData.java
poi-ooxml/src/test/java/org/apache/poi/xssf/util/TestEvilUnclosedBRFixingInputStream.java
poi-ooxml/src/test/java/org/apache/poi/xwpf/XWPFTestDataSamples.java
poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestChangeTracking.java
poi-scratchpad/src/main/java/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java
poi-scratchpad/src/main/java/org/apache/poi/hdgf/HDGFLZW.java
poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/CompressedStreamStore.java
poi-scratchpad/src/main/java/org/apache/poi/hemf/draw/HemfImageRenderer.java
poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfFill.java
poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java
poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java
poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java
poi-scratchpad/src/main/java/org/apache/poi/hmef/attribute/MAPIAttribute.java
poi-scratchpad/src/main/java/org/apache/poi/hmef/attribute/MAPIRtfAttribute.java
poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/HPBFPart.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/Bitmap.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/EMF.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/Metafile.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/PICT.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/WMF.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideIdListing.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideShowRecordDumper.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/UserEditAndPersistListing.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/model/textproperties/TextPropCollection.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ColorSchemeAtom.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/record/CurrentUserAtom.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/record/EscherTextboxWrapper.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExOleObjStg.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/record/HSLFEscherClientDataRecord.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PPDrawingGroup.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/record/RecordContainer.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/record/StyleTextPropAtom.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextRulerAtom.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextSpecInfoAtom.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TxMasterStyleAtom.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/PropertiesChunk.java
poi-scratchpad/src/main/java/org/apache/poi/hwmf/usermodel/HwmfEmbeddedIterator.java
poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java
poi-scratchpad/src/main/java/org/apache/poi/hwpf/usermodel/Picture.java
poi-scratchpad/src/test/java/org/apache/poi/hdgf/dev/TestVSDDumper.java
poi-scratchpad/src/test/java/org/apache/poi/hemf/usermodel/TestHemfPicture.java
poi-scratchpad/src/test/java/org/apache/poi/hmef/TestHMEFMessage.java
poi-scratchpad/src/test/java/org/apache/poi/hmef/dev/TestHMEFDumper.java
poi-scratchpad/src/test/java/org/apache/poi/hmef/extractor/TestHMEFContentsExtractor.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/HSLFTestDataSamples.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWrite.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWriteSanity.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/BaseTestPPTIterating.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/TestSLWTListing.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestMovieShape.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestOleEmbedding.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestAnimationInfoAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestCString.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestColorSchemeAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestComment2000.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestComment2000Atom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestCurrentUserAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestDocumentAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestDocumentEncryption.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExControl.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExHyperlink.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExHyperlinkAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExMediaAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExObjListAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjStg.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExVideoContainer.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestFontCollection.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestHeadersFootersAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestHeadersFootersContainer.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestInteractiveInfo.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestInteractiveInfoAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestNotesAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestSlideAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestSlidePersistAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestStyleTextPropAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextBytesAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextCharsAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextHeaderAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextRulerAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextSpecInfoAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTxInteractiveInfoAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestUserEditAtom.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestPictures.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestRichTextRun.java
poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestExtractEmbeddedMSG.java
poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java
poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFixedSizedProperties.java
poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestCase.java
poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestDataSamples.java
poi-scratchpad/src/test/java/org/apache/poi/hwpf/dev/TestHWPFLister.java
poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestHWPFWrite.java
poi/src/main/java/org/apache/poi/POIDocument.java
poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java
poi/src/main/java/org/apache/poi/hpsf/Property.java
poi/src/main/java/org/apache/poi/hpsf/PropertySet.java
poi/src/main/java/org/apache/poi/hpsf/Section.java
poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java
poi/src/main/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java
poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java
poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java
poi/src/main/java/org/apache/poi/hssf/record/FilePassRecord.java
poi/src/main/java/org/apache/poi/hssf/record/Record.java
poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java
poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java
poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPicture.java
poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
poi/src/main/java/org/apache/poi/poifs/filesystem/DocumentOutputStream.java
poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java
poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java
poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java
poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java
poi/src/main/java/org/apache/poi/sl/image/ImageHeaderBitmap.java
poi/src/main/java/org/apache/poi/sl/usermodel/ObjectShape.java
poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java
poi/src/main/java/org/apache/poi/ss/util/ImageUtils.java
poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java
poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java
poi/src/main/java/org/apache/poi/util/IOUtils.java
poi/src/main/java/org/apache/poi/util/LZWDecompresser.java
poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java
poi/src/test/java/org/apache/poi/POIDataSamples.java
poi/src/test/java/org/apache/poi/TestPOIDocumentMain.java
poi/src/test/java/org/apache/poi/ddf/TestEscherDump.java
poi/src/test/java/org/apache/poi/hpsf/basic/TestHPSFBugs.java
poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java
poi/src/test/java/org/apache/poi/hpsf/basic/TestReadAllFiles.java
poi/src/test/java/org/apache/poi/hpsf/basic/TestWrite.java
poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java
poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java
poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java
poi/src/test/java/org/apache/poi/hssf/model/TestEscherRecordFactory.java
poi/src/test/java/org/apache/poi/hssf/record/TestDConRefRecord.java
poi/src/test/java/org/apache/poi/hssf/record/TestDrawingRecord.java
poi/src/test/java/org/apache/poi/hssf/record/TestLbsDataSubRecord.java
poi/src/test/java/org/apache/poi/hssf/record/TestRecordFactory.java
poi/src/test/java/org/apache/poi/hssf/record/TestSSTRecord.java
poi/src/test/java/org/apache/poi/hssf/record/common/TestUnicodeString.java
poi/src/test/java/org/apache/poi/hssf/usermodel/TestBugs.java
poi/src/test/java/org/apache/poi/hssf/usermodel/TestDataValidation.java
poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFCell.java
poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
poi/src/test/java/org/apache/poi/hssf/usermodel/TestOLE2Embedding.java
poi/src/test/java/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java
poi/src/test/java/org/apache/poi/poifs/crypt/agile/TestAgileDecryptor.java
poi/src/test/java/org/apache/poi/poifs/dev/TestPOIFSDump.java
poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocument.java
poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java
poi/src/test/java/org/apache/poi/poifs/filesystem/TestEmptyDocument.java
poi/src/test/java/org/apache/poi/poifs/filesystem/TestEntryUtils.java
poi/src/test/java/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java
poi/src/test/java/org/apache/poi/poifs/filesystem/TestOle10Native.java
poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java
poi/src/test/java/org/apache/poi/poifs/property/TestDirectoryProperty.java
poi/src/test/java/org/apache/poi/poifs/property/TestDocumentProperty.java
poi/src/test/java/org/apache/poi/poifs/property/TestPropertyTable.java
poi/src/test/java/org/apache/poi/poifs/property/TestRootProperty.java
poi/src/test/java/org/apache/poi/poifs/storage/RawDataUtil.java
poi/src/test/java/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java
poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestPicture.java
poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
poi/src/test/java/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java
poi/src/test/java/org/apache/poi/ss/util/TestCellRangeAddress.java
poi/src/test/java/org/apache/poi/ss/util/TestDateFormatConverter.java
poi/src/test/java/org/apache/poi/util/TestHexDump.java
poi/src/test/java/org/apache/poi/util/TestIOUtils.java
poi/src/test/java/org/apache/poi/util/TestLittleEndianInputStream.java
poi/src/test/java/org/apache/poi/util/TestLittleEndianStreams.java
poi/src/test/java/org/apache/poi/util/TestRLEDecompressingInputStream.java

index 3bf58a2b610d0046c5b6e74d30e3b2ded043aec2..0196bfb6f077e56d76724b392f38db23704669a3 100755 (executable)
@@ -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();
 
index 9744c36ca975f0fcc82fdc25ffb83c14eca00242..3e4ebdf96e71d4d19955aee9545a5dfdc11739ce 100755 (executable)
@@ -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);
index 618b76e36c90a211a7cf5560892d6f26b00e3f09..7793754bcae51b29818936c5c8dae63552ef6518 100644 (file)
@@ -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);
index 2cefd3d87f96e7eb8c8bc7cabab65af6472ee010..c3a5b8c4002945bb5e38a4105179c97e924c3db0 100644 (file)
@@ -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);
         }
index edba46bba38f521c6bf2424403e30a505a41b4e5..e1a912e734fa260062c5d84fe287a488e32b4434 100644 (file)
@@ -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);
index a9bed390084164a36a77d5c4e0e6617eee411f96..b172b38295a3f99edcee127c2afdb46026292d11 100644 (file)
@@ -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.
index 5dd01bdff5fba1774450034e290d518e75c698b6..14b26c395d142d607db2856691926cb335ec2cd5 100644 (file)
@@ -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();
index ec291e1c0bec348ab1f6f247517b4d0b7d4e9be7..305793cd1e7e5342f68b0acbb2fea551c8df471f 100644 (file)
@@ -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);
index 50212654c91ed32f0bbbaee881b36074f5369635..1e57bb856a8784b085f6963afb8b814aaea7feb8 100644 (file)
@@ -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;
     }
index f60752d6ddbdfd9e6fdbe53973c55e4a2bad6bfa..fb130b9d72b81882805954883d612b2c503a8d4f 100644 (file)
@@ -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 {
index 314d5ed985c6512e1a773b85c24fe6113baef750..160d7059a2aba5f720c441f542f880995c50166f 100644 (file)
@@ -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);
         }
     }
 
index dd53be0ea986ee65057227d5f6acef6846fbeb84..9096b69457d49f4ece0ae189af5d14e69c6c0c8e 100644 (file)
@@ -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
index 071718021b49a3787cc2aea8af835dbdd1e2d17e..3b146103c4b9f8c2dc5d97f0d22e18ae77b4d6e9 100644 (file)
@@ -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
index 34b28ab66296f30fed35f503a93f50f68b7b3ffa..7a74f0747297247503458ab65a60def490aacf09 100644 (file)
@@ -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.");
         }
index baf8e0a21586a2df4e03385a4e8bf95d60200d89..bf49df547d75d225359be8048e4e08565ad9127a 100644 (file)
@@ -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);
index c4c988b4de2ef495cb8ad0b10ab00899a171157c..01c05652bd26caa5a78d1b83d98ef7d9d7fbfb76 100644 (file)
@@ -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);
index 54964d1decd08268118c11a2aa3ee0c60655d83d..060ab3b12c6ad5b719e043dc535c8ed46de0e2b0 100644 (file)
@@ -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();
     }
index a9d0a4171e091b756c5b6775605b230c7027fde7..7e5bbcf5ac2e234aaffe65d2661f76aca6ea5f23 100644 (file)
@@ -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
index 1e16483ea97307d6d6283d3ccb31359baf2c85bb..2bd46c4876a70edfcadf1e5327736219fccd3383 100644 (file)
@@ -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
index 8e2bb21aed1cc2bc7792e6efeef4701659b93cb2..7f787629963c917b05ba5ae03ee4111f8153e70e 100644 (file)
@@ -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) {
index c01b9ff3de0c77ab661b6f320ec47e78d2581779..cdb9d0e4af8adffc66ad1bce25366ba4e555862b 100644 (file)
@@ -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) {
index 53727ef5e8a61bfa4e5d62dfc086e0359b315eb3..b7e2bb54967dcee539489cb2ffa65965d085cc9c 100644 (file)
@@ -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);
 
index b090c34cc347bf41e7244c3e9f06e7b6f81dd6ab..0a995ed4980d1aa0f1be1afc1270f6150380e117 100644 (file)
@@ -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);
index 38feae68e91dfee757c0f0ca9c72cf7815f28e1b..eccbc02e225fcc9918ff5c8a9c157b2cb418edf8 100644 (file)
@@ -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
index 63ef92a7075f019d09713c22efd59a0aa8690ba1..b650380e88893de13220c8f8db160524ccdf2bb3 100644 (file)
@@ -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)));
index 6f0b5e11694ad163bce880de4e51d0054206a064..aeb7874a6c3929cdf4a8296675bf9c6c4ce07d30 100644 (file)
@@ -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){
index c15b21ebf66f433a046554091dae129cfd064c5d..cc7284e04b01073ce277d940766ed892c999112e 100644 (file)
@@ -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()) {
index 0e2d09dc918d338045d3c83c3d09365b8bad7760..ee285455f45f459380e59aab4f3c60bc3e58aec9 100644 (file)
@@ -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
index 80f18926a9a2b5166efb99d6893d8c298ac632b5..cc22c41ca98968b1f0c47421c3a21e52d0568971 100644 (file)
@@ -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());
 
index c52135d5c5a041bf4a277097f5696b00504821f2..d0d0514a80dc8ab45f06d71bf45acc296b6179a1 100644 (file)
@@ -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)) {
index 6ef0bab8f417fd9ef8e3515c381c81fad1a858fc..5979190252a3821ce0a288ff276c432febc62554 100644 (file)
@@ -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();
index 7fd655d4a1bd39db21896b27a6582ce683ab0fee..ce63f811a807e594b88192d27016520be939c9b5 100644 (file)
@@ -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())) {
index a22ad42d197a37083f96b4b049da2a11b4cc71b6..ea49804eadbc8766c62bcf2d1b4f5908a61f9027 100644 (file)
@@ -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);
             }
index b079f00bf3224f6d0089f1c9b399630225ba6ff6..2079cbd9e13459736b4e76f812fd9663a8a65b36 100644 (file)
@@ -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
index 40345a029ad7a704119d9c1d3074ceb7897cd986..09ebcb20c21911fcd28843c6751d7e6fdeff47b7 100644 (file)
@@ -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");
index 10eaa22f38a3b4dda92e2164bac5955bbffeb39e..3ad3dcfbe86dc43f3a54216323e420d63fce77e9 100644 (file)
@@ -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());
         }
     }
index 2566f16388f080d82ecb1d41b616f952810a4567..932195193eaa5c874737402cec74ad2d6151dfbc 100644 (file)
@@ -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);
index e0ad0febea79891c4bd786951333d3841c6460db..e4baf2b75cfacf47152399276aa9a649017e6047 100644 (file)
@@ -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();
index 94392f00c4e5ead78babe057aaee6724c769a8b0..c6d10af2b72ba88a5f6ea1f35ce77a7abde9e866 100644 (file)
@@ -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) {
index 5e106b4202f6bd625dd8fb5d0944b31cfb4ea377..f531631e38faf5be07902c6dc72ce32dd6747077 100644 (file)
@@ -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);
             }
         }
 
index d51ac67e3bccb4b755e054c62450bcd50609a3e7..518d44fda617428d767a353ccd13f9b729dd17ae 100644 (file)
@@ -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");
index 8352e0061c16ff59967b799ee48b9b2bf7339e8b..7370bd9c2c1fbc14082ae7970d9bd4c4d290f11a 100644 (file)
@@ -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();
index 06c358a459f633a5fe1c0ac2fd15a7b864b860a9..49acd8d9129c49cfedd0c4d0511a810bd047555f 100644 (file)
@@ -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();
index ccd6d86aa551c5ae780c04ce8ddff771de268056..2f5b9c13351078a91eae4113dc209901797c8f23 100644 (file)
@@ -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())) {
index ca832891517cb4e87b886f35efd883339977bd0d..ea7067a1493a5f5a3f6c022a5956941240f93673 100644 (file)
@@ -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();
 
index 0ff51a9d17b162302ce1088bfd2e8978926f5f75..8d7a37dd7ac794dd17bfb561afc4ff801598daeb 100644 (file)
@@ -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) {
index 7e198d40b6e9fb5c5a9aab08e44da782a45140bc..135bf5f833d40dc198eaa74a19e2007abf430ae6 100644 (file)
@@ -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;
index 0c531ccd48f09a0865c7b05dd62517411fe9ce30..1f78e24adf15e5af53c1c298f19a7091b65d73a9 100644 (file)
@@ -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);
index 5e479e83c7dd7e44cf31d9b924a5ab22eec1f286..5b6a7229f83acc05dba019dcf55d3bf118c15ad3 100644 (file)
@@ -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);
index 5d73bdf1a4c127e0503e516e287873feb5c9ecf7..f6c5570003c5be65e750fecc5c2f70762b97f8f6 100644 (file)
@@ -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
index c915390dc220ebb596cf5aa6be174d58e1ef98e6..59c1322fc63e80b07a152ff299cf36c94f492d5b 100644 (file)
@@ -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);
index c43a9cb38cd70ec43d22c4f8b42eb439e707856e..1b9d291aa6dd8a0d287cf83500d5f724ee12161d 100644 (file)
@@ -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);
index 0aaceecd61088ad67e25391a230ae34eb629051a..1a0b577281910833814bf8d3ea729c34356767ef 100644 (file)
@@ -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";
index 3b35c52ac9ae6e49a78ea1be033a48ffd0898e37..16ca608c0d4bcabc12e836a6311f1031001988f8 100644 (file)
@@ -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);
             }
 
index 30cb09a09aaedf996c421b35e2a059f11f159732..882ac230780e13b5c22201131c4bf074926c99f7 100644 (file)
@@ -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;
     }
index 96565866fbb15b71534b238be68811df0131553d..8dd8a70e2385c6efe97de82c94683fd809d6d238 100644 (file)
@@ -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 */
index 66c7ae39e54941b594595f0f980824f04db2b005..8fbd2ad53586e68696796e651a8fe77d48a05118 100644 (file)
@@ -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));
             }
         }
index f0339a9165607eb2cfe2bba7d9d859cd4e4d1e5f..1fe25dcf0949caaec964553276ec86d2f49464ce 100644 (file)
@@ -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()) {
index 41df3b3384369b38da74027d285aeb2db9d2771d..015f608cf2b6214dd6cef95cb8b2d15364cb8727 100644 (file)
@@ -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);
index c0011da4e203d3519410fe7a7c671aee80fabae7..6af454252551267edd73c4a6892b09c604cce5c4 100644 (file)
@@ -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);
index d5afe8ea15e3dae4021f4a78e55b09d790cd7984..d89ffbb2b3baec859c1734f6b9479efde2d5d6a3 100644 (file)
@@ -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());
index 1b2352b29d44b85b11ec592739f58bf2759d2ba2..797ed4acc219d3cd288c4237ad64ec2c71c38f7e 100644 (file)
@@ -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();
index 1c3690f1017ac1cb19e6da42a47df83ea7ca9c04..c269b7c913f192143d0db469a535ff0d43ef36b1 100644 (file)
@@ -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);
index 0b307277f55c414f926841081d4d019284ba50d0..9b26f2e0aa8eeb0314357898536c89607130e0f9 100644 (file)
@@ -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
index a9240a6f0a44a27af9aac5a9962c45e87a25f6bd..7b735206d44ab77ae17390e20c56e7742901aff8 100644 (file)
@@ -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)) {
index 8a5a17ce2c113140e25311656b983a7adedfa7b7..a5e07eb5f35255de4e737d3461a06c1e78fd5770 100644 (file)
@@ -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);
index 88f903179d4d974ab6b00d8d44f0582208179906..9504b20ac809f66512f060ae18d1843a98c01f2c 100644 (file)
@@ -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());
index 2e3d1ec76e8596f5de3aa57b1e2e2474629c4177..8cdf4706f354e96a3bdbc7594a9014e7550c9487 100644 (file)
@@ -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);
index 4ee8a83d3cd62e3e714aae3b367eac2ee38767db..7822c97410c1f7fbd593ed4d886c7af41b43c0af 100644 (file)
@@ -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();
index ac903cc661c1e0f570933beae39c90acd76cf4a4..10ccde01fab96f17b9b9eeb50bb1145aa9607d8a 100644 (file)
@@ -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());
index 6eacb5be89242f95aab68e50e36d092e4d6dc9c4..2d2271dbf6fc10308dbd9120bce0717eea59499b 100644 (file)
@@ -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
index ec2b4cc5e69601037cbe498002d930524b16de57..27d478eed13a5611caa3f6f7d82cebe1c0f43949 100644 (file)
@@ -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);
index e38b5b1e2d956198acdb86b73502cc7392dff1d3..510765d318e8a26bc08252d9c964c47797cb0ae9 100644 (file)
@@ -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());
     }
index 0b74bfa5f171f504858fc55e05d3a0832e52f514..960b6c5c7ebb896204e32b6d68f54dd39c86a68c 100644 (file)
@@ -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()) {
index 2485589e3133c4d52488fd6b8f4941ba78710d15..64c2c6fce04e69385fb8f28fdb1ab2f248ccf3ab 100644 (file)
@@ -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());
                 }
index 5e70f033a27189702f8b6e8913f8b573e3c6e0ed..1a961963fb51f76d287a25368a2ac2ebf94da1b8 100644 (file)
@@ -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();
    }
index 0009a3d511f2b1ca17c494521e7932786ab01ecf..d4ca5c8bc97d7559d7b2a748a4941175f0f3213c 100644 (file)
@@ -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);
index 221c9d5a5ab9d0504b02859bddaffa492e31bd66..27efbe18a93009841e1c27f9329700c7ec1d1a75 100644 (file)
@@ -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
index f1b668e3f0a1daf4b1c00d38c3666bfa3b92a1e8..4930959fde0d9c75c18d64a28b1c0e75730e7fa4 100644 (file)
@@ -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);
index 09c17d054b2599fc24106b76e455fe85a6e613c5..6c34385070d809ac52786061ebc46e538c429c15 100644 (file)
@@ -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) {
index 6afb53cdd36a5c0222a701d5d1c9b39dad359b4b..76436f697d0f69705ec408b9f18a1ab9a56293c7 100644 (file)
@@ -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) {
index d6d2b536f4244abdb027a22b4b390b362eab225f..c0c2763ac844db0633ce3824300c0044ec106aec 100644 (file)
@@ -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();
index f851526ea3b514b3d953401abe51132179b3483a..de08c4fc49e0c342acaf000556befbc57e092116 100644 (file)
@@ -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<>();
index f8b2d1952229f1c1f74da1f85add93c31426c563..6683beb878415b0e01c0cc8c2bffae62a8cdb545 100644 (file)
@@ -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);
       }
 
index f727360b3479286b29758b77918d76df0d000a68..a723fc2cc19cf58070830e36fe474e69c58a8ed7 100644 (file)
@@ -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);
         }
     }
index 9d6a3ba7731fbf8b0e09c286557f63efb42f18c2..a1b90a8e7e754e3b6e17e0fd325df8b16900467d 100644 (file)
@@ -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()),
index fd1df89ca623a966726d9ae6af9b91872af46c34..d8d9231f490e610782f7810dfba623ab06dfc9c9 100644 (file)
@@ -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);
index acb3e849a22ffa8984989c06244dfece193ad84d..e449f1350676c396d4ce8c3e71cde8785f36bfa7 100644 (file)
@@ -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) {
index 3e5042af46702024ac40ed1b4919aa368cc4f5f2..fdc23e9e3ead08e881653021b28e36f46b990ca5 100644 (file)
@@ -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) {
index 73da07c9b417b1c96e14ac48997ac1add483d49b..16e7d5f2946daa6908e214b7d70bc94e071c4cf4 100644 (file)
@@ -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 )) {
index 3dca0340d1786c4a03bba40bb1d0bedf0a586ef5..7940dae77d4c1e523c56cbeec44eb79f66ba1e00 100644 (file)
@@ -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();
         }
index b335752e9c2ffe56ac9482647f2a38fa68d6c20d..6f8c59645024ef9d474c81b9b7fdc5f74b5a98c2 100644 (file)
@@ -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();
             }
index f1898ccd880158527632b5e3622191a69c46f2c9..005da134728a2f7b89c0839f20a5dc686bd8d61a 100644 (file)
@@ -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();
 
index 5803b425884dd692680ea98ddd24398e36b8aac3..f0aeaff126763dd1473014213676ce351b79317d 100644 (file)
@@ -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();
             }
index 814c82e788b0e48407ff292f217ce962b143be32..fa9618483f8d903b63bc551beb55adaebf6f3398 100644 (file)
@@ -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));
index 6664b76676e559a325016727d8bb2df5919de23f..2b4561c2f5e9adb2993a103f993f9bdea420d50c 100644 (file)
@@ -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) {
index 9d5400416615010ed2db73e8121f37daf1b17000..70e422b838ec8907cc13b3183f4266ca981f5951 100644 (file)
@@ -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
index 4164158e5f3633c9604243ce28225a33637e4924..f2f909d9995d5290afd3945af39ddceb01b55fee 100644 (file)
@@ -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);
             }
index d4366fa43623820b0e8556c48647b67175aac755..28496016126a6d54a605ff7438a7536fa1433295 100644 (file)
@@ -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];
index 14751254d6d18fd25709469b33c3d3232d0e1144..9ee2d60c8349551aaa4e13d8703493f85d0049b8 100644 (file)
@@ -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);
             }
index 957edcb945750f47d1b1300c440e35bd358b983b..08ab371e63c63b85d76e92cba3fde7eee356b7dc 100644 (file)
@@ -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;
index abd3a22ceda4022681e39c3b88e07e522064b380..f970b8d5f18e43758edea1fbf5f9a72ecf761bb3 100644 (file)
@@ -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});
index 62773615e0bc7c942d2761d1267231cc8707a09e..eb683b42aa6116ddc46b8c4588586061ed64da38 100644 (file)
@@ -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);
index d9e18a30d0df3f50e1743b7a812eb3412bde1ff7..df9db94f86f37bd9d9656ebee7309d2d0640d7fa 100644 (file)
@@ -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);
index aa71d41540987c5b120ba40c6bb7f16a2f0478d3..01f3dc9d8e23c72af3fb70f64bd374e2c2e05817 100644 (file)
@@ -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;
index ca94a6acfdba50d149b0e5c77ba3344667feccc9..610ad27c396662a7aaa22738e98a0cc389f50060 100644 (file)
@@ -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);
index 1239fe686fd0ca94a9c47b0f1ff575c62fb2f1a8..15476e48f3e5506ff5bf073231d257c497314c33 100644 (file)
@@ -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) {
index 953ef3733a96d64ac73c3a7e882a7a561a566e31..54edf47faa6f2b35982b4c385e71437a3a991171 100644 (file)
@@ -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);
index cdc146d98066907016ee8ea6f682235f8bc8a7c5..64a3a31c2107d2aef6806b3ade912212187401c5 100644 (file)
@@ -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
index 03dfdec40212a40adf866b202abba47c3ebc0105..cf15734217e9d60ba3327eab97f35b377875b340 100644 (file)
@@ -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;
index 52ae97a3ed28d328ea1e461c2edb88ad700a9bb2..214af0afa1ce8e07b1be02dbff5600f55f9e7fa9 100644 (file)
@@ -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);
index 05b22ccd00450f11d67973a6c08331db6d3714dc..7ba7892b283cdbe32036db7dcd6ff7c9e26e2971 100644 (file)
@@ -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();
index 6a1a830a0bca4cc963b097d091f44150c579d675..a192125081dbdafc49c5386d8333e889420d367c 100644 (file)
@@ -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() };
index 1fbc303d78691ae1ccebc6f149b58eefc510b54b..22740b0cf648319ecb073ffb6b717edb888c21c2 100644 (file)
@@ -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());
index 5717e5157d9a8ad5586b2e23ac2052e5e2c4f43c..5a12ac6426d49f484db8e41e72e29a9ca15cb690 100644 (file)
@@ -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);
index 49ef65cb8385dc5f82eb9c5f53cacaa1912aa0ec..df27e801a62f6dce654bdcc082e0e3070e51f40c 100644 (file)
@@ -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);
index 81912bbba54ac490fdfa4030823e5398b7976300..9f41088668cf00943cdd7d5327d317548ba02053 100644 (file)
@@ -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'};
index 881d543b0d5b6a3b00cba1e4cf2ed5373b595270..39d5a32482dcdef7519bd568f00cc8b15318bad0 100644 (file)
@@ -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) {
index 687888a69a332bd92fd9c9716b81d591ce46548f..48e2666aa147920d328d900368837d150ff34e52 100644 (file)
@@ -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
index b2991c1533b1096f87de168fcbcf914a4734079c..dbf1866da2a82db3c9d506188b99e9365d4c4e59 100644 (file)
@@ -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) {
index 4a0036b01003cb384f6b29d65f0a353abea7f4f8..0ce99759c1bf1c4815eb6a254fb82b3b9bbdd720 100644 (file)
@@ -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
index 3ac7adb84dec63e375236e8e59ef660d2c410600..b828d4745d17f60c32b2bfe3f6c44a89957297ce 100644 (file)
@@ -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
index 336f6bc4f2bce8f4b8eba15faa5a78ae8709e620..982c8700431cc33a9eacfc6530683545d775ed82 100644 (file)
@@ -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());
index 1a443d1e182a7bd0b9f46a40f292063af36cedee..059fffa2994de33d30f655dc6f580279feb2d859 100644 (file)
@@ -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());
index dac20b569b0f2a9a9dc2b1858829e52e1547fa54..afb18e09fa5ce5211a89af5db9b187a17b068573 100644 (file)
@@ -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();
 
index 57af6afcb5a193b284a33e567ca116b9da102a1a..db7e206541b2db5104b20b5c9ecc6cdc5ec093a3 100644 (file)
@@ -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);
index 03d657a42f0a86fa1c2c146a2ef8c018096766ca..d465118a333a4b0e1a32da7f1ce8615546c7602f 100644 (file)
@@ -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();
 
index 32213d0e4d76b4e852e68a9813aa8fd2c86caa49..3c94ef7319945c1db584d1c932c272527af3a9e0 100644 (file)
@@ -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();
index 734f3b73adaf1df8cac63224fd5e7e521ce603ae..225d0b5e05656fbba23b8eb387545d0f19b49b14 100644 (file)
@@ -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);
index c8c0cc2eac609c452d33669d015a1f63556c034e..a1ee955fd36704b74679905ffd57801add94e297 100644 (file)
@@ -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();
 
index 9cdf6f62c40ba90d5d7d39aad643f0c01df11a37..861f43ad8539a36ef1566ab98d270dc7595e4160 100644 (file)
@@ -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());
     }
index 26c00b64a17b27fb38e11b8535197d69a1c4603c..926a3e3ede76ff2e51dafb07a5f0d3f511a1d6e3 100644 (file)
@@ -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)) {
index fc8c353e3388e35e0097253aced8ee7a721b4cb6..b8b8a44427a478c4ac8231369a516786ce777797 100644 (file)
@@ -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());
     }
index d67a9db105c5443cf330eef0b65e1e196555b6e8..4eca038dcc7da0bb4b54824d237f2dfa88940c6a 100644 (file)
@@ -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());
     }
index f738f44ec893af7c528bd2f6b764e0e5ba63aa6e..a9d900f2c96608173b111e62327090c5305d7d19 100644 (file)
@@ -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());
     }
index 6d7e08c6a9f740e6fa3bfc9eae3da83f2eb3d71a..ff73e5b846a39fa64fb3cf9297ebcbfd4b9b993b 100644 (file)
@@ -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();
 
index d8a5229aba93fb6d0b1a200e197a2f9055f0e6b9..addc164d88734efdb2c870e49192cbae341de3ca 100644 (file)
@@ -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());
     }
index 337f6f5307b65803a82d7c9384dfae771f534d86..a28be1bdefb13f7c788970282cb3e63a639e1f95 100644 (file)
@@ -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());
     }
index f9d282a09512736493fb19958596e821d110129e..46d607e72974aed554966fafe309fdac16e6bb3e 100644 (file)
@@ -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();
 
index ce022023359dcd911277836c2062770c30124e76..a4c2a31401aa9aae61b25e93399fddb6050039cf 100644 (file)
@@ -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());
     }
index a15fa800162d848bd1b7840ef9739d019920e0a3..bb7eab1dbbfc0a83be359fbe1ec6928bffb0303a 100644 (file)
@@ -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);
index 71ea592da2ce090d04ff4b0cb3d687ca5f8019ec..f5cf552a5fafbc840fed92823b860fcf41fe5d9e 100644 (file)
@@ -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());
     }
index 21d7a83d1615f995564cc284bbf26d4022a5e14a..209409e4256c5c9545e94c7b0f65a31fbb9b4566 100644 (file)
@@ -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());
     }
index 3e003969a951577292c6ee574e2aed4c6815d3b5..8845e285fa916e4d24d43e98ff96512b841fe630 100644 (file)
@@ -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());
    }
index 824cfce1fdcc7a6ea14545ddf5720efaea86fa16..1ef63efbde8c838179aa865d1df78e35c23448b4 100644 (file)
@@ -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());
     }
index 5528d26293ca7da5171d6cc51fcc79341a6756ae..b6d7c644e7cdeae5f0ccfb6f493ebed1fc612dd1 100644 (file)
@@ -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());
     }
index 366f85310fc51a30298ab68fac43e84dc882c82b..2f5dac443f2c335fec470051ddc3b42bcbbb5192 100644 (file)
@@ -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());
     }
index 4e0386d1ca69b4b5b01304bed92d53f7612e3bb7..7393888034b5970de3ac97d2b1f8dd16d3c5c932 100644 (file)
@@ -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());
     }
index 1e57798caf76e58efca23d54cdbfc92c25b60cfe..e155df07b8499d097b7554ae63216f149e84205c 100644 (file)
@@ -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());
     }
index d50fc18a92a9057931a5106c783d97ca42e16609..a39f4d3c426e7455bc47843aa3c9efcf04b2da12 100644 (file)
@@ -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());
     }
index d2357a8fdc9c5e4fe3768eceb34174bc8089ab33..d1b79f2234c15c64185e53399c035d462123afac 100644 (file)
@@ -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());
     }
index 22bce9375b9876aa7900081b560abe984d96db21..213db5f08080fe97c63d7c143c8c11216b0c12f6 100644 (file)
@@ -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());
     }
index e1a08b6e098c7b97b45b789d6f4a5215a94e61e6..c9067d594ef1abc450de18609bf8723a1cc332cc 100644 (file)
@@ -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();
index c3cd26d1ce7fef2c18161add6876a6e22cf3e74b..8902d31882978412da3cdd36c7be0c741cc707db 100644 (file)
@@ -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();
index 4671e7a8aae6bb9d774e824d2844e22954158618..488e5172ad2bfdca67cf6f2c17b6c5b54e4c055d 100644 (file)
@@ -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());
     }
index a7defb0e388cd17085cf1e1cc277b63eaf49a924..be72848ee4275ea430d10bdf0c49ea835092f94e 100644 (file)
@@ -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());
     }
index 343c1117d96e8cd976fbf91e570281c2dc562bfa..bfadc5e47407ed02d45e30b56c3bfe42d3136bad 100644 (file)
@@ -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);
index ebda0b8afa240b9e6bf392e563d525449c32e79d..2b909167757bb2e7d185d4bda37c9d50aaae17c7 100644 (file)
@@ -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();
index 87fb7e0033005926fe7b0aa03effb9f6ae64d2cb..08d0e0e8bf685363e356d8a0c7ee41239a14a2b2 100644 (file)
@@ -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();
     }
index c5395232dc6b1cd478249774156c346d81e3e96b..b7613be2dafe87958a6b348a0707c0704a387769 100644 (file)
@@ -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);
index 068fa108836b3b444e5a1e2e72844d4cee012dd4..28d02df0a033cbd68f0f743b1cea2938cfbe8153 100644 (file)
@@ -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
index 74d6d27ec23607557c0443291f6a0824539938b9..9d8aa55dde57b3f0a73c935a8981d988c4801f00 100644 (file)
@@ -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));
    }
 
    /**
index fba8bc97c0deec0ae0316af44bc4c8ef16d6789b..9a0808d286153c1f063d4c01e3c476984b1101a9 100644 (file)
@@ -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);
index 0d6ce9bc8c2afe9c3c5cfb453b6d7213dbd7aa05..082b4866d4b5887f16bcdfca4cd952b8072d4b01 100644 (file)
@@ -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) {
index c7cd45c1cc6773025f0f42394fcf5381928e647d..2c9fc685206750a24141c516bc4c3b807d0068b0 100644 (file)
@@ -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(" ")));
index 36ad393a518e8af57e359589efd52f3e741e357e..936b84317c231d0d15c6e8ec1c633ab52132cef0 100644 (file)
@@ -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());
index 608c14be6dd21943988b4b99ef825f9c77777e1c..c7e4536b3bd3494591c3bbf1187992de510bdd30 100644 (file)
@@ -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);
 
index d5dceb43fc1d33d635ea9c3f59d1e187a7b436ef..cc44cf91baa342925d37cee52e45cc2e65b2524f 100644 (file)
@@ -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);
             }
index 5587042f0ca462b16642065f4ae2a914b343e0e8..1981f8b6e579afab33a0f8a255ac0a6b0843a9d4 100644 (file)
@@ -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) {
index acef3d7d36b43996c45334535e719c178aa1321c..5bd4cd6b443cc86fe336878027c3172af4e83505 100644 (file)
@@ -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();
     }
 
     /**
index 09ce055d34c289811c19abaf704cc768a3896a2b..1f127fb48a7f7a5c2fe53d419063e6294b8142f7 100644 (file)
@@ -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 */
index 2ef4f34cfb25f65db6804a1ea40c8295a5f4ffc1..74a6dee371cc13268bb057583403f60414d7f255 100644 (file)
@@ -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;
     }
index a4cb805e039d8714d7a5838ab696bf1be03740cd..ae88715975df3bf9578990857c120fb5aba49d0a 100644 (file)
@@ -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;
     }
index ec1dce3ffb469055fa29c5a6a9eaa18fbf997610..92c5fa799a4b63809dfe4172477284a9a37312d1 100644 (file)
@@ -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);
index 717b866c85b8616b48696349d2346f1996257e78..2c71372ee9e0fac7520f32760e9c4d087afe1d3e 100644 (file)
@@ -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 {
index 833310d495fb2ed46a9b95ee7e9226a28f687740..91cfded86318a2d1e409596836e0da0926771ad4 100644 (file)
@@ -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();
index 3ae5c1b3128ba3d9636cc3ef1177195c827655e9..2178577bf0481cf566ce756b33302ad8911c2c52 100644 (file)
@@ -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);
index b41c2b91461bde5dec2262142892f00cc5cc3552..caeac85d666e1c39998a055ac21143703cf3dd5a 100644 (file)
@@ -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();
index 0c18b2b2ec7d950e6c2ae618c5e10ea325abf710..230e47b16ce9b740f3baaba01d8372bdcbe243fd 100644 (file)
@@ -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");
index 42fa643a36cdddcb854ca26416b0af4a3c1f1484..ccc8eef44e744754d293078fd84e4dd077259b62 100644 (file)
@@ -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);
+        }
     }
 
     /**
index 12a4ff008aed17ed114829e5a4a3c435fc4b3d4b..b303d3d7dac8dc5f09c9e3cc2e16b561cf8a4c24 100644 (file)
@@ -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());
         }
index e848859a00b004d8a81b0f4338c0cfbd9c0862a1..3efcb1055c8927f5857321682329374ec7527acc 100644 (file)
@@ -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 {
index 762038b3c49473f3694b4fabd883784af4978a0e..90fbc2433e820f2e6f528477a3fae0adee787cad 100644 (file)
@@ -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 ..
 
index 727030bf15b0f5171419bea51ef3cb73e81ccded..f70edb9044b450d0afcd2df48b925b1dfa4b9036 100644 (file)
@@ -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());
 
index 9dec8e6ca638444634a9babec644fcd276da4323..c89b6504529663bfd8838b8e89a49ea824d7a6cf 100644 (file)
@@ -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
index 14bd636e840c907b9fbffcd96f2f016b7457701c..b7ea54ddf5a4045c3cc1aa839d23400199b8cb51 100644 (file)
@@ -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);
     }
 
     /**
index 9f7564cfe2da0cf57f75fb8e41486a0eedf2c1c1..f16fe436e1253158370ed1b9067af4066bc00f1d 100644 (file)
@@ -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");
         }
index 3c36c778273601bd84090c5ec8be657af16f2f1f..8f6bd803e40bedaa0e63da2c4681093b7a09752c 100644 (file)
@@ -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);
index bdaccb7d6c924b291cedbf1a3a23af88de644d88..31c6632c07bc5b17198dacd5279e4a581855aedb 100644 (file)
@@ -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);
index adb426d35821ca3273d7d15c9e303bd86f1eef78..18f162395f1eb930da15520fedbc25c2fbd45b29 100644 (file)
@@ -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(),
index 370a02f672320e2de710277461823d6d4fc8c837..7b24b774f6a114b89475644b079fd5206056c76f 100644 (file)
@@ -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);
     }
index b812a3d31c4bb791571fcab12392e575ffadf19b..ba098965d300dc8ed00dbfe305fbf13db1d961da 100644 (file)
@@ -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));
     }
 
index 6dd510fe3921b596f52223e43327b14d965d01d0..51281d4bbaf48943eaacdbaa1601b236c3e65c76 100644 (file)
@@ -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 {
index a883ee3abb1893bceedc3d0a6aa95b9179e0446c..3bbec57f50e0ede61d55cd5272c1a6bc9a1442a2 100644 (file)
@@ -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();
     }
index b59950b96c84a6ced9cfa037d1910014e98f11e1..55ba486407cf133463fce7f13cf60d9631832d37 100644 (file)
@@ -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);
index 3e04fc8976820523d5dba5f30ad73ad9af8efb55..d96e2f264ee9bc4c23e63f7d743aa0788a83c0e4 100644 (file)
@@ -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());
         }
index 78fd9db41ba7000d445d1e9409f80e1d2c5d5769..24f00639164c48bffa79989b7d2f0db9cecae743 100644 (file)
@@ -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");
index 07c67c4c1046f855100f6d06825986b88e93ed42..635af68dde6faaefb8f7a46437ce906a3ca88a05 100644 (file)
@@ -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
index bd86d39cc284790565ab6358df179c81f8b5f1ba..e3fb4d30b1a12bed2acaff0c1e810fabb6377d40 100644 (file)
@@ -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);
            }
index 0bf0b99ce73bdbe0ea94ecce9d6afb9652274d1a..0f7d88939d072930e17616e660ab28dd2a4c0432 100644 (file)
@@ -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();
 
index 057e16ae87382604d6878a6d06640a67a70de5d0..4cf5a31eb70014035c9f1577baf6b19982ee1800 100644 (file)
@@ -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());
index 5af30cd97813abe007a73f75062441efc7df43f4..48b8b594ecb93928440491bc6a5cc11691724311 100644 (file)
@@ -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);
 
 
index 29cf6852aa09d1120a738806c9441e931d6265c4..e85ff044ab2d96a5c58803baf58e1e387ce798f8 100644 (file)
@@ -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);
index f36e24d56227e0856a683c319f7e53b87ce5e569..0d42a7ba429cb650a1b0466959bb8079b16afed2 100644 (file)
@@ -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);
         }
index 3121ee039d30233754b6c12352fdf77986f11e75..91c7a36513c2cfbc28c16db78dee5ad95cc350f6 100644 (file)
@@ -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()});
index 6b99428aeadf610bd55a2a6087e892d8ec1f691e..b904af880869d03f5b8d2572f0aadc8d47bf1739 100644 (file)
@@ -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 {
index 69566e59f5ef5e0bfdb7eb4c5ab393acf6d3ae8b..091802098c495c828c77b78cfb3deca171fe7713 100644 (file)
@@ -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 {
index 466f596650f2a8556696d88b83836c7a2145c366..91bf45681679621a49eee6b3312e85b4da933399 100644 (file)
@@ -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();
index d519393c8ced66f5c06e8ad7c008b2f00e1d54be..f0df67af50e6a062cdf064bb180cdc615eb48e20 100644 (file)
@@ -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];
index 005d03d6ef528d8b3f7b3081307303084254966c..53e1229537e624f7dd85cd87cd35e10cbe811bcd 100644 (file)
@@ -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);
 
index e9737324e890c7eed822e9a2c7a3aeb84d9fbed3..26793e193058af4715e561c55fa55bf4674d2773 100644 (file)
@@ -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());
index eed605b661973cdea5b091cdff66becac5431565..da9050740026b276f9c4b00122c673bab693150c 100644 (file)
@@ -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));
index 57b344bd259a0a8cc4edef8cda2ea197638ae481..8abd514c6cd1d109d2746e0afde857afa6729a05 100644 (file)
@@ -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);
 
index b29c4bc3eeb4004485b03df99e143dc28f4e943b..b836e3269ce80cc3641f33abd46762ee6f26e3cf 100644 (file)
@@ -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) {
index b978581ee20b467411db3e12df2c951a9861fd7c..f5a0f1620d8c564035ec0095fbc6c1c8b38b24e9 100644 (file)
@@ -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();
index b4ea25eddc6b4dcf5482c70d2aeec5b10008a1ec..48ef715a929561e24cd395d6965cca024877c694 100644 (file)
@@ -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();
index 3cd5b703825f0bf403c387c9e728893dbebc7fe0..6b9a1575f6e822363a3860505fbe6066a0702afb 100644 (file)
@@ -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());
index ca892b9ca8c899dd22264141290791b1ee49fa42..cd96d6c605586f4ac282540e4812aadf4fb8647b 100644 (file)
@@ -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");
index 5ff7c4e5cabfb62128eb5adeb28625c579c7c026..2bc2da0a1c972a690e6d8f74959c173c8bceb1c0 100644 (file)
@@ -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()) {
 
index 0d08b232bf9d47ccc944b94b547031e3c9bce2d5..2ee6ba30e12ffd2bc7068de680964003693c7d78 100644 (file)
@@ -69,7 +69,7 @@ class TestAgileDecryptor {
                 os.write(testData);
             }
 
-            UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+            UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
             fsEnc.writeFilesystem(bos);
 
             bos.close();
index ad585737645e4994eb12812f53f4fcb6906c4136..e13f205c40b98c003ca3ea3791ed8b067db1f7f6 100644 (file)
@@ -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
index 4994d5db98eaed79361dbcc77e538c7dd698571e..94bc700be31f724d77cee023639e65ac5e27cdf4 100644 (file)
@@ -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);
index 8674a41d1587f3f6a7be5920f9f9faf6aae40ed2..bd1da88a7ce6a9cd8d49ecd62f7398df8058e6e7 100644 (file)
@@ -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());
             }
index a2da085b011e9ed581a260bd4ac8f12be7027c03..f60ce5bc3bf72d723d0c73da997a8d3bafc98bf5 100644 (file)
@@ -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");
index e2abb090ab76e5fcedee35de6265170cff0416f4..16fa1fd2404ec207a8b54192840767b87db25913 100644 (file)
@@ -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();
index dd52a10a580186b8a7fad5c33204623a738585ec..a162dd834693f9c4c2d78492db2ec597eeb31423 100644 (file)
@@ -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());
index 3a3f2fa8dca74e11ae5d1abc16c6412c1adff2b9..7a39eb47797f6cb753e4d6ae9ab9dc22ddcd4e00 100644 (file)
@@ -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()));
index 886340091c9c17a5a9d0c3a51a3669cf44c876d8..c7135da492fb4f2999a3593380d87d87dbb810b2 100644 (file)
@@ -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();
 
index 430cd8e5d2048f4ede7699ed07de7ef76c4ac1ee..4efcc809835e848b493de3e60bcae5a67b1953da 100644 (file)
@@ -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());
     }
index c200bbdee0bbc82d4d2daca77bad5114914bb86e..b503472db7e2767c923f225985e161e6273fe056 100644 (file)
@@ -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);
index 1bda3ab462e6a113b850d27ea6750181a2434e32..c72f0bdbfaa2fb3f93f3fca94134de91474691d3 100644 (file)
@@ -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();
index 64577b0c7c6a9283430dd79272de5eb636f1ae9d..b79a002f693d18b5ad450bfe5d0b6e709c6a0ff6 100644 (file)
@@ -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) {
index a210ac8d7c443dee7d118408769d7656ab3cb13f..3ab7e67561ae17b0dd8bd4f1133af6191d5ab89b 100644 (file)
@@ -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();
index af7ec4eaa10b74f30fa9519ae2cfbd89fdc69f37..7382c65778eeefeac4d9101893fb31768b14544b 100644 (file)
@@ -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);
index 02d84fac03c3bf53ccd595b0c855e9fa0a170d5c..30731899522904e9e503417932493b86ae97586c 100644 (file)
@@ -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];
index 94db023cc1e2d3d562a30283f3f296b551308774..ebcdb5baf272cc36dec6ba4ed76a3a9125ad083c 100644 (file)
@@ -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);
 
index af3c773d00d032d98999bbfd51af6d78793c0497..8502bbfcd1964319acaa158b0523474d3a9dd95b 100644 (file)
@@ -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();
     }
index 349e5427fceaf9c300b3084c98fac85b406c4d26..0dc0bafbf691d352cabba4444cce7a01acc026e7 100644 (file)
@@ -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));
         }
     }
 
index 62b83ffaf98bc429c634dd7744dd563bee9c50ff..d80d23990c5d84e9cf325a833e67bc86a2dd6e9f 100644 (file)
@@ -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) {
index 4d729d600620674849d6908e8f1371015fc542bf..321e67fe77afaf449e2640763ab40ab6657ba338 100644 (file)
@@ -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);
index 0faf865e5a081f1a876540a533b525f1869cfbd1..059426289e81af05f86345dd2e9441cd59c53e6c 100644 (file)
@@ -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));
         }
     }
 
index 16b1b334d5ce07e5a13d12cdbe2c00119c8196df..58640417060deaefab15682c98ecbb7044b66ca1 100644 (file)
@@ -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);
index 481afd28bea49855e437aec980cf06ac779ed0c1..bb12f9932e4172a1380fb68c46d9f295b891e25d 100644 (file)
@@ -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);
index d7b9ad7b5f4b3637d0dd1bebd2425475d8617379..00240378dc856bc196a795552faafe1e72e50ac6 100644 (file)
@@ -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);
index d1c58f927860cacef420467cfcbc289034273c8d..8f505f793c6dc0035f4635899e1f7d3ce7ba7398 100644 (file)
@@ -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);
index 0c8fad889ec152ccdc8d7b1b0567fb432a780c73..3d63d930f3fa2aedef756751815423c94e6ba10c 100644 (file)
@@ -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);
         }