aboutsummaryrefslogtreecommitdiffstats
path: root/poi
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2023-06-08 08:53:08 +0000
committerDominik Stadler <centic@apache.org>2023-06-08 08:53:08 +0000
commitd3e35e740a593027a1105e6509c0aadaa54399b0 (patch)
tree4f9c5b276aa7a088def6aaa7282bb37c39b16105 /poi
parentc8f9fe4c2c01aa896c80de7b43725788b4ce6c4a (diff)
downloadpoi-d3e35e740a593027a1105e6509c0aadaa54399b0.tar.gz
poi-d3e35e740a593027a1105e6509c0aadaa54399b0.zip
Remove deprecation warnings reported with newer commons-io
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1910300 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
-rw-r--r--poi/src/main/java/org/apache/poi/POIDocument.java2
-rw-r--r--poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java6
-rw-r--r--poi/src/main/java/org/apache/poi/hpsf/Property.java4
-rw-r--r--poi/src/main/java/org/apache/poi/hpsf/PropertySet.java4
-rw-r--r--poi/src/main/java/org/apache/poi/hpsf/Section.java4
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java9
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java13
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java2
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java2
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/FilePassRecord.java2
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/Record.java10
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java2
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java2
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPicture.java8
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java8
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/filesystem/DocumentOutputStream.java4
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java4
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java4
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java18
-rw-r--r--poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java4
-rw-r--r--poi/src/main/java/org/apache/poi/sl/image/ImageHeaderBitmap.java2
-rw-r--r--poi/src/main/java/org/apache/poi/sl/usermodel/ObjectShape.java2
-rw-r--r--poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java4
-rw-r--r--poi/src/main/java/org/apache/poi/ss/util/ImageUtils.java20
-rw-r--r--poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java5
-rw-r--r--poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java5
-rw-r--r--poi/src/main/java/org/apache/poi/util/IOUtils.java4
-rw-r--r--poi/src/main/java/org/apache/poi/util/LZWDecompresser.java2
-rw-r--r--poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java4
-rw-r--r--poi/src/test/java/org/apache/poi/POIDataSamples.java4
-rw-r--r--poi/src/test/java/org/apache/poi/TestPOIDocumentMain.java2
-rw-r--r--poi/src/test/java/org/apache/poi/ddf/TestEscherDump.java2
-rw-r--r--poi/src/test/java/org/apache/poi/hpsf/basic/TestHPSFBugs.java2
-rw-r--r--poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java2
-rw-r--r--poi/src/test/java/org/apache/poi/hpsf/basic/TestReadAllFiles.java2
-rw-r--r--poi/src/test/java/org/apache/poi/hpsf/basic/TestWrite.java12
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java2
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java2
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java4
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java6
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/model/TestEscherRecordFactory.java2
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/record/TestDConRefRecord.java2
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/record/TestDrawingRecord.java2
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/record/TestLbsDataSubRecord.java2
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/record/TestRecordFactory.java4
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/record/TestSSTRecord.java2
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/record/common/TestUnicodeString.java4
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/usermodel/TestBugs.java12
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/usermodel/TestDataValidation.java4
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFCell.java2
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java12
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/usermodel/TestOLE2Embedding.java4
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java4
-rw-r--r--poi/src/test/java/org/apache/poi/poifs/crypt/agile/TestAgileDecryptor.java2
-rw-r--r--poi/src/test/java/org/apache/poi/poifs/dev/TestPOIFSDump.java2
-rw-r--r--poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocument.java4
-rw-r--r--poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java2
-rw-r--r--poi/src/test/java/org/apache/poi/poifs/filesystem/TestEmptyDocument.java4
-rw-r--r--poi/src/test/java/org/apache/poi/poifs/filesystem/TestEntryUtils.java2
-rw-r--r--poi/src/test/java/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java2
-rw-r--r--poi/src/test/java/org/apache/poi/poifs/filesystem/TestOle10Native.java4
-rw-r--r--poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java4
-rw-r--r--poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java2
-rw-r--r--poi/src/test/java/org/apache/poi/poifs/property/TestDirectoryProperty.java4
-rw-r--r--poi/src/test/java/org/apache/poi/poifs/property/TestDocumentProperty.java4
-rw-r--r--poi/src/test/java/org/apache/poi/poifs/property/TestPropertyTable.java2
-rw-r--r--poi/src/test/java/org/apache/poi/poifs/property/TestRootProperty.java4
-rw-r--r--poi/src/test/java/org/apache/poi/poifs/storage/RawDataUtil.java6
-rw-r--r--poi/src/test/java/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java2
-rw-r--r--poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java4
-rw-r--r--poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestPicture.java2
-rw-r--r--poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestWorkbook.java4
-rw-r--r--poi/src/test/java/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java4
-rw-r--r--poi/src/test/java/org/apache/poi/ss/util/TestCellRangeAddress.java2
-rw-r--r--poi/src/test/java/org/apache/poi/ss/util/TestDateFormatConverter.java4
-rw-r--r--poi/src/test/java/org/apache/poi/util/TestHexDump.java4
-rw-r--r--poi/src/test/java/org/apache/poi/util/TestIOUtils.java4
-rw-r--r--poi/src/test/java/org/apache/poi/util/TestLittleEndianInputStream.java2
-rw-r--r--poi/src/test/java/org/apache/poi/util/TestLittleEndianStreams.java2
-rw-r--r--poi/src/test/java/org/apache/poi/util/TestRLEDecompressingInputStream.java2
80 files changed, 193 insertions, 147 deletions
diff --git a/poi/src/main/java/org/apache/poi/POIDocument.java b/poi/src/main/java/org/apache/poi/POIDocument.java
index 608c14be6d..c7e4536b3b 100644
--- a/poi/src/main/java/org/apache/poi/POIDocument.java
+++ b/poi/src/main/java/org/apache/poi/POIDocument.java
@@ -336,7 +336,7 @@ public abstract class POIDocument implements Closeable {
* {@link POIFSFileSystem} occurs
*/
private void writePropertySet(String name, PropertySet set, POIFSFileSystem outFS) throws IOException {
- try (UnsynchronizedByteArrayOutputStream bOut = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bOut = UnsynchronizedByteArrayOutputStream.builder().get()) {
PropertySet mSet = new PropertySet(set);
mSet.write(bOut);
diff --git a/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java b/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java
index d5dceb43fc..cc44cf91ba 100644
--- a/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java
+++ b/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java
@@ -192,8 +192,8 @@ public final class EscherMetafileBlip extends EscherBlipRecord {
* @return the inflated picture data.
*/
private static byte[] inflatePictureData(byte[] data) {
- try (InflaterInputStream in = new InflaterInputStream(new UnsynchronizedByteArrayInputStream(data));
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
+ try (InflaterInputStream in = new InflaterInputStream(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get());
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) {
IOUtils.copy(in, out);
return out.toByteArray();
} catch (IOException e) {
@@ -410,7 +410,7 @@ public final class EscherMetafileBlip extends EscherBlipRecord {
// "... LZ compression algorithm in the format used by GNU Zip deflate/inflate with a 32k window ..."
// not sure what to do, when lookup tables exceed 32k ...
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
try (DeflaterOutputStream dos = new DeflaterOutputStream(bos)) {
dos.write(pictureData);
}
diff --git a/poi/src/main/java/org/apache/poi/hpsf/Property.java b/poi/src/main/java/org/apache/poi/hpsf/Property.java
index 5587042f0c..1981f8b6e5 100644
--- a/poi/src/main/java/org/apache/poi/hpsf/Property.java
+++ b/poi/src/main/java/org/apache/poi/hpsf/Property.java
@@ -272,7 +272,7 @@ public class Property {
/* Variable length: */
if (type == Variant.VT_LPSTR || type == Variant.VT_LPWSTR) {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try {
length = write(bos, property) - 2*LittleEndianConsts.INT_SIZE;
/* Pad to multiples of 4. */
@@ -399,7 +399,7 @@ public class Property {
if (value instanceof String) {
b.append((String)value);
b.append("\n");
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try {
write(bos, codepage);
} catch (Exception e) {
diff --git a/poi/src/main/java/org/apache/poi/hpsf/PropertySet.java b/poi/src/main/java/org/apache/poi/hpsf/PropertySet.java
index acef3d7d36..5bd4cd6b44 100644
--- a/poi/src/main/java/org/apache/poi/hpsf/PropertySet.java
+++ b/poi/src/main/java/org/apache/poi/hpsf/PropertySet.java
@@ -514,7 +514,7 @@ public class PropertySet {
}
private byte[] toBytes() throws WritingNotSupportedException, IOException {
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
LittleEndianOutputStream leos = new LittleEndianOutputStream(bos)) {
/* Write the number of sections in this property set stream. */
@@ -599,7 +599,7 @@ public class PropertySet {
* @throws IOException if an I/O exception occurs.
*/
public InputStream toInputStream() throws WritingNotSupportedException, IOException {
- return new UnsynchronizedByteArrayInputStream(toBytes());
+ return UnsynchronizedByteArrayInputStream.builder().setByteArray(toBytes()).get();
}
/**
diff --git a/poi/src/main/java/org/apache/poi/hpsf/Section.java b/poi/src/main/java/org/apache/poi/hpsf/Section.java
index 09ce055d34..1f127fb48a 100644
--- a/poi/src/main/java/org/apache/poi/hpsf/Section.java
+++ b/poi/src/main/java/org/apache/poi/hpsf/Section.java
@@ -64,7 +64,7 @@ public class Section {
* established when the section's size is calculated and can be reused
* later. If the array is empty, the section was modified and the bytes need to be regenerated.
*/
- private final UnsynchronizedByteArrayOutputStream sectionBytes = new UnsynchronizedByteArrayOutputStream();
+ private final UnsynchronizedByteArrayOutputStream sectionBytes = UnsynchronizedByteArrayOutputStream.builder().get();
/**
* The offset of the section in the stream.
@@ -733,7 +733,7 @@ public class Section {
}
final int[][] offsets = new int[properties.size()][2];
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
LittleEndianOutputStream leos = new LittleEndianOutputStream(bos)) {
/* Write the section's length - dummy value, fixed later */
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java
index 2ef4f34cfb..74a6dee371 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java
@@ -18,6 +18,7 @@
*/
package org.apache.poi.hssf.record;
+import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@@ -278,7 +279,13 @@ public class DConRefRecord extends StandardRecord {
}
private static RecordInputStream bytesToRIStream(byte[] data) {
- RecordInputStream ric = new RecordInputStream(new UnsynchronizedByteArrayInputStream(data));
+ RecordInputStream ric = null;
+ try {
+ ric = new RecordInputStream(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get());
+ } catch (IOException e) {
+ // not possible with ByteArray but still declared in the API
+ throw new IllegalStateException(e);
+ }
ric.nextRecord();
return ric;
}
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java b/poi/src/main/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java
index a4cb805e03..ae88715975 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java
@@ -19,6 +19,7 @@ package org.apache.poi.hssf.record;
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
+import java.io.IOException;
import java.util.Map;
import java.util.function.Supplier;
@@ -48,9 +49,15 @@ public final class DrawingRecordForBiffViewer extends AbstractEscherHolderRecord
private static RecordInputStream convertToInputStream(DrawingRecord r)
{
byte[] data = r.serialize();
- RecordInputStream rinp = new RecordInputStream(
- new UnsynchronizedByteArrayInputStream(data)
- );
+ RecordInputStream rinp = null;
+ try {
+ rinp = new RecordInputStream(
+ UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get()
+ );
+ } catch (IOException e) {
+ // not possible with ByteArray but still declared in the API
+ throw new IllegalStateException(e);
+ }
rinp.nextRecord();
return rinp;
}
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java
index ec1dce3ffb..92c5fa799a 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java
@@ -180,7 +180,7 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord {
private static Ptg readRefPtg(byte[] formulaRawBytes) {
try (LittleEndianInputStream in = new LittleEndianInputStream(
- new UnsynchronizedByteArrayInputStream(formulaRawBytes))) {
+ UnsynchronizedByteArrayInputStream.builder().setByteArray(formulaRawBytes).get())) {
byte ptgSid = in.readByte();
switch(ptgSid) {
case AreaPtg.sid: return new AreaPtg(in);
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java b/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java
index 717b866c85..2c71372ee9 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java
@@ -1034,7 +1034,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
private static class ShapeCollector extends DefaultEscherRecordFactory {
final List<EscherRecord> objShapes = new ArrayList<>();
- final UnsynchronizedByteArrayOutputStream buffer = new UnsynchronizedByteArrayOutputStream();
+ final UnsynchronizedByteArrayOutputStream buffer = UnsynchronizedByteArrayOutputStream.builder().get();
void addBytes(byte[] data) {
try {
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/FilePassRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/FilePassRecord.java
index 833310d495..91cfded863 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/FilePassRecord.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/FilePassRecord.java
@@ -122,7 +122,7 @@ public final class FilePassRecord extends StandardRecord {
@Override
protected int getDataSize() {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
LittleEndianOutputStream leos = new LittleEndianOutputStream(bos);
serialize(leos);
return bos.size();
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/Record.java b/poi/src/main/java/org/apache/poi/hssf/record/Record.java
index 3ae5c1b312..2178577bf0 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/Record.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/Record.java
@@ -17,6 +17,8 @@
package org.apache.poi.hssf.record;
+import java.io.IOException;
+
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
import org.apache.poi.common.Duplicatable;
import org.apache.poi.common.usermodel.GenericRecord;
@@ -75,7 +77,13 @@ public abstract class Record extends RecordBase implements Duplicatable, Generic
// Do it via a re-serialization
// It's a cheat, but it works...
byte[] b = serialize();
- RecordInputStream rinp = new RecordInputStream(new UnsynchronizedByteArrayInputStream(b));
+ RecordInputStream rinp = null;
+ try {
+ rinp = new RecordInputStream(UnsynchronizedByteArrayInputStream.builder().setByteArray(b).get());
+ } catch (IOException e) {
+ // not possible with ByteArray but still declared in the API
+ throw new IllegalStateException(e);
+ }
rinp.nextRecord();
Record[] r = RecordFactory.createRecord(rinp);
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java b/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java
index b41c2b9146..caeac85d66 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java
@@ -453,7 +453,7 @@ public final class RecordInputStream implements LittleEndianInput {
*/
@Deprecated
public byte[] readAllContinuedRemainder() {
- try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(2 * MAX_RECORD_DATA_SIZE)) {
+ try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(2 * MAX_RECORD_DATA_SIZE).get()) {
while (true) {
byte[] b = readRemainder();
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java
index 0c18b2b2ec..230e47b16c 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java
@@ -136,7 +136,7 @@ public abstract class SubRecord implements Duplicatable, GenericRecord {
protected abstract int getDataSize();
public byte[] serialize() {
int size = getDataSize() + 4;
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(size);
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(size).get();
serialize(new LittleEndianOutputStream(baos));
if (baos.size() != size) {
throw new IllegalStateException("write size mismatch");
diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPicture.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPicture.java
index 42fa643a36..ccc8eef44e 100644
--- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPicture.java
+++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPicture.java
@@ -18,6 +18,7 @@
package org.apache.poi.hssf.usermodel;
import java.awt.Dimension;
+import java.io.IOException;
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
import org.apache.poi.ddf.DefaultEscherRecordFactory;
@@ -191,7 +192,12 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture {
EscherBSERecord bse = iwb.getBSERecord(getPictureIndex());
byte[] data = bse.getBlipRecord().getPicturedata();
int type = bse.getBlipTypeWin32();
- return ImageUtils.getImageDimension(new UnsynchronizedByteArrayInputStream(data), type);
+ try {
+ return ImageUtils.getImageDimension(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get(), type);
+ } catch (IOException e) {
+ // not possible with ByteArray but still declared in the API
+ throw new IllegalStateException(e);
+ }
}
/**
diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
index 12a4ff008a..b303d3d7da 100644
--- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
+++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
@@ -1353,7 +1353,7 @@ public final class HSSFWorkbook extends POIDocument implements Workbook {
DocumentNode workbookNode = (DocumentNode) dir.getEntry(
getWorkbookDirEntryName(dir));
POIFSDocument workbookDoc = new POIFSDocument(workbookNode);
- workbookDoc.replaceContents(new UnsynchronizedByteArrayInputStream(getBytes()));
+ workbookDoc.replaceContents(UnsynchronizedByteArrayInputStream.builder().setByteArray(getBytes()).get());
// Update the properties streams in the file
writeProperties();
@@ -1415,7 +1415,7 @@ public final class HSSFWorkbook extends POIDocument implements Workbook {
List<String> excepts = new ArrayList<>(1);
// Write out the Workbook stream
- fs.createDocument(new UnsynchronizedByteArrayInputStream(getBytes()), "Workbook");
+ fs.createDocument(UnsynchronizedByteArrayInputStream.builder().setByteArray(getBytes()).get(), "Workbook");
// Write out our HPFS properties, if we have them
writeProperties(fs, excepts);
@@ -2110,7 +2110,7 @@ public final class HSSFWorkbook extends POIDocument implements Workbook {
}
}
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
poiData.writeFilesystem(bos);
return addOlePackage(bos.toByteArray(), label, fileName, command);
}
@@ -2138,7 +2138,7 @@ public final class HSSFWorkbook extends POIDocument implements Workbook {
Ole10Native.createOleMarkerEntry(oleDir);
Ole10Native oleNative = new Ole10Native(label, fileName, command, oleData);
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
oleNative.writeOut(bos);
oleDir.createDocument(Ole10Native.OLE10_NATIVE, bos.toInputStream());
}
diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/DocumentOutputStream.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/DocumentOutputStream.java
index e848859a00..3efcb1055c 100644
--- a/poi/src/main/java/org/apache/poi/poifs/filesystem/DocumentOutputStream.java
+++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/DocumentOutputStream.java
@@ -43,7 +43,7 @@ public final class DocumentOutputStream extends OutputStream {
/** our buffer, when null we're into normal blocks */
private UnsynchronizedByteArrayOutputStream _buffer =
- new UnsynchronizedByteArrayOutputStream(POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE);
+ UnsynchronizedByteArrayOutputStream.builder().setBufferSize(POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE).get();
/** our main block stream, when we're into normal blocks */
private POIFSStream _stream;
@@ -105,7 +105,7 @@ public final class DocumentOutputStream extends OutputStream {
}
// Have an empty one created for now
- return parent.createDocument(name, new UnsynchronizedByteArrayInputStream(new byte[0]));
+ return parent.createDocument(name, UnsynchronizedByteArrayInputStream.builder().setByteArray(new byte[0]).get());
}
private void checkBufferSize() throws IOException {
diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java
index 762038b3c4..90fbc2433e 100644
--- a/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java
+++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java
@@ -254,7 +254,7 @@ public class Ole10Native {
*/
public static void createOleMarkerEntry(final DirectoryEntry parent) throws IOException {
if (!parent.hasEntry(OLE_MARKER_NAME)) {
- parent.createDocument(OLE_MARKER_NAME, new UnsynchronizedByteArrayInputStream(OLE_MARKER_BYTES));
+ parent.createDocument(OLE_MARKER_NAME, UnsynchronizedByteArrayInputStream.builder().setByteArray(OLE_MARKER_BYTES).get());
}
}
@@ -402,7 +402,7 @@ public class Ole10Native {
switch (mode) {
case parsed: {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (LittleEndianOutputStream leos = new LittleEndianOutputStream(bos)) {
// total size, will be determined later ..
diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java
index 727030bf15..f70edb9044 100644
--- a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java
+++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java
@@ -780,9 +780,9 @@ public class POIFSFileSystem extends BlockStore
// _header.setPropertyStart has been updated on write ...
// HeaderBlock
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(
_header.getBigBlockSize().getBigBlockSize()
- );
+ ).get();
_header.writeData(baos);
getBlockAt(-1).put(baos.toByteArray());
diff --git a/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java b/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java
index 9dec8e6ca6..c89b650452 100644
--- a/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java
+++ b/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java
@@ -233,7 +233,11 @@ public class VBAMacroReader implements Closeable {
} else {
// Decompress a previously found module and store the decompressed result into module.buf
InputStream stream = new RLEDecompressingInputStream(
- new UnsynchronizedByteArrayInputStream(module.buf, moduleOffset, module.buf.length - moduleOffset)
+ UnsynchronizedByteArrayInputStream.builder().
+ setByteArray(module.buf).
+ setOffset(moduleOffset).
+ setLength(module.buf.length - moduleOffset).
+ get()
);
module.read(stream);
stream.close();
@@ -275,7 +279,7 @@ public class VBAMacroReader implements Closeable {
}
if (decompressedBytes != null) {
- module.read(new UnsynchronizedByteArrayInputStream(decompressedBytes));
+ module.read(UnsynchronizedByteArrayInputStream.builder().setByteArray(decompressedBytes).get());
}
}
@@ -668,7 +672,7 @@ public class VBAMacroReader implements Closeable {
private static String readUnicode(InputStream is) throws IOException {
//reads null-terminated unicode string
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
int b0 = IOUtils.readByte(is);
int b1 = IOUtils.readByte(is);
@@ -688,7 +692,7 @@ public class VBAMacroReader implements Closeable {
}
private static String readMBCS(int firstByte, InputStream is, Charset charset) throws IOException {
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
int len = 0;
int b = firstByte;
while (b > 0 && len < MAX_STRING_LENGTH) {
@@ -802,7 +806,11 @@ public class VBAMacroReader implements Closeable {
if (w <= 0 || (w & 0x7000) != 0x3000) {
continue;
}
- decompressed = tryToDecompress(new UnsynchronizedByteArrayInputStream(compressed, i, compressed.length - i));
+ decompressed = tryToDecompress(UnsynchronizedByteArrayInputStream.builder().
+ setByteArray(compressed).
+ setOffset(i).
+ setLength(compressed.length - i).
+ get());
if (decompressed != null) {
if (decompressed.length > 9) {
//this is a complete hack. The challenge is that there
diff --git a/poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java b/poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java
index 14bd636e84..b7ea54ddf5 100644
--- a/poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java
+++ b/poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java
@@ -85,7 +85,7 @@ public class BitmapImageRenderer implements ImageRenderer {
public void loadImage(InputStream data, String contentType) throws IOException {
InputStream in = data;
if (doCache) {
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
IOUtils.copy(data, bos);
cachedImage = bos.toByteArray();
cachedContentType = contentType;
@@ -104,7 +104,7 @@ public class BitmapImageRenderer implements ImageRenderer {
cachedImage = data.clone();
cachedContentType = contentType;
}
- img = readImage(new UnsynchronizedByteArrayInputStream(data), contentType);
+ img = readImage(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get(), contentType);
}
/**
diff --git a/poi/src/main/java/org/apache/poi/sl/image/ImageHeaderBitmap.java b/poi/src/main/java/org/apache/poi/sl/image/ImageHeaderBitmap.java
index 9f7564cfe2..f16fe436e1 100644
--- a/poi/src/main/java/org/apache/poi/sl/image/ImageHeaderBitmap.java
+++ b/poi/src/main/java/org/apache/poi/sl/image/ImageHeaderBitmap.java
@@ -38,7 +38,7 @@ public class ImageHeaderBitmap {
public ImageHeaderBitmap(byte[] data, int offset) {
BufferedImage img = null;
try {
- img = ImageIO.read(new UnsynchronizedByteArrayInputStream(data, offset, data.length-offset));
+ img = ImageIO.read(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).setOffset(offset).setLength(data.length-offset).get());
} catch (IOException e) {
LOG.atWarn().withThrowable(e).log("Can't determine image dimensions");
}
diff --git a/poi/src/main/java/org/apache/poi/sl/usermodel/ObjectShape.java b/poi/src/main/java/org/apache/poi/sl/usermodel/ObjectShape.java
index 3c36c77827..8f6bd803e4 100644
--- a/poi/src/main/java/org/apache/poi/sl/usermodel/ObjectShape.java
+++ b/poi/src/main/java/org/apache/poi/sl/usermodel/ObjectShape.java
@@ -96,7 +96,7 @@ public interface ObjectShape<
final Application app = Application.lookup(progId);
- try (final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ try (final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
final InputStream is = FileMagic.prepareToCheckMagic(readObjectDataRaw())) {
final FileMagic fm = FileMagic.valueOf(is);
diff --git a/poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java b/poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java
index bdaccb7d6c..31c6632c07 100644
--- a/poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java
+++ b/poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java
@@ -177,7 +177,7 @@ public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> {
protected EmbeddedData extract(DirectoryNode dn) throws IOException {
assert(canExtract(dn));
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(20000);
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(20000).get();
POIFSFileSystem dest = new POIFSFileSystem()) {
copyNodes(dn, dest.getRoot());
// start with a reasonable big size
@@ -218,7 +218,7 @@ public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> {
@Override
public EmbeddedData extract(DirectoryNode dn) throws IOException {
- try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
InputStream is = dn.createDocumentInputStream("CONTENTS")) {
IOUtils.copy(is, bos);
return new EmbeddedData(dn.getName() + ".pdf", bos.toByteArray(), CONTENT_TYPE_PDF);
diff --git a/poi/src/main/java/org/apache/poi/ss/util/ImageUtils.java b/poi/src/main/java/org/apache/poi/ss/util/ImageUtils.java
index adb426d358..18f162395f 100644
--- a/poi/src/main/java/org/apache/poi/ss/util/ImageUtils.java
+++ b/poi/src/main/java/org/apache/poi/ss/util/ImageUtils.java
@@ -143,6 +143,7 @@ public final class ImageUtils {
* @param scaleY the amount by which image height is multiplied relative to the original height.
* @return the new Dimensions of the scaled picture in EMUs
* @throws IllegalArgumentException if scale values lead to negative or infinite results
+ * @throws IllegalStateException if the picture data is corrupt
*/
public static Dimension setPreferredSize(Picture picture, double scaleX, double scaleY) {
ClientAnchor anchor = picture.getClientAnchor();
@@ -151,9 +152,15 @@ public final class ImageUtils {
Sheet sheet = picture.getSheet();
// in pixel
- final Dimension imgSize = (scaleX == Double.MAX_VALUE || scaleY == Double.MAX_VALUE)
- ? getImageDimension(new UnsynchronizedByteArrayInputStream(data.getData()), data.getPictureType())
- : new Dimension();
+ final Dimension imgSize;
+ try {
+ imgSize = (scaleX == Double.MAX_VALUE || scaleY == Double.MAX_VALUE)
+ ? getImageDimension(UnsynchronizedByteArrayInputStream.builder().setByteArray(data.getData()).get(), data.getPictureType())
+ : new Dimension();
+ } catch (IOException e) {
+ // is actually impossible with ByteArray, but still declared in the interface
+ throw new IllegalStateException(e);
+ }
// in emus
final Dimension anchorSize = (scaleX != Double.MAX_VALUE || scaleY != Double.MAX_VALUE)
@@ -192,7 +199,12 @@ public final class ImageUtils {
Dimension imgSize = null;
if (anchor.getCol2() < anchor.getCol1() || anchor.getRow2() < anchor.getRow1()) {
PictureData data = picture.getPictureData();
- imgSize = getImageDimension(new UnsynchronizedByteArrayInputStream(data.getData()), data.getPictureType());
+ try {
+ imgSize = getImageDimension(UnsynchronizedByteArrayInputStream.builder().setByteArray(data.getData()).get(), data.getPictureType());
+ } catch (IOException e) {
+ // not possible with ByteArray but still declared in the API
+ throw new IllegalStateException(e);
+ }
}
int w = getDimFromCell(imgSize == null ? 0 : imgSize.getWidth(), anchor.getCol1(), anchor.getDx1(), anchor.getCol2(), anchor.getDx2(),
diff --git a/poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java b/poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java
index 370a02f672..7b24b774f6 100644
--- a/poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java
+++ b/poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java
@@ -19,8 +19,6 @@
package org.apache.poi.util;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
-
import java.awt.Color;
import java.awt.geom.AffineTransform;
import java.awt.geom.Dimension2D;
@@ -55,6 +53,7 @@ import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.poi.common.usermodel.GenericRecord;
import org.apache.poi.util.GenericRecordUtil.AnnotatedFlag;
@@ -117,7 +116,7 @@ public class GenericRecordJsonWriter implements Closeable {
protected int childIndex = 0;
public GenericRecordJsonWriter(File fileName) throws IOException {
- OutputStream os = ("null".equals(fileName.getName())) ? NULL_OUTPUT_STREAM : new FileOutputStream(fileName);
+ OutputStream os = ("null".equals(fileName.getName())) ? NullOutputStream.INSTANCE : new FileOutputStream(fileName);
aw = new AppendableWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));
fw = new PrintWriter(aw);
}
diff --git a/poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java b/poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java
index b812a3d31c..ba098965d3 100644
--- a/poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java
+++ b/poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java
@@ -19,8 +19,6 @@
package org.apache.poi.util;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
-
import java.awt.Color;
import java.awt.geom.AffineTransform;
import java.awt.geom.Dimension2D;
@@ -50,6 +48,7 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.poi.common.usermodel.GenericRecord;
import org.apache.poi.util.GenericRecordJsonWriter.AppendableWriter;
@@ -109,7 +108,7 @@ public class GenericRecordXmlWriter implements Closeable {
private boolean attributePhase = true;
public GenericRecordXmlWriter(File fileName) throws IOException {
- OutputStream os = ("null".equals(fileName.getName())) ? NULL_OUTPUT_STREAM : new FileOutputStream(fileName);
+ OutputStream os = ("null".equals(fileName.getName())) ? NullOutputStream.INSTANCE : new FileOutputStream(fileName);
fw = new PrintWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));
}
diff --git a/poi/src/main/java/org/apache/poi/util/IOUtils.java b/poi/src/main/java/org/apache/poi/util/IOUtils.java
index 6dd510fe39..51281d4bba 100644
--- a/poi/src/main/java/org/apache/poi/util/IOUtils.java
+++ b/poi/src/main/java/org/apache/poi/util/IOUtils.java
@@ -141,7 +141,7 @@ public final class IOUtils {
checkByteSizeLimit(limit);
stream.mark(limit);
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(limit)) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(limit).get()) {
copy(new BoundedInputStream(stream, limit), bos);
int readBytes = bos.size();
@@ -238,7 +238,7 @@ public final class IOUtils {
final int derivedLen = isLengthKnown ? Math.min(length, derivedMaxLength) : derivedMaxLength;
final int byteArrayInitLen = calculateByteArrayInitLength(isLengthKnown, length, derivedMaxLength);
final int internalBufferLen = DEFAULT_BUFFER_SIZE;
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(byteArrayInitLen)) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(byteArrayInitLen).get()) {
byte[] buffer = new byte[internalBufferLen];
int totalBytes = 0, readBytes;
do {
diff --git a/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java b/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java
index a883ee3abb..3bbec57f50 100644
--- a/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java
+++ b/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java
@@ -102,7 +102,7 @@ public abstract class LZWDecompresser {
* of the decompressed input.
*/
public byte[] decompress(InputStream src) throws IOException {
- UnsynchronizedByteArrayOutputStream res = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream res = UnsynchronizedByteArrayOutputStream.builder().get();
decompress(src, res);
return res.toByteArray();
}
diff --git a/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java b/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java
index b59950b96c..55ba486407 100644
--- a/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java
+++ b/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java
@@ -277,8 +277,8 @@ public class RLEDecompressingInputStream extends InputStream {
}
public static byte[] decompress(byte[] compressed, int offset, int length) throws IOException {
- try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
- InputStream instream = new UnsynchronizedByteArrayInputStream(compressed, offset, length);
+ try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
+ InputStream instream = UnsynchronizedByteArrayInputStream.builder().setByteArray(compressed).setOffset(offset).setLength(length).get();
InputStream stream = new RLEDecompressingInputStream(instream)) {
IOUtils.copy(stream, out);
diff --git a/poi/src/test/java/org/apache/poi/POIDataSamples.java b/poi/src/test/java/org/apache/poi/POIDataSamples.java
index 3e04fc8976..d96e2f264e 100644
--- a/poi/src/test/java/org/apache/poi/POIDataSamples.java
+++ b/poi/src/test/java/org/apache/poi/POIDataSamples.java
@@ -264,7 +264,7 @@ public final class POIDataSamples {
*/
public byte[] readFile(String fileName) {
try (InputStream fis = openResourceAsStream(fileName);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
IOUtils.copy(fis, bos);
return bos.toByteArray();
} catch (IOException e) {
@@ -273,7 +273,7 @@ public final class POIDataSamples {
}
public static POIFSFileSystem writeOutAndReadBack(POIFSFileSystem original) throws IOException {
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
original.writeFilesystem(baos);
return new POIFSFileSystem(baos.toInputStream());
}
diff --git a/poi/src/test/java/org/apache/poi/TestPOIDocumentMain.java b/poi/src/test/java/org/apache/poi/TestPOIDocumentMain.java
index 78fd9db41b..24f0063916 100644
--- a/poi/src/test/java/org/apache/poi/TestPOIDocumentMain.java
+++ b/poi/src/test/java/org/apache/poi/TestPOIDocumentMain.java
@@ -87,7 +87,7 @@ final class TestPOIDocumentMain {
@Test
void WriteReadProperties() throws IOException {
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
// Write them out
try (POIDocument xls = openSampleWorkbook("DateFormats.xls");
diff --git a/poi/src/test/java/org/apache/poi/ddf/TestEscherDump.java b/poi/src/test/java/org/apache/poi/ddf/TestEscherDump.java
index 07c67c4c10..635af68dde 100644
--- a/poi/src/test/java/org/apache/poi/ddf/TestEscherDump.java
+++ b/poi/src/test/java/org/apache/poi/ddf/TestEscherDump.java
@@ -64,7 +64,7 @@ class TestEscherDump {
"eJr+iZEHAAA=";
private final EscherDump dumper = new EscherDump();
- private final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ private final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
private PrintStream stream;
@BeforeEach
diff --git a/poi/src/test/java/org/apache/poi/hpsf/basic/TestHPSFBugs.java b/poi/src/test/java/org/apache/poi/hpsf/basic/TestHPSFBugs.java
index bd86d39cc2..e3fb4d30b1 100644
--- a/poi/src/test/java/org/apache/poi/hpsf/basic/TestHPSFBugs.java
+++ b/poi/src/test/java/org/apache/poi/hpsf/basic/TestHPSFBugs.java
@@ -121,7 +121,7 @@ final class TestHPSFBugs {
// Write out and read back, should still be valid
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (POIDocument doc = new HPSFPropertiesOnlyDocument(fs)) {
doc.write(baos);
}
diff --git a/poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java b/poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java
index 0bf0b99ce7..0f7d88939d 100644
--- a/poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java
+++ b/poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java
@@ -527,7 +527,7 @@ final class TestMetaDataIPI {
dsi.write(poifs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
si.write(poifs.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME);
- UnsynchronizedByteArrayOutputStream bout = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bout = UnsynchronizedByteArrayOutputStream.builder().get();
poifs.writeFilesystem(bout);
poifs.close();
diff --git a/poi/src/test/java/org/apache/poi/hpsf/basic/TestReadAllFiles.java b/poi/src/test/java/org/apache/poi/hpsf/basic/TestReadAllFiles.java
index 057e16ae87..4cf5a31eb7 100644
--- a/poi/src/test/java/org/apache/poi/hpsf/basic/TestReadAllFiles.java
+++ b/poi/src/test/java/org/apache/poi/hpsf/basic/TestReadAllFiles.java
@@ -101,7 +101,7 @@ class TestReadAllFiles {
/* Create a new POI filesystem containing the origin file's
* property set streams: */
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (POIFSFileSystem poiFs = new POIFSFileSystem()) {
for (POIFile poifile : Util.readPropertySets(file)) {
final InputStream in = new ByteArrayInputStream(poifile.getBytes());
diff --git a/poi/src/test/java/org/apache/poi/hpsf/basic/TestWrite.java b/poi/src/test/java/org/apache/poi/hpsf/basic/TestWrite.java
index 5af30cd978..48b8b594ec 100644
--- a/poi/src/test/java/org/apache/poi/hpsf/basic/TestWrite.java
+++ b/poi/src/test/java/org/apache/poi/hpsf/basic/TestWrite.java
@@ -110,7 +110,7 @@ class TestWrite {
/* Write it to a POIFS and the latter to disk: */
try (OutputStream out = new FileOutputStream(filename);
POIFSFileSystem poiFs = new POIFSFileSystem();
- UnsynchronizedByteArrayOutputStream psStream = new UnsynchronizedByteArrayOutputStream()) {
+ UnsynchronizedByteArrayOutputStream psStream = UnsynchronizedByteArrayOutputStream.builder().get()) {
assertThrows(NoFormatIDException.class, () -> ps.write(psStream));
poiFs.createDocument(psStream.toInputStream(), SummaryInformation.DEFAULT_STREAM_NAME);
poiFs.writeFilesystem(out);
@@ -132,7 +132,7 @@ class TestWrite {
/* Create a mutable property set and write it to a POIFS: */
try (OutputStream out = new FileOutputStream(filename);
POIFSFileSystem poiFs = new POIFSFileSystem();
- UnsynchronizedByteArrayOutputStream psStream = new UnsynchronizedByteArrayOutputStream()) {
+ UnsynchronizedByteArrayOutputStream psStream = UnsynchronizedByteArrayOutputStream.builder().get()) {
final PropertySet ps = new PropertySet();
final Section s = ps.getSections().get(0);
s.setFormatID(SummaryInformation.FORMAT_ID);
@@ -343,7 +343,7 @@ class TestWrite {
p.setValue(TITLE);
ms.setProperty(p);
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
mps.write(out);
byte[] bytes = out.toByteArray();
@@ -373,7 +373,7 @@ class TestWrite {
private void check(final long variantType, final Object value, final int codepage)
throws UnsupportedVariantTypeException, IOException
{
- final UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ final UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
VariantSupport.write(out, variantType, value, codepage);
final byte[] b = out.toByteArray();
final Object objRead =
@@ -526,9 +526,9 @@ class TestWrite {
doufStream.close();
// And also write to some bytes for checking
- UnsynchronizedByteArrayOutputStream sinfBytes = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream sinfBytes = UnsynchronizedByteArrayOutputStream.builder().get();
sinf.write(sinfBytes);
- UnsynchronizedByteArrayOutputStream dinfBytes = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream dinfBytes = UnsynchronizedByteArrayOutputStream.builder().get();
dinf.write(dinfBytes);
diff --git a/poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java b/poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java
index 29cf6852aa..e85ff044ab 100644
--- a/poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java
+++ b/poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java
@@ -55,7 +55,7 @@ public final class HSSFTestDataSamples {
* Useful for verifying that the serialisation round trip
*/
public static HSSFWorkbook writeOutAndReadBack(HSSFWorkbook original) {
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
original.write(baos);
try (InputStream is = baos.toInputStream()) {
return new HSSFWorkbook(is);
diff --git a/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java b/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java
index f36e24d562..0d42a7ba42 100644
--- a/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java
+++ b/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java
@@ -135,7 +135,7 @@ final class TestEventRecordFactory {
*/
@Test
void testContinuedUnknownRecord() throws IOException {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
for (byte[] b : CONTINUE_DATA) {
bos.write(b);
}
diff --git a/poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java b/poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
index 3121ee039d..91c7a36513 100644
--- a/poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
+++ b/poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
@@ -314,7 +314,7 @@ final class TestOldExcelExtractor {
SecurityManager sm = System.getSecurityManager();
System.setSecurityManager(new NoExitSecurityManager());
try {
- System.setErr(new NullPrintStream());
+ System.setErr(NullPrintStream.INSTANCE);
// calls System.exit()
assertThrows(ExitException.class, () -> OldExcelExtractor.main(new String[]{}));
} finally {
@@ -328,7 +328,7 @@ final class TestOldExcelExtractor {
void testMain() throws IOException {
File file = HSSFTestDataSamples.getSampleFile("testEXCEL_3.xls");
PrintStream save = System.out;
- try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
PrintStream str = new PrintStream(out, false, StandardCharsets.UTF_8.displayName(LocaleUtil.getUserLocale()))) {
System.setOut(str);
OldExcelExtractor.main(new String[] {file.getAbsolutePath()});
diff --git a/poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java b/poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java
index 6b99428aea..b904af8808 100644
--- a/poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java
+++ b/poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java
@@ -114,7 +114,7 @@ class TestDrawingAggregate {
* @return the raw data being aggregated
*/
byte[] getRawBytes(){
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
for (RecordBase rb : aggRecords) {
Record r = (org.apache.poi.hssf.record.Record) rb;
try {
@@ -222,7 +222,7 @@ class TestDrawingAggregate {
assertEquals(dgBytes.length, pos, "data was not fully read");
// serialize to byte array
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
for(EscherRecord r : records) {
out.write(r.serialize());
}
@@ -248,7 +248,7 @@ class TestDrawingAggregate {
}
private static byte[] toByteArray(List<RecordBase> records) {
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
for (RecordBase rb : records) {
Record r = (org.apache.poi.hssf.record.Record) rb;
try {
diff --git a/poi/src/test/java/org/apache/poi/hssf/model/TestEscherRecordFactory.java b/poi/src/test/java/org/apache/poi/hssf/model/TestEscherRecordFactory.java
index 69566e59f5..091802098c 100644
--- a/poi/src/test/java/org/apache/poi/hssf/model/TestEscherRecordFactory.java
+++ b/poi/src/test/java/org/apache/poi/hssf/model/TestEscherRecordFactory.java
@@ -39,7 +39,7 @@ import org.junit.jupiter.api.Test;
class TestEscherRecordFactory {
private static byte[] toByteArray(List<RecordBase> records) {
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
for (RecordBase rb : records) {
Record r = (org.apache.poi.hssf.record.Record) rb;
try {
diff --git a/poi/src/test/java/org/apache/poi/hssf/record/TestDConRefRecord.java b/poi/src/test/java/org/apache/poi/hssf/record/TestDConRefRecord.java
index 466f596650..91bf456816 100644
--- a/poi/src/test/java/org/apache/poi/hssf/record/TestDConRefRecord.java
+++ b/poi/src/test/java/org/apache/poi/hssf/record/TestDConRefRecord.java
@@ -209,7 +209,7 @@ class TestDConRefRecord {
private void testReadWrite(byte[] data, String message) throws IOException {
RecordInputStream is = TestcaseRecordInputStream.create(81, data);
DConRefRecord d = new DConRefRecord(is);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(data.length);
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(data.length).get();
LittleEndianOutputStream o = new LittleEndianOutputStream(bos);
d.serialize(o);
o.flush();
diff --git a/poi/src/test/java/org/apache/poi/hssf/record/TestDrawingRecord.java b/poi/src/test/java/org/apache/poi/hssf/record/TestDrawingRecord.java
index d519393c8c..f0df67af50 100644
--- a/poi/src/test/java/org/apache/poi/hssf/record/TestDrawingRecord.java
+++ b/poi/src/test/java/org/apache/poi/hssf/record/TestDrawingRecord.java
@@ -38,7 +38,7 @@ final class TestDrawingRecord {
void testReadContinued() throws IOException {
//simulate a continues drawing record
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
//main part
DrawingRecord dg = new DrawingRecord();
byte[] data1 = new byte[8224];
diff --git a/poi/src/test/java/org/apache/poi/hssf/record/TestLbsDataSubRecord.java b/poi/src/test/java/org/apache/poi/hssf/record/TestLbsDataSubRecord.java
index 005d03d6ef..53e1229537 100644
--- a/poi/src/test/java/org/apache/poi/hssf/record/TestLbsDataSubRecord.java
+++ b/poi/src/test/java/org/apache/poi/hssf/record/TestLbsDataSubRecord.java
@@ -166,7 +166,7 @@ final class TestLbsDataSubRecord {
try (LittleEndianInputStream in = new LittleEndianInputStream(new ByteArrayInputStream(data))) {
LbsDataSubRecord.LbsDropData lbs = new LbsDataSubRecord.LbsDropData(in);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (LittleEndianOutputStream out = new LittleEndianOutputStream(baos)) {
lbs.serialize(out);
diff --git a/poi/src/test/java/org/apache/poi/hssf/record/TestRecordFactory.java b/poi/src/test/java/org/apache/poi/hssf/record/TestRecordFactory.java
index e9737324e8..26793e1930 100644
--- a/poi/src/test/java/org/apache/poi/hssf/record/TestRecordFactory.java
+++ b/poi/src/test/java/org/apache/poi/hssf/record/TestRecordFactory.java
@@ -185,7 +185,7 @@ final class TestRecordFactory {
assertTrue(records.get(4) instanceof ObjRecord);
//serialize and verify that the serialized data is the same as the original
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
for(org.apache.poi.hssf.record.Record rec : records){
out.write(rec.serialize());
}
@@ -204,7 +204,7 @@ final class TestRecordFactory {
BOFRecord.createSheetBOF(),
EOFRecord.instance,
};
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
for (org.apache.poi.hssf.record.Record rec : recs) {
try {
baos.write(rec.serialize());
diff --git a/poi/src/test/java/org/apache/poi/hssf/record/TestSSTRecord.java b/poi/src/test/java/org/apache/poi/hssf/record/TestSSTRecord.java
index eed605b661..da90507400 100644
--- a/poi/src/test/java/org/apache/poi/hssf/record/TestSSTRecord.java
+++ b/poi/src/test/java/org/apache/poi/hssf/record/TestSSTRecord.java
@@ -49,7 +49,7 @@ final class TestSSTRecord {
*/
private static byte[] concatHexDumps(String... hexDumpFileNames) throws IOException {
int nFiles = hexDumpFileNames.length;
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(nFiles * 8228);
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(nFiles * 8228).get();
for (String sampleFileName : hexDumpFileNames) {
try (InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName)) {
BufferedReader br = new BufferedReader(new InputStreamReader(is, LocaleUtil.CHARSET_1252));
diff --git a/poi/src/test/java/org/apache/poi/hssf/record/common/TestUnicodeString.java b/poi/src/test/java/org/apache/poi/hssf/record/common/TestUnicodeString.java
index 57b344bd25..8abd514c6c 100644
--- a/poi/src/test/java/org/apache/poi/hssf/record/common/TestUnicodeString.java
+++ b/poi/src/test/java/org/apache/poi/hssf/record/common/TestUnicodeString.java
@@ -185,7 +185,7 @@ final class TestUnicodeString {
assertEquals(4, fr.getCharacterPos());
assertEquals(0x15c, fr.getFontIndex());
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
LittleEndianOutputStream out = new LittleEndianOutputStream(baos);
fr.serialize(out);
@@ -216,7 +216,7 @@ final class TestUnicodeString {
assertEquals(0, ext.getPhRuns().length);
assertEquals(10, ext.getDataSize()); // Excludes 4 byte header
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
LittleEndianOutputStream out = new LittleEndianOutputStream(baos);
ContinuableRecordOutput cout = new ContinuableRecordOutput(out, 0xffff);
diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestBugs.java b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestBugs.java
index b29c4bc3ee..b836e3269c 100644
--- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestBugs.java
+++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestBugs.java
@@ -1175,9 +1175,9 @@ final class TestBugs extends BaseTestBugzillaIssues {
@Test
void bug32191() throws IOException {
try (HSSFWorkbook wb = openSampleWorkbook("27394.xls");
- UnsynchronizedByteArrayOutputStream out1 = new UnsynchronizedByteArrayOutputStream();
- UnsynchronizedByteArrayOutputStream out2 = new UnsynchronizedByteArrayOutputStream();
- UnsynchronizedByteArrayOutputStream out3 = new UnsynchronizedByteArrayOutputStream()) {
+ UnsynchronizedByteArrayOutputStream out1 = UnsynchronizedByteArrayOutputStream.builder().get();
+ UnsynchronizedByteArrayOutputStream out2 = UnsynchronizedByteArrayOutputStream.builder().get();
+ UnsynchronizedByteArrayOutputStream out3 = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(out1);
wb.write(out2);
wb.write(out3);
@@ -2331,7 +2331,7 @@ final class TestBugs extends BaseTestBugzillaIssues {
}
// Convert BufferedImage to byte[]
- UnsynchronizedByteArrayOutputStream imageBAOS = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream imageBAOS = UnsynchronizedByteArrayOutputStream.builder().get();
ImageIO.write(bimage, "jpeg", imageBAOS);
imageBAOS.flush();
byte[] imageBytes = imageBAOS.toByteArray();
@@ -2614,7 +2614,7 @@ final class TestBugs extends BaseTestBugzillaIssues {
void test66319() throws IOException {
try (
HSSFWorkbook workbook = openSampleWorkbook("bug66319.xls");
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
for (Sheet sheet : workbook) {
for (Row row : sheet) {
@@ -2631,7 +2631,7 @@ final class TestBugs extends BaseTestBugzillaIssues {
void test66319WithRemove() throws IOException {
try (
HSSFWorkbook workbook = openSampleWorkbook("bug66319.xls");
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
for (Sheet sheet : workbook) {
for (Row row : sheet) {
diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestDataValidation.java b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestDataValidation.java
index b978581ee2..f5a0f1620d 100644
--- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestDataValidation.java
+++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestDataValidation.java
@@ -61,7 +61,7 @@ final class TestDataValidation extends BaseTestDataValidation {
void assertDataValidation(Workbook wb) {
byte[] generatedContent;
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(22000)) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(22000).get()) {
wb.write(baos);
generatedContent = baos.toByteArray();
} catch (IOException e) {
@@ -133,7 +133,7 @@ final class TestDataValidation extends BaseTestDataValidation {
sheet.addValidationData(dv);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
wb.write(baos);
byte[] wbData = baos.toByteArray();
diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFCell.java b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFCell.java
index b4ea25eddc..48ef715a92 100644
--- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFCell.java
+++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFCell.java
@@ -422,7 +422,7 @@ final class TestHSSFCell extends BaseTestCell {
void setFillForegroundColor() throws IOException {
try (
HSSFWorkbook wb = new HSSFWorkbook();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
Cell cell = wb.createSheet().createRow(0).createCell(0);
HSSFCellStyle cellStyle = wb.createCellStyle();
diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
index 3cd5b70382..6b9a1575f6 100644
--- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
+++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
@@ -559,7 +559,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
HSSFWorkbook wb = new HSSFWorkbook(fs1)) {
ClassID clsid1 = fs1.getRoot().getStorageClsid();
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(4096);
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(4096).get();
wb.write(out);
try (POIFSFileSystem fs2 = new POIFSFileSystem(out.toInputStream())) {
ClassID clsid2 = fs2.getRoot().getStorageClsid();
@@ -974,7 +974,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
assertNotNull(name);
assertEquals("ASheet!A1", name.getRefersToFormula());
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().get();
wb.write(stream);
assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3", "ASheet");
@@ -985,7 +985,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
assertSheetOrder(wb, "Sheet1", "Sheet3", "ASheet");
assertEquals("ASheet!A1", name.getRefersToFormula());
- UnsynchronizedByteArrayOutputStream stream2 = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream stream2 = UnsynchronizedByteArrayOutputStream.builder().get();
wb.write(stream2);
assertSheetOrder(wb, "Sheet1", "Sheet3", "ASheet");
@@ -1074,7 +1074,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
private void writeAndCloseWorkbook(Workbook workbook, File file)
throws IOException {
- final UnsynchronizedByteArrayOutputStream bytesOut = new UnsynchronizedByteArrayOutputStream();
+ final UnsynchronizedByteArrayOutputStream bytesOut = UnsynchronizedByteArrayOutputStream.builder().get();
workbook.write(bytesOut);
workbook.close();
@@ -1182,7 +1182,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
@Test
void checkExistingFileForR1C1Refs() throws IOException {
try (
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
HSSFWorkbook wb = openSampleWorkbook("49423.xls")
) {
assertEquals(CellReferenceType.A1, wb.getCellReferenceType());
@@ -1198,7 +1198,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
@Test
void checkNewFileForR1C1Refs() throws IOException {
try (
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
HSSFWorkbook wb = new HSSFWorkbook()
) {
assertEquals(CellReferenceType.UNKNOWN, wb.getCellReferenceType());
diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestOLE2Embedding.java b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestOLE2Embedding.java
index ca892b9ca8..cd96d6c605 100644
--- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestOLE2Embedding.java
+++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestOLE2Embedding.java
@@ -105,7 +105,7 @@ final class TestOLE2Embedding {
circle.setNoFill(true);
try (HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1)) {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
HSSFObjectData od = wb2.getAllEmbeddedObjects().get(0);
Ole10Native ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode) od.getDirectory());
bos.reset();
@@ -135,7 +135,7 @@ final class TestOLE2Embedding {
}
static POIFSFileSystem getSampleXLS() throws IOException {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFSheet sheet = wb.createSheet();
sheet.createRow(5).createCell(2).setCellValue("yo dawg i herd you like embeddet objekts, so we put an ole in your ole so you can save a file while you save a file");
diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java
index 5ff7c4e5ca..2bc2da0a1c 100644
--- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java
+++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java
@@ -42,7 +42,7 @@ class TestPOIFSProperties {
@Test
void testFail() throws IOException, NoPropertySetStreamException, WritingNotSupportedException {
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
// read the workbook, adjust the SummaryInformation and write the data to a byte array
try (POIFSFileSystem fs = openFileSystem();
HSSFWorkbook wb = new HSSFWorkbook(fs)) {
@@ -61,7 +61,7 @@ class TestPOIFSProperties {
@Test
void testOK() throws Exception {
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
// read the workbook, adjust the SummaryInformation and write the data to a byte array
try (POIFSFileSystem fs = openFileSystem()) {
diff --git a/poi/src/test/java/org/apache/poi/poifs/crypt/agile/TestAgileDecryptor.java b/poi/src/test/java/org/apache/poi/poifs/crypt/agile/TestAgileDecryptor.java
index 0d08b232bf..2ee6ba30e1 100644
--- a/poi/src/test/java/org/apache/poi/poifs/crypt/agile/TestAgileDecryptor.java
+++ b/poi/src/test/java/org/apache/poi/poifs/crypt/agile/TestAgileDecryptor.java
@@ -69,7 +69,7 @@ class TestAgileDecryptor {
os.write(testData);
}
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
fsEnc.writeFilesystem(bos);
bos.close();
diff --git a/poi/src/test/java/org/apache/poi/poifs/dev/TestPOIFSDump.java b/poi/src/test/java/org/apache/poi/poifs/dev/TestPOIFSDump.java
index ad58573764..e13f205c40 100644
--- a/poi/src/test/java/org/apache/poi/poifs/dev/TestPOIFSDump.java
+++ b/poi/src/test/java/org/apache/poi/poifs/dev/TestPOIFSDump.java
@@ -51,7 +51,7 @@ public class TestPOIFSDump {
@BeforeAll
public static void setUp() throws UnsupportedEncodingException {
SYSTEM = System.out;
- System.setOut(new NullPrintStream());
+ System.setOut(NullPrintStream.INSTANCE);
}
@AfterAll
diff --git a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocument.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocument.java
index 4994d5db98..94bc700be3 100644
--- a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocument.java
+++ b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocument.java
@@ -68,7 +68,7 @@ class TestDocument {
// verify that output is correct
POIFSDocument document = checkDocument(poifs, LARGER_BIG_BLOCK_SIZE + 1);
DocumentProperty property = document.getDocumentProperty();
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().get();
property.writeData(stream);
byte[] output = stream.toByteArray();
@@ -135,7 +135,7 @@ class TestDocument {
assertEquals(blockCountExp, blockCountAct);
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().get();
try (DocumentInputStream dis = document.getFileSystem().createDocumentInputStream(
document.getDocumentProperty().getName())) {
IOUtils.copy(dis, stream);
diff --git a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java
index 8674a41d15..bd1da88a7c 100644
--- a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java
+++ b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java
@@ -97,7 +97,7 @@ final class TestDocumentOutputStream {
root.createDocument("foo", expected.length, l);
try (DocumentInputStream is = root.createDocumentInputStream("foo")) {
- final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(expected.length);
+ final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(expected.length).get();
IOUtils.copy(is, bos);
assertArrayEquals(expected, bos.toByteArray());
}
diff --git a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEmptyDocument.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEmptyDocument.java
index a2da085b01..f60ce5bc3b 100644
--- a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEmptyDocument.java
+++ b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEmptyDocument.java
@@ -82,7 +82,7 @@ final class TestEmptyDocument {
DirectoryEntry dir = fs.getRoot();
emptyDoc.handle(dir);
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
fs.writeFilesystem(out);
assertDoesNotThrow(() -> new POIFSFileSystem(out.toInputStream()));
}
@@ -92,7 +92,7 @@ final class TestEmptyDocument {
void testEmptyDocumentBug11744() throws Exception {
byte[] testData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
try (POIFSFileSystem fs = new POIFSFileSystem()) {
fs.createDocument(new ByteArrayInputStream(new byte[0]), "Empty");
fs.createDocument(new ByteArrayInputStream(testData), "NotEmpty");
diff --git a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEntryUtils.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEntryUtils.java
index e2abb090ab..16fa1fd240 100644
--- a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEntryUtils.java
+++ b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEntryUtils.java
@@ -125,7 +125,7 @@ class TestEntryUtils {
// Can work with POIFS
- try (UnsynchronizedByteArrayOutputStream tmpO = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream tmpO = UnsynchronizedByteArrayOutputStream.builder().get()) {
fs.writeFilesystem(tmpO);
try (InputStream tmpI = tmpO.toInputStream();
diff --git a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java
index dd52a10a58..a162dd8346 100644
--- a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java
+++ b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java
@@ -140,7 +140,7 @@ final class TestFileSystemBugs {
EntryUtils.copyNodes(root, dest);
// Re-load
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
root.getFileSystem().writeFilesystem(baos);
POIFSFileSystem read = new POIFSFileSystem(baos.toInputStream());
diff --git a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestOle10Native.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestOle10Native.java
index 3a3f2fa8dc..7a39eb4779 100644
--- a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestOle10Native.java
+++ b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestOle10Native.java
@@ -67,14 +67,14 @@ class TestOle10Native {
findOle10(entries, fs.getRoot(), "/");
for (Entry e : entries) {
- UnsynchronizedByteArrayOutputStream bosExp = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bosExp = UnsynchronizedByteArrayOutputStream.builder().get();
try (InputStream is = ((DirectoryNode) e.getParent()).createDocumentInputStream(e)) {
IOUtils.copy(is, bosExp);
}
Ole10Native ole = Ole10Native.createFromEmbeddedOleObject((DirectoryNode) e.getParent());
- UnsynchronizedByteArrayOutputStream bosAct = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bosAct = UnsynchronizedByteArrayOutputStream.builder().get();
ole.writeOut(bosAct);
assertThat(bosExp.toByteArray(), equalTo(bosAct.toByteArray()));
diff --git a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
index 886340091c..c7135da492 100644
--- a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
+++ b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
@@ -142,7 +142,7 @@ final class TestPOIFSFileSystem {
try (POIFSFileSystem fs = new POIFSFileSystem(_samples.openResourceAsStream(file))) {
// Write it into a temp output array
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
fs.writeFilesystem(baos);
// Check sizes
@@ -181,7 +181,7 @@ final class TestPOIFSFileSystem {
"BIG", new ByteArrayInputStream(hugeStream)
);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
fs.writeFilesystem(baos);
byte[] fsData = baos.toByteArray();
diff --git a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java
index 430cd8e5d2..4efcc80983 100644
--- a/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java
+++ b/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSStream.java
@@ -1190,7 +1190,7 @@ final class TestPOIFSStream {
}
private static HeaderBlock writeOutAndReadHeader(POIFSFileSystem fs) throws IOException {
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
fs.writeFilesystem(baos);
return new HeaderBlock(baos.toInputStream());
}
diff --git a/poi/src/test/java/org/apache/poi/poifs/property/TestDirectoryProperty.java b/poi/src/test/java/org/apache/poi/poifs/property/TestDirectoryProperty.java
index c200bbdee0..b503472db7 100644
--- a/poi/src/test/java/org/apache/poi/poifs/property/TestDirectoryProperty.java
+++ b/poi/src/test/java/org/apache/poi/poifs/property/TestDirectoryProperty.java
@@ -188,7 +188,7 @@ final class TestDirectoryProperty {
}
private void verifyProperty() throws IOException {
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(512);
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(512).get();
_property.writeData(stream);
byte[] output = stream.toByteArray();
@@ -254,7 +254,7 @@ final class TestDirectoryProperty {
private static void verifyReadingProperty(int index, byte[] input, int offset, String name) {
DirectoryProperty property = new DirectoryProperty(index, input, offset);
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(128);
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(128).get();
byte[] expected = Arrays.copyOfRange(input, offset, offset+128);
try {
property.writeData(stream);
diff --git a/poi/src/test/java/org/apache/poi/poifs/property/TestDocumentProperty.java b/poi/src/test/java/org/apache/poi/poifs/property/TestDocumentProperty.java
index 1bda3ab462..c72f0bdbfa 100644
--- a/poi/src/test/java/org/apache/poi/poifs/property/TestDocumentProperty.java
+++ b/poi/src/test/java/org/apache/poi/poifs/property/TestDocumentProperty.java
@@ -83,7 +83,7 @@ final class TestDocumentProperty {
throws IOException {
DocumentProperty property = new DocumentProperty(index, input,
offset);
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(128);
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(128).get();
byte[] expected = Arrays.copyOfRange(input, offset, offset+128);
property.writeData(stream);
byte[] output = stream.toByteArray();
@@ -145,7 +145,7 @@ final class TestDocumentProperty {
{
testblock[ index * 2 ] = name_bytes[ index ];
}
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(512);
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(512).get();
property.writeData(stream);
byte[] output = stream.toByteArray();
diff --git a/poi/src/test/java/org/apache/poi/poifs/property/TestPropertyTable.java b/poi/src/test/java/org/apache/poi/poifs/property/TestPropertyTable.java
index 64577b0c7c..b79a002f69 100644
--- a/poi/src/test/java/org/apache/poi/poifs/property/TestPropertyTable.java
+++ b/poi/src/test/java/org/apache/poi/poifs/property/TestPropertyTable.java
@@ -45,7 +45,7 @@ import org.junit.jupiter.api.Test;
final class TestPropertyTable {
private static void confirmBlockEncoding(String expectedDataStr, PropertyTable table) throws IOException {
- final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
byte[] expectedData = RawDataUtil.decompress(expectedDataStr);
POIFSStream stream = new POIFSStream(null) {
diff --git a/poi/src/test/java/org/apache/poi/poifs/property/TestRootProperty.java b/poi/src/test/java/org/apache/poi/poifs/property/TestRootProperty.java
index a210ac8d7c..3ab7e67561 100644
--- a/poi/src/test/java/org/apache/poi/poifs/property/TestRootProperty.java
+++ b/poi/src/test/java/org/apache/poi/poifs/property/TestRootProperty.java
@@ -42,7 +42,7 @@ final class TestRootProperty {
void testConstructor() throws IOException {
createBasicRootProperty();
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(512);
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(512).get();
_property.writeData(stream);
assertArrayEquals(_testblock, stream.toByteArray());
@@ -105,7 +105,7 @@ final class TestRootProperty {
int offset = 0;
RootProperty property = new RootProperty(index, input, offset);
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(128);
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(128).get();
byte[] expected = Arrays.copyOfRange(input, offset, offset+128);
property.writeData(stream);
byte[] output = stream.toByteArray();
diff --git a/poi/src/test/java/org/apache/poi/poifs/storage/RawDataUtil.java b/poi/src/test/java/org/apache/poi/poifs/storage/RawDataUtil.java
index af7ec4eaa1..7382c65778 100644
--- a/poi/src/test/java/org/apache/poi/poifs/storage/RawDataUtil.java
+++ b/poi/src/test/java/org/apache/poi/poifs/storage/RawDataUtil.java
@@ -37,7 +37,7 @@ public final class RawDataUtil {
public static byte[] decode(String[] hexDataLines) {
try (UnsynchronizedByteArrayOutputStream baos =
- new UnsynchronizedByteArrayOutputStream(hexDataLines.length * 32 + 32)) {
+ UnsynchronizedByteArrayOutputStream.builder().setBufferSize(hexDataLines.length * 32 + 32).get()) {
for (String hexDataLine : hexDataLines) {
byte[] lineData = HexRead.readFromString(hexDataLine);
baos.write(lineData, 0, lineData.length);
@@ -58,7 +58,7 @@ public final class RawDataUtil {
public static byte[] decompress(String data) throws IOException {
byte[] base64Bytes = Base64.getDecoder().decode(data);
try (
- InputStream is = new UnsynchronizedByteArrayInputStream(base64Bytes);
+ InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(base64Bytes).get();
GZIPInputStream gzis = new GZIPInputStream(is);
) {
return IOUtils.toByteArray(gzis);
@@ -74,7 +74,7 @@ public final class RawDataUtil {
*/
public static String compress(byte[] data) throws IOException {
try (
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
java.util.zip.GZIPOutputStream gz = new java.util.zip.GZIPOutputStream(bos)
) {
gz.write(data);
diff --git a/poi/src/test/java/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java b/poi/src/test/java/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java
index 02d84fac03..3073189952 100644
--- a/poi/src/test/java/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java
+++ b/poi/src/test/java/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java
@@ -133,7 +133,7 @@ public abstract class BaseTestSlideShowFactory {
}
private static byte[] readExternalFile(String path) {
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (InputStream fis = new FileInputStream(path)) {
byte[] buf = new byte[512];
diff --git a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
index 94db023cc1..ebcdb5baf2 100644
--- a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
+++ b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
@@ -1815,8 +1815,8 @@ public abstract class BaseTestBugzillaIssues {
cell.setCellValue("Ernie & Bert are cool!");
cell.setCellFormula("A1 & \" are cool!\"");
- try (UnsynchronizedByteArrayOutputStream out1 = new UnsynchronizedByteArrayOutputStream();
- UnsynchronizedByteArrayOutputStream out2 = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream out1 = UnsynchronizedByteArrayOutputStream.builder().get();
+ UnsynchronizedByteArrayOutputStream out2 = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(out1);
wb.write(out2);
diff --git a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestPicture.java b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestPicture.java
index af3c773d00..8502bbfcd1 100644
--- a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestPicture.java
+++ b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestPicture.java
@@ -272,7 +272,7 @@ public abstract class BaseTestPicture {
g.draw(ell);
g.dispose();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(2000);
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(2000).get();
ImageIO.write(bi, "PNG", bos);
return bos.toByteArray();
}
diff --git a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestWorkbook.java b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
index 349e5427fc..0dc0bafbf6 100644
--- a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
+++ b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
@@ -17,7 +17,6 @@
package org.apache.poi.ss.usermodel;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -33,6 +32,7 @@ import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.Spliterator;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
@@ -784,7 +784,7 @@ public abstract class BaseTestWorkbook {
c.setCellStyle(cs);
c.setCellValue("AAA");
}
- assertDoesNotThrow(() -> workbook.write(NULL_OUTPUT_STREAM));
+ assertDoesNotThrow(() -> workbook.write(NullOutputStream.INSTANCE));
}
}
diff --git a/poi/src/test/java/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java b/poi/src/test/java/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java
index 62b83ffaf9..d80d23990c 100644
--- a/poi/src/test/java/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java
+++ b/poi/src/test/java/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java
@@ -150,7 +150,7 @@ public class NumberRenderingSpreadsheetGenerator {
File outputFile = new File("ExcelNumberRendering.xls");
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
FileOutputStream os = new FileOutputStream(outputFile)) {
wb.write(baos);
@@ -212,7 +212,7 @@ public class NumberRenderingSpreadsheetGenerator {
}
private static String interpretLong(byte[] fileContent, int offset) {
- try (InputStream is = new UnsynchronizedByteArrayInputStream(fileContent, offset, 8)) {
+ try (InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(fileContent).setOffset(offset).setLength(8).get()) {
long l = new DataInputStream(is).readLong();
return "0x" + Long.toHexString(l).toUpperCase(Locale.ROOT);
} catch (IOException e) {
diff --git a/poi/src/test/java/org/apache/poi/ss/util/TestCellRangeAddress.java b/poi/src/test/java/org/apache/poi/ss/util/TestCellRangeAddress.java
index 4d729d6006..321e67fe77 100644
--- a/poi/src/test/java/org/apache/poi/ss/util/TestCellRangeAddress.java
+++ b/poi/src/test/java/org/apache/poi/ss/util/TestCellRangeAddress.java
@@ -67,7 +67,7 @@ final class TestCellRangeAddress {
CellRangeAddress ref = new CellRangeAddress(0, 0, 0, 0);
byte[] recordBytes;
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (LittleEndianOutputStream out = new LittleEndianOutputStream(baos)) {
// With nothing set
ref.serialize(out);
diff --git a/poi/src/test/java/org/apache/poi/ss/util/TestDateFormatConverter.java b/poi/src/test/java/org/apache/poi/ss/util/TestDateFormatConverter.java
index 0faf865e5a..059426289e 100644
--- a/poi/src/test/java/org/apache/poi/ss/util/TestDateFormatConverter.java
+++ b/poi/src/test/java/org/apache/poi/ss/util/TestDateFormatConverter.java
@@ -22,7 +22,6 @@ package org.apache.poi.ss.util;
import static java.text.DateFormat.getDateInstance;
import static java.text.DateFormat.getDateTimeInstance;
import static java.text.DateFormat.getTimeInstance;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.poi.ss.util.DateFormatConverter.getPrefixForLocale;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -43,6 +42,7 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
@@ -122,7 +122,7 @@ final class TestDateFormatConverter {
cell[6].setCellValue(excelFormatPattern);
}
- assertDoesNotThrow(() -> workbook.write(NULL_OUTPUT_STREAM));
+ assertDoesNotThrow(() -> workbook.write(NullOutputStream.INSTANCE));
}
}
diff --git a/poi/src/test/java/org/apache/poi/util/TestHexDump.java b/poi/src/test/java/org/apache/poi/util/TestHexDump.java
index 16b1b334d5..5864041706 100644
--- a/poi/src/test/java/org/apache/poi/util/TestHexDump.java
+++ b/poi/src/test/java/org/apache/poi/util/TestHexDump.java
@@ -41,7 +41,7 @@ class TestHexDump {
@BeforeAll
public static void setUp() throws UnsupportedEncodingException {
SYSTEM_OUT = System.out;
- System.setOut(new NullPrintStream());
+ System.setOut(NullPrintStream.INSTANCE);
}
@AfterAll
@@ -52,7 +52,7 @@ class TestHexDump {
@Test
void testDump() throws IOException {
byte[] testArray = testArray();
- UnsynchronizedByteArrayOutputStream streamAct = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream streamAct = UnsynchronizedByteArrayOutputStream.builder().get();
HexDump.dump(testArray, 0, streamAct, 0);
byte[] bytesAct = streamAct.toByteArray();
byte[] bytesExp = toHexDump(0, 0);
diff --git a/poi/src/test/java/org/apache/poi/util/TestIOUtils.java b/poi/src/test/java/org/apache/poi/util/TestIOUtils.java
index 481afd28be..bb12f9932e 100644
--- a/poi/src/test/java/org/apache/poi/util/TestIOUtils.java
+++ b/poi/src/test/java/org/apache/poi/util/TestIOUtils.java
@@ -229,7 +229,7 @@ final class TestIOUtils {
@Test
void testSkipFullyByteArray() throws IOException {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (InputStream is = new FileInputStream(TMP)) {
assertEquals(LENGTH, IOUtils.copy(is, bos));
long skipped = IOUtils.skipFully(bos.toInputStream(), 20000L);
@@ -239,7 +239,7 @@ final class TestIOUtils {
@Test
void testSkipFullyByteArrayGtIntMax() throws IOException {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (InputStream is = new FileInputStream(TMP)) {
assertEquals(LENGTH, IOUtils.copy(is, bos));
long skipped = IOUtils.skipFully(bos.toInputStream(), Integer.MAX_VALUE + 20000L);
diff --git a/poi/src/test/java/org/apache/poi/util/TestLittleEndianInputStream.java b/poi/src/test/java/org/apache/poi/util/TestLittleEndianInputStream.java
index d7b9ad7b5f..00240378dc 100644
--- a/poi/src/test/java/org/apache/poi/util/TestLittleEndianInputStream.java
+++ b/poi/src/test/java/org/apache/poi/util/TestLittleEndianInputStream.java
@@ -34,7 +34,7 @@ class TestLittleEndianInputStream {
assertEquals(4, fr.getCharacterPos());
assertEquals(0x15c, fr.getFontIndex());
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
LittleEndianOutputStream out = new LittleEndianOutputStream(baos);
fr.serialize(out);
diff --git a/poi/src/test/java/org/apache/poi/util/TestLittleEndianStreams.java b/poi/src/test/java/org/apache/poi/util/TestLittleEndianStreams.java
index d1c58f9278..8f505f793c 100644
--- a/poi/src/test/java/org/apache/poi/util/TestLittleEndianStreams.java
+++ b/poi/src/test/java/org/apache/poi/util/TestLittleEndianStreams.java
@@ -35,7 +35,7 @@ final class TestLittleEndianStreams {
@Test
void testRead() throws IOException {
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (LittleEndianOutputStream leo = new LittleEndianOutputStream(baos)) {
leo.writeInt(12345678);
leo.writeShort(12345);
diff --git a/poi/src/test/java/org/apache/poi/util/TestRLEDecompressingInputStream.java b/poi/src/test/java/org/apache/poi/util/TestRLEDecompressingInputStream.java
index 0c8fad889e..3d63d930f3 100644
--- a/poi/src/test/java/org/apache/poi/util/TestRLEDecompressingInputStream.java
+++ b/poi/src/test/java/org/apache/poi/util/TestRLEDecompressingInputStream.java
@@ -148,7 +148,7 @@ class TestRLEDecompressingInputStream {
private static void checkRLEDecompression(String expected, byte[] runLengthEncodedData) throws IOException {
InputStream compressedStream = new ByteArrayInputStream(runLengthEncodedData);
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
try (InputStream stream = new RLEDecompressingInputStream(compressedStream)) {
IOUtils.copy(stream, out);
}