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
This commit is contained in:
Dominik Stadler 2023-06-08 08:53:08 +00:00
parent c8f9fe4c2c
commit d3e35e740a
246 changed files with 550 additions and 490 deletions

View File

@ -57,7 +57,7 @@ public class OSGiExtractorsIT extends BaseOSGiTestCase {
box.setText("Hello, World!");
box.setAnchor(new Rectangle(36, 15, 648, 65));
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
ppt.write(out);
return out.toByteArray();
}
@ -66,7 +66,7 @@ public class OSGiExtractorsIT extends BaseOSGiTestCase {
Sheet s = wb.createSheet("OSGi");
s.createRow(0).createCell(0).setCellValue("Hello, World!");
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
wb.write(out);
return out.toByteArray();

View File

@ -75,7 +75,7 @@ public class OSGiSlideShowIT extends BaseOSGiTestCase {
}
box2.setAnchor(new Rectangle(36, 80, 648, 400));
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
ppt.write(baos);
try (InputStream bais = baos.toInputStream()) {
ppt = SlideShowFactory.create(bais);

View File

@ -48,7 +48,7 @@ public class OSGiSpreadsheetIT extends BaseOSGiTestCase {
s.createRow(0).createCell(0).setCellValue("With OSGi");
s.createRow(1).createCell(0).setCellFormula("SUM(A1:B3)");
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(baos);
try (InputStream bais = baos.toInputStream()) {
wb = WorkbookFactory.create(bais);

View File

@ -192,7 +192,7 @@ public final class OfficeDrawing {
private static int loadPicture( String path, HSSFWorkbook wb ) throws IOException {
int pictureIndex;
try (FileInputStream fis = new FileInputStream(path);
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
IOUtils.copy(fis, bos);
pictureIndex = wb.addPicture(bos.toByteArray(), Workbook.PICTURE_TYPE_PNG);
}

View File

@ -38,7 +38,7 @@ public final class CustomXMLMapping {
for (XSSFMap map : wb.getCustomXMLMappings()) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xml = os.toString(StandardCharsets.UTF_8);
System.out.println(xml);

View File

@ -35,7 +35,7 @@ import org.junit.jupiter.api.Test;
public class TestXLSX2CSV {
private PrintStream err;
private final UnsynchronizedByteArrayOutputStream errorBytes = new UnsynchronizedByteArrayOutputStream();
private final UnsynchronizedByteArrayOutputStream errorBytes = UnsynchronizedByteArrayOutputStream.builder().get();
@BeforeEach
public void setUp() throws UnsupportedEncodingException {
@ -77,7 +77,7 @@ public class TestXLSX2CSV {
@Test
public void testSampleFile() throws Exception {
final UnsynchronizedByteArrayOutputStream outputBytes = new UnsynchronizedByteArrayOutputStream();
final UnsynchronizedByteArrayOutputStream outputBytes = UnsynchronizedByteArrayOutputStream.builder().get();
PrintStream out = new PrintStream(outputBytes, true, StandardCharsets.UTF_8.name());
// The package open is instantaneous, as it should be.
@ -96,7 +96,7 @@ public class TestXLSX2CSV {
@Test
public void testMinColumns() throws Exception {
final UnsynchronizedByteArrayOutputStream outputBytes = new UnsynchronizedByteArrayOutputStream();
final UnsynchronizedByteArrayOutputStream outputBytes = UnsynchronizedByteArrayOutputStream.builder().get();
PrintStream out = new PrintStream(outputBytes, true, StandardCharsets.UTF_8.name());
// The package open is instantaneous, as it should be.

View File

@ -57,7 +57,7 @@ public class POIFSFileHandler extends AbstractFileHandler {
}
protected void handlePOIDocument(POIDocument doc) throws Exception {
try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) {
doc.write(out);
try (InputStream in = out.toInputStream();

View File

@ -49,7 +49,7 @@ public abstract class SlideShowHandler extends POIFSFileHandler {
readPictures(ss);
// write out the file
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
ss.write(out);
readContent(ss);

View File

@ -61,7 +61,7 @@ public abstract class SpreadsheetHandler extends AbstractFileHandler {
}
private UnsynchronizedByteArrayOutputStream writeToArray(Workbook wb) throws IOException {
UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().get();
wb.write(stream);
return stream;
}

View File

@ -41,11 +41,11 @@ public class XSSFBFileHandler extends AbstractFileHandler {
public void handleFile(InputStream stream, String path) throws Exception {
byte[] bytes = IOUtils.toByteArray(stream);
try (OPCPackage opcPackage = OPCPackage.open(new UnsynchronizedByteArrayInputStream(bytes))) {
try (OPCPackage opcPackage = OPCPackage.open(UnsynchronizedByteArrayInputStream.builder().setByteArray(bytes).get())) {
testOne(opcPackage);
}
testNotHandledByWorkbookException(OPCPackage.open(new UnsynchronizedByteArrayInputStream(bytes)));
testNotHandledByWorkbookException(OPCPackage.open(UnsynchronizedByteArrayInputStream.builder().setByteArray(bytes).get()));
}
private void testNotHandledByWorkbookException(OPCPackage pkg) throws IOException {

View File

@ -16,7 +16,6 @@
==================================================================== */
package org.apache.poi.stress;
import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.poi.xssf.XSSFTestDataSamples.getSampleFile;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
@ -36,6 +35,7 @@ import java.util.Set;
import javax.xml.transform.TransformerException;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.examples.ss.ExcelComparator;
@ -72,7 +72,7 @@ public class XSSFFileHandler extends SpreadsheetHandler {
// make sure the potentially large byte-array is freed up quickly again
{
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
IOUtils.copy(stream, out);
if (pass != null) {
@ -156,7 +156,7 @@ public class XSSFFileHandler extends SpreadsheetHandler {
TransformerException {
for (XSSFMap map : wb.getCustomXMLMappings()) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
exporter.exportToXML(NULL_OUTPUT_STREAM, true);
exporter.exportToXML(NullOutputStream.INSTANCE, true);
}
}

View File

@ -88,7 +88,12 @@ public final class MemoryPackagePart extends PackagePart {
if (data == null) {
data = new byte[0];
}
return new UnsynchronizedByteArrayInputStream(data);
try {
return UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get();
} catch (IOException e) {
// not possible with ByteArray but still declared in the API
throw new IllegalStateException(e);
}
}
@Override
@ -113,7 +118,7 @@ public final class MemoryPackagePart extends PackagePart {
@Override
public boolean load(InputStream is) throws InvalidFormatException {
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
// Grab the data
IOUtils.copy(is, baos);
// Save it

View File

@ -33,7 +33,7 @@ public final class MemoryPackagePartOutputStream extends OutputStream {
public MemoryPackagePartOutputStream(MemoryPackagePart part) {
this._part = part;
_buff = new UnsynchronizedByteArrayOutputStream();
_buff = UnsynchronizedByteArrayOutputStream.builder().get();
}
@Override

View File

@ -104,7 +104,7 @@ import org.apache.poi.util.TempFile;
throw new IOException("temp file " + tempFile.getAbsolutePath() + " is missing");
}
} else if (data != null) {
return new UnsynchronizedByteArrayInputStream(data);
return UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get();
} else {
throw new IOException("Cannot retrieve data from Zip Entry, probably because the Zip Entry was closed before the data was requested.");
}

View File

@ -65,7 +65,7 @@ import org.ietf.jgss.Oid;
}
public byte[] sign() throws IOException, GeneralSecurityException {
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
bos.write(getHashMagic());
bos.write(md.digest());
@ -91,7 +91,7 @@ import org.ietf.jgss.Oid;
// in an earlier release the hashMagic (aka DigestAlgorithmIdentifier) contained only
// an object identifier, but to conform with the header generated by the
// javax-signature API, the empty <associated parameters> are also included
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
final byte[] oidBytes = new Oid(algo.rsaOid).getDER();
bos.write(0x30);

View File

@ -90,7 +90,7 @@ public class OOXMLURIDereferencer implements URIDereferencer {
if (part.getPartName().toString().endsWith(".rels")) {
// although xmlsec has an option to ignore line breaks, currently this
// only affects .rels files, so we only modify these
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
for (int ch; (ch = dataStream.read()) != -1; ) {
if (ch == 10 || ch == 13) continue;
bos.write(ch);

View File

@ -341,7 +341,7 @@ public abstract class SignatureLine {
rnd.drawImage(gfx, new Rectangle2D.Double(0, 0, defaultWidth, defaultHeight));
gfx.dispose();
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
ImageIO.write(bi, "PNG", bos);
return bos.toByteArray();
}
@ -426,7 +426,7 @@ public abstract class SignatureLine {
gfx.dispose();
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
ImageIO.write(bi, "PNG", bos);
return bos.toByteArray();
}

View File

@ -223,9 +223,12 @@ public class XAdESXLSignatureFacet implements SignatureFacet {
X509CRL crl;
try {
crl = (X509CRL) this.certificateFactory
.generateCRL(new UnsynchronizedByteArrayInputStream(encodedCrl));
.generateCRL(UnsynchronizedByteArrayInputStream.builder().setByteArray(encodedCrl).get());
} catch (CRLException e) {
throw new IllegalStateException("CRL parse error: " + e.getMessage(), e);
} catch (IOException e) {
// not possible with ByteArray but still declared in the API
throw new IllegalStateException(e);
}
CRLIdentifierType crlIdentifier = crlRef.addNewCRLIdentifier();
@ -299,7 +302,7 @@ public class XAdESXLSignatureFacet implements SignatureFacet {
}
private static byte[] getC14nValue(List<Node> nodeList, String c14nAlgoId) {
try (UnsynchronizedByteArrayOutputStream c14nValue = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream c14nValue = UnsynchronizedByteArrayOutputStream.builder().get()) {
for (Node node : nodeList) {
/*
* Re-initialize the c14n else the namespaces will get cached

View File

@ -68,7 +68,7 @@ public class SVGImageRenderer implements ImageRenderer {
@Override
public void loadImage(byte[] data, String contentType) throws IOException {
loadImage(new UnsynchronizedByteArrayInputStream(data), contentType);
loadImage(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get(), contentType);
}
@Override

View File

@ -310,7 +310,7 @@ public class SVGRenderExtension extends DefaultExtensionHandler {
}
if (imgData == null) {
BufferedImage bi = imgRdr.getImage();
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try {
ImageIO.write(bi, "PNG", bos);
} catch (IOException e) {

View File

@ -44,7 +44,7 @@ public class XSLFMetroShape implements MetroShapeProvider {
/** parses the metro bytes to a XSLF shape */
@Override
public XSLFShape parseShape(byte[] metroBytes) throws IOException {
try (OPCPackage pkg = OPCPackage.open(new UnsynchronizedByteArrayInputStream(metroBytes))) {
try (OPCPackage pkg = OPCPackage.open(UnsynchronizedByteArrayInputStream.builder().setByteArray(metroBytes).get())) {
PackagePartName shapePN = PackagingURIHelper.createPartName("/drs/shapexml.xml");
PackagePart shapePart = pkg.getPart(shapePN);
if (shapePart == null) {

View File

@ -372,7 +372,7 @@ public class XSLFPictureShape extends XSLFSimpleShape
}
BufferedImage thmBI = renderer.getImage(dim);
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(100000)) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(100000).get()) {
// use extension instead of enum name, because of "jpeg"
ImageIO.write(thmBI, pt.extension.substring(1), bos);

View File

@ -34,7 +34,7 @@ public class DummyFormat implements OutputFormat {
public DummyFormat() {
try {
bos = new UnsynchronizedByteArrayOutputStream();
bos = UnsynchronizedByteArrayOutputStream.builder().get();
dummy2d = new DummyGraphics2d(new PrintStream(bos, true, StandardCharsets.UTF_8.name()));
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);

View File

@ -1019,7 +1019,7 @@ public class SXSSFWorkbook implements Workbook {
flushSheets();
//Save the template
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
_wb.write(bos);
//Substitute the template entries with the generated sheet data files

View File

@ -409,8 +409,8 @@ public enum XSSFBuiltinTableStyle {
// hack because I can't figure out how to get XMLBeans to parse a sub-element in a standalone manner
// - build a fake styles.xml file with just this built-in
StylesTable styles = new StylesTable();
try (UnsynchronizedByteArrayInputStream bis = new UnsynchronizedByteArrayInputStream(
styleXML(dxfsNode, tableStyleNode).getBytes(StandardCharsets.UTF_8))) {
try (UnsynchronizedByteArrayInputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(
styleXML(dxfsNode, tableStyleNode).getBytes(StandardCharsets.UTF_8)).get()) {
styles.readFrom(bis);
}
styleMap.put(builtIn, new XSSFBuiltinTypeStyleStyle(builtIn, styles.getExplicitTableStyle(styleName)));

View File

@ -57,7 +57,7 @@ public class XSSFChartSheet extends XSSFSheet {
@Override
protected void read(InputStream is) throws IOException {
//initialize the supeclass with a blank worksheet
super.read(new UnsynchronizedByteArrayInputStream(BLANK_WORKSHEET));
super.read(UnsynchronizedByteArrayInputStream.builder().setByteArray(BLANK_WORKSHEET).get());
try {
chartsheet = ChartsheetDocument.Factory.parse(is, DEFAULT_XML_OPTIONS).getChartsheet();
@ -95,7 +95,7 @@ public class XSSFChartSheet extends XSSFSheet {
}
private static byte[] blankWorksheet(){
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
try {
new XSSFSheet().write(out);
} catch (IOException e){

View File

@ -511,7 +511,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
protected static OPCPackage newPackage(XSSFWorkbookType workbookType) {
OPCPackage pkg = null;
try {
pkg = OPCPackage.create(new UnsynchronizedByteArrayOutputStream()); // NOSONAR - we do not want to close this here
pkg = OPCPackage.create(UnsynchronizedByteArrayOutputStream.builder().get()); // NOSONAR - we do not want to close this here
// Main part
PackagePartName corePartName = PackagingURIHelper.createPartName(XSSFRelation.WORKBOOK.getDefaultFileName());
// Create main part relationship
@ -665,7 +665,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
}
try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) {
srcSheet.write(out);
try (InputStream bis = out.toInputStream()) {
clonedSheet.read(bis);
@ -2466,7 +2466,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
Ole10Native ole10 = new Ole10Native(label, fileName, command, oleData);
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(oleData.length+500)) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(oleData.length+500).get()) {
ole10.writeOut(bos);
try (POIFSFileSystem poifs = new POIFSFileSystem()) {

View File

@ -174,7 +174,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
protected static OPCPackage newPackage() {
OPCPackage pkg = null;
try {
pkg = OPCPackage.create(new UnsynchronizedByteArrayOutputStream()); // NOSONAR - we do not want to close this here
pkg = OPCPackage.create(UnsynchronizedByteArrayOutputStream.builder().get()); // NOSONAR - we do not want to close this here
// Main part
PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
// Create main part relationship

View File

@ -17,7 +17,6 @@
package org.apache.poi.ooxml;
import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@ -38,6 +37,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart;
import org.apache.poi.ooxml.util.PackageHelper;
@ -141,7 +141,7 @@ public final class TestPOIXMLDocument {
// Should not be able to write a document that has been closed
doc.close();
IOException e2 = assertThrows(IOException.class, () -> doc.write(NULL_OUTPUT_STREAM),
IOException e2 = assertThrows(IOException.class, () -> doc.write(NullOutputStream.INSTANCE),
"Should not be able to write a document that has been closed.");
assertEquals("Cannot write data, document seems to have been closed already", e2.getMessage());

View File

@ -218,7 +218,7 @@ public final class TestPackage {
*/
@Test
void createPackageWithCoreDocument() throws IOException, InvalidFormatException, URISyntaxException, SAXException {
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (OPCPackage pkg = OPCPackage.create(baos)) {
// Add a core document
@ -676,7 +676,7 @@ public final class TestPackage {
@Test
void zipBombCreateAndHandle()
throws IOException, EncryptedDocumentException {
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(2500000);
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(2500000).get();
try (ZipFile zipFile = ZipHelper.openZipFile(getSampleFile("sample.xlsx"));
ZipArchiveOutputStream append = new ZipArchiveOutputStream(bos)) {

View File

@ -216,7 +216,7 @@ public final class TestPackageCoreProperties {
@Test
void testGetPropertiesLO() throws Exception {
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
// Open the package
try (OPCPackage pkg1 = OPCPackage.open(openSampleStream("51444.xlsx"))) {
PackageProperties props1 = pkg1.getPackageProperties();
@ -284,7 +284,7 @@ public final class TestPackageCoreProperties {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ROOT);
df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (InputStream is = openSampleStream("OPCCompliance_CoreProperties_AlternateTimezones.docx");
OPCPackage pkg1 = OPCPackage.open(is)) {
PackagePropertiesPart props1 = (PackagePropertiesPart) pkg1.getPackageProperties();

View File

@ -198,7 +198,7 @@ class TestRelationships {
// Write out and re-load
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
pkg.save(baos);
// use revert to not re-write the input file
@ -226,7 +226,7 @@ class TestRelationships {
@Test
void testCreateRelationsFromScratch() throws Exception {
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
OPCPackage pkg = OPCPackage.create(baos);
PackagePart partA =
@ -298,7 +298,7 @@ class TestRelationships {
OPCPackage pkg = OPCPackage.open(filepath);
assert_50154(pkg);
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
pkg.save(baos);
// use revert to not re-write the input file
@ -353,7 +353,7 @@ class TestRelationships {
@Test
void testSelfRelations_bug51187() throws Exception {
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
PackageRelationship rel1;
try (OPCPackage pkg = OPCPackage.create(baos)) {
@ -399,7 +399,7 @@ class TestRelationships {
assertEquals("mailto:nobody@nowhere.uk%C2%A0", targetUri.toASCIIString());
assertEquals("nobody@nowhere.uk\u00A0", targetUri.getSchemeSpecificPart());
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
pkg1.save(out);
try (OPCPackage pkg2 = OPCPackage.open(out.toInputStream())) {

View File

@ -106,7 +106,7 @@ public final class ZipFileAssert {
while ((entree = zis.getNextEntry()) != null) {
/* Create an array for the current entry */
UnsynchronizedByteArrayOutputStream byteArray = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream byteArray = UnsynchronizedByteArrayOutputStream.builder().get();
IOUtils.copy(zis, byteArray);
zipContent.put(entree.getName(), byteArray);
}

View File

@ -216,7 +216,7 @@ public final class TestOPCComplianceCoreProperties {
@Test
void testNoCoreProperties_saveNew() throws Exception {
String sampleFileName = "OPCCompliance_NoCoreProperties.xlsx";
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (OPCPackage pkg = OPCPackage.open(getSampleFile(sampleFileName).getPath())) {
// Verify it has empty properties

View File

@ -17,7 +17,6 @@
package org.apache.poi.openxml4j.opc.internal.marshallers;
import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.poi.openxml4j.opc.PackagingURIHelper.PACKAGE_RELATIONSHIPS_ROOT_URI;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -27,6 +26,7 @@ import java.io.OutputStream;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.PackagePartName;
@ -39,7 +39,7 @@ class TestZipPackagePropertiesMarshaller {
private final PartMarshaller marshaller = new ZipPackagePropertiesMarshaller();
private boolean marshall() throws OpenXML4JException {
return marshall(new ZipArchiveOutputStream(new UnsynchronizedByteArrayOutputStream()));
return marshall(new ZipArchiveOutputStream(UnsynchronizedByteArrayOutputStream.builder().get()));
}
private boolean marshall(OutputStream zos) throws OpenXML4JException {
@ -51,7 +51,7 @@ class TestZipPackagePropertiesMarshaller {
@Test
void nonZipOutputStream() {
assertThrows(IllegalArgumentException.class, () -> marshall(NULL_OUTPUT_STREAM));
assertThrows(IllegalArgumentException.class, () -> marshall(NullOutputStream.INSTANCE));
}
@Test
@ -61,7 +61,7 @@ class TestZipPackagePropertiesMarshaller {
@Test
void ioException() {
ZipArchiveOutputStream zos = new ZipArchiveOutputStream(new UnsynchronizedByteArrayOutputStream()) {
ZipArchiveOutputStream zos = new ZipArchiveOutputStream(UnsynchronizedByteArrayOutputStream.builder().get()) {
@Override
public void putArchiveEntry(final ArchiveEntry archiveEntry) throws IOException {
throw new IOException("TestException");

View File

@ -152,7 +152,7 @@ public class DummyKeystore {
public DummyKeystore(String pfxInput, String storePass) throws GeneralSecurityException, IOException {
CryptoFunctions.registerBouncyCastle();
keystore = KeyStore.getInstance("PKCS12");
try (InputStream fis = new UnsynchronizedByteArrayInputStream(RawDataUtil.decompress(pfxInput))) {
try (InputStream fis = UnsynchronizedByteArrayInputStream.builder().setByteArray(RawDataUtil.decompress(pfxInput)).get()) {
keystore.load(fis, storePass.toCharArray());
}
}

View File

@ -209,7 +209,7 @@ class TestSignatureInfo {
SignatureInfo si = new SignatureInfo();
si.setSignatureConfig(signatureConfig);
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(100000);
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(100000).get();
try (XSSFWorkbook wb1 = new XSSFWorkbook()) {
wb1.createSheet().createRow(1).createCell(1).setCellValue("Test");
wb1.write(bos);
@ -426,7 +426,7 @@ class TestSignatureInfo {
void testSignEnvelopingDocument() throws Exception {
String testFile = "hello-world-unsigned.xlsx";
File sigCopy = testdata.getFile(testFile);
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(50000);
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(50000).get();
final String execTimestr;
@ -698,7 +698,7 @@ class TestSignatureInfo {
DummyKeystore ks = new DummyKeystore(STORE_PASS);
KeyCertPair certPair = ks.createDummyKey();
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (XWPFDocument doc = new XWPFDocument()) {
XWPFHyperlinkRun r = doc.createParagraph().createHyperlinkRun("http://poi.apache.org");
r.setText("Hyperlink");
@ -743,7 +743,7 @@ class TestSignatureInfo {
try (SXSSFWorkbook wb1 = new SXSSFWorkbook((XSSFWorkbook)WorkbookFactory.create(tpl), 10)) {
wb1.setCompressTempFiles(true);
wb1.removeSheetAt(0);
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
wb1.write(os);
try (OPCPackage pkg = OPCPackage.open(os.toInputStream())) {
@ -888,7 +888,7 @@ class TestSignatureInfo {
throw e;
}
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (XSSFWorkbook wb = new XSSFWorkbook()) {
wb.createSheet().createRow(0).createCell(0).setCellValue("Test");
wb.write(bos);
@ -1075,7 +1075,7 @@ class TestSignatureInfo {
throw e;
}
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (XSSFWorkbook wb = new XSSFWorkbook()) {
wb.createSheet().createRow(0).createCell(0).setCellValue("test");
wb.write(bos);

View File

@ -93,7 +93,7 @@ class TestAgileEncryptionParameters {
}
// create a small sample workbook for encrypting
UnsynchronizedByteArrayOutputStream bosOrig = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bosOrig = UnsynchronizedByteArrayOutputStream.builder().get();
try (XSSFWorkbook workbook = new XSSFWorkbook()) {
XSSFSheet sheet = workbook.createSheet();
XSSFRow row = sheet.createRow(0);
@ -136,7 +136,7 @@ class TestAgileEncryptionParameters {
os.write(testData);
}
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
fsEnc.writeFilesystem(bos);
bos.close();

View File

@ -142,7 +142,7 @@ class TestDecryptor {
Decryptor d = Decryptor.getInstance(info);
d.verifyPassword("pwd123");
final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(10000);
final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(10000).get();
try (final ZipArchiveInputStream zis = new ZipArchiveInputStream(d.getDataStream(fs))) {
int[] sizes = { 3711, 1155, 445, 9376, 450, 588, 1337, 2593, 304, 7910 };
for (int size : sizes) {

View File

@ -16,7 +16,6 @@
==================================================================== */
package org.apache.poi.poifs.crypt.tests;
import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.poi.poifs.crypt.CryptoFunctions.getMessageDigest;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -38,6 +37,7 @@ import java.util.Random;
import javax.crypto.Cipher;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.openxml4j.opc.ContentTypes;
@ -76,7 +76,7 @@ class TestEncryptor {
payloadExpected = IOUtils.toByteArray(is);
}
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (POIFSFileSystem fs = new POIFSFileSystem()) {
EncryptionInfo ei = new EncryptionInfo(EncryptionMode.binaryRC4);
Encryptor enc = ei.getEncryptor();
@ -113,7 +113,7 @@ class TestEncryptor {
payloadExpected = IOUtils.toByteArray(is);
}
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (POIFSFileSystem fs = new TempFilePOIFSFileSystem()) {
EncryptionInfo ei = new EncryptionInfo(EncryptionMode.agile);
Encryptor enc = ei.getEncryptor();
@ -200,7 +200,7 @@ class TestEncryptor {
Encryptor e = Encryptor.getInstance(infoActual);
e.confirmPassword(pass, keySpec, keySalt, verifierExpected, verifierSaltExpected, integritySalt);
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (POIFSFileSystem fs = new POIFSFileSystem()) {
try (OutputStream os = e.getDataStream(fs)) {
os.write(payloadExpected);
@ -287,7 +287,7 @@ class TestEncryptor {
// now we use a newly generated salt/verifier and check
// if the file content is still the same
final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(50000);
final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(50000).get();
try (POIFSFileSystem fs = new POIFSFileSystem()) {
final EncryptionInfo infoActual2 = new EncryptionInfo(
@ -331,7 +331,7 @@ class TestEncryptor {
@Test
void encryptPackageWithoutCoreProperties() throws Exception {
// Open our file without core properties
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (InputStream is = POIDataSamples.getOpenXML4JInstance().openResourceAsStream("OPCCompliance_NoCoreProperties.xlsx");
OPCPackage pkg = OPCPackage.open(is)) {
@ -530,7 +530,7 @@ class TestEncryptor {
os.write(zipInput);
}
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
fsNew.writeFilesystem(bos);
try (POIFSFileSystem fsReload = new POIFSFileSystem(bos.toInputStream())) {
@ -624,7 +624,7 @@ class TestEncryptor {
try (InputStream is = dec.getDataStream(poifs);
DigestInputStream dis = new DigestInputStream(is, md)) {
IOUtils.copy(dis, NULL_OUTPUT_STREAM);
IOUtils.copy(dis, NullOutputStream.INSTANCE);
}
}

View File

@ -105,7 +105,7 @@ class TestHxxFEncryption {
File f = sampleDir.getFile(file);
Biff8EncryptionKey.setCurrentUserPassword(password);
try (POITextExtractor te1 = ExtractorFactory.createExtractor(f);
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
Biff8EncryptionKey.setCurrentUserPassword(newPass);
try (POIDocument doc = (POIDocument) te1.getDocument()) {
doc.write(bos);
@ -126,7 +126,7 @@ class TestHxxFEncryption {
File f = sampleDir.getFile(file);
Biff8EncryptionKey.setCurrentUserPassword(password);
try (POITextExtractor te1 = ExtractorFactory.createExtractor(f);
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
// first remove encryption
Biff8EncryptionKey.setCurrentUserPassword(null);
try (POIDocument doc = (POIDocument) te1.getDocument()) {
@ -174,7 +174,7 @@ class TestHxxFEncryption {
@Test
public void changeEncryptionMode() throws IOException {
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(10_000);
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(10_000).get();
try (HSSFWorkbook wb = new HSSFWorkbook()) {
wb.createSheet().createRow(1).createCell(1).setCellValue("Test");

View File

@ -113,7 +113,7 @@ class TestOleShape {
@ParameterizedTest
@MethodSource("data")
void embedData(Api api, ObjectMetaData.Application app) throws IOException, ReflectiveOperationException {
final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(50000);
final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(50000).get();
try (SlideShow<?,?> ppt = createSlideShow(api)) {
final PictureData picData = ppt.addPicture(pictureFile, PictureType.EMF);
final Slide<?,?> slide = ppt.createSlide();

View File

@ -55,7 +55,7 @@ class TestSlide {
ppt1.createSlide().setHidden(true);
ppt1.createSlide();
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
ppt1.write(bos);
try (InputStream is = bos.toInputStream();

View File

@ -125,7 +125,7 @@ class TestTable {
}
}
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
ppt1.write(bos);
try (SlideShow<?,?> ppt2 = SlideShowFactory.create(bos.toInputStream())) {

View File

@ -123,7 +123,7 @@ class TestEmbedOLEPackage {
try (POIFSFileSystem scratchFS = new POIFSFileSystem();
POIFSFileSystem ole1FS = new POIFSFileSystem(new ByteArrayInputStream(oleShapes.get(0).getObjectData()))) {
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
scratch.writeOut(bos);
scratchFS.createDocument(bos.toInputStream(), Ole10Native.OLE10_NATIVE);
scratchFS.getRoot().setStorageClsid(ClassIDPredefined.OLE_V1_PACKAGE.getClassID());
@ -222,7 +222,7 @@ class TestEmbedOLEPackage {
sh1.setAnchor(new java.awt.Rectangle(50, 50, 100, 200));
sh1.setFillColor(java.awt.Color.red);
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
ppt.write(bos);
ppt.close();

View File

@ -964,7 +964,7 @@ class TestXSLFBugs {
final List<Object> strings = new ArrayList<>();
DummyGraphics2d dgfx = new DummyGraphics2d(new NullPrintStream()) {
DummyGraphics2d dgfx = new DummyGraphics2d(NullPrintStream.INSTANCE) {
@Override
public void drawString(AttributedCharacterIterator iterator, float x, float y) {
// For the test file, common sl draws textruns one by one and not mixed
@ -1009,7 +1009,7 @@ class TestXSLFBugs {
{ 79.58198774450841, 53.20887318960063, 109.13118501448272, 9.40935058567127 },
};
DummyGraphics2d dgfx = new DummyGraphics2d(new NullPrintStream()) {
DummyGraphics2d dgfx = new DummyGraphics2d(NullPrintStream.INSTANCE) {
int idx = 0;
@Override
public void clip(java.awt.Shape s) {
@ -1065,7 +1065,7 @@ class TestXSLFBugs {
assertNotNull(targetSlide);
assertEquals(2, targetPresentation.getPictureData().size());
targetPresentation.write(NullOutputStream.NULL_OUTPUT_STREAM);
targetPresentation.write(NullOutputStream.INSTANCE);
}
}
@ -1143,7 +1143,7 @@ class TestXSLFBugs {
final ArrayList<LinearGradientPaint> linearGradients = new ArrayList<>();
final ArrayList<RadialGradientPaint> radialGradients = new ArrayList<>();
final DummyGraphics2d dgfx = new DummyGraphics2d(new NullPrintStream())
final DummyGraphics2d dgfx = new DummyGraphics2d(NullPrintStream.INSTANCE)
{
public void setPaint(final Paint paint) {
if (paint instanceof LinearGradientPaint) {

View File

@ -40,7 +40,7 @@ class TestXSLFSlideCopy {
try (
InputStream stream = slTests.openResourceAsStream("copy-slide-demo.pptx");
XMLSlideShow slideShow = new XMLSlideShow(stream);
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
XSLFSlide defaultSlide = getSlideByShapeName(slideShow, shapeName);
int slideIndex = defaultSlide.getSlideNumber() - 1;

View File

@ -43,7 +43,7 @@ public class XSLFTestDataSamples {
}
public static XMLSlideShow writeOutAndReadBack(XMLSlideShow doc) throws IOException {
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(4096)) {
try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(4096).get()) {
doc.write(baos);
try (InputStream bais = baos.toInputStream()) {
return new XMLSlideShow(bais);

View File

@ -90,7 +90,7 @@ class TestXSLFShape {
void testReplaceTextInShapes() throws IOException {
try (
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
assertEquals(6, ppt.getSlides().size());
XSLFSlide slide0 = ppt.getSlides().get(0);
@ -135,7 +135,7 @@ class TestXSLFShape {
void testReplaceTextInShapesXDDF() throws IOException {
try (
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
assertEquals(6, ppt.getSlides().size());
XSLFSlide slide0 = ppt.getSlides().get(0);
@ -180,7 +180,7 @@ class TestXSLFShape {
void testCloneSlideAndReplaceText() throws IOException {
try (
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
assertEquals(6, ppt.getSlides().size());
XSLFSlide slide0 = ppt.getSlides().get(0);
@ -245,7 +245,7 @@ class TestXSLFShape {
void testCloneSlideAndReplaceTextXDDF() throws IOException {
try (
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
assertEquals(6, ppt.getSlides().size());
XSLFSlide slide0 = ppt.getSlides().get(0);

View File

@ -452,7 +452,7 @@ class TestXSLFTextParagraph {
assertEquals("This is a highlight test", sh.getText());
DummyGraphics2d dgfx = new DummyGraphics2d(new NullPrintStream()) {
DummyGraphics2d dgfx = new DummyGraphics2d(NullPrintStream.INSTANCE) {
@Override
public void drawString(AttributedCharacterIterator iterator, float x, float y) {
// For the test file, common sl draws textruns one by one and not mixed

View File

@ -68,7 +68,7 @@ public final class DeferredSXSSFITestDataProvider implements ITestDataProvider {
throw new IllegalArgumentException("Expected an instance of XSSFWorkbook");
}
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(baos);
try (InputStream is = baos.toInputStream()) {
return new XSSFWorkbook(is);
@ -82,7 +82,7 @@ public final class DeferredSXSSFITestDataProvider implements ITestDataProvider {
* Returns an XSSFWorkbook since SXSSFWorkbook is write-only
*/
public XSSFWorkbook inMemoryWriteOutAndReadBack(SXSSFWorkbook wb) {
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.writeAvoidingTempFiles(baos);
try (InputStream is = baos.toInputStream()) {
return new XSSFWorkbook(is);

View File

@ -67,7 +67,7 @@ public class SXSSFITestDataProvider implements ITestDataProvider {
throw new IllegalArgumentException("Expected an instance of SXSSFWorkbook");
}
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(baos);
try (InputStream is = baos.toInputStream()) {
return new XSSFWorkbook(is);

View File

@ -35,7 +35,7 @@ class TestSSUtilVsXSSFColor {
try (
XSSFWorkbook workbook = new XSSFWorkbook();
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
XSSFCellStyle cellStyle = workbook.createCellStyle();
final String rgbS = "ffff00";

View File

@ -72,7 +72,7 @@ public class TestXSSFMemoryLeak {
// not freed until we free up the Cell itself
//verifier.addObject(ctCell);
try (OutputStream out = new UnsynchronizedByteArrayOutputStream(8192)) {
try (OutputStream out = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(8192).get()) {
wb.write(out);
}

View File

@ -116,7 +116,7 @@ public class XSSFTestDataSamples {
* @throws IOException If writing the file fails
*/
public static <R extends Workbook> UnsynchronizedByteArrayOutputStream writeOut(R wb) throws IOException {
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(8192);
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(8192).get();
wb.write(out);
return out;
}

View File

@ -376,7 +376,7 @@ public final class TestXSSFReader {
@Test
void testBug65676() throws Exception {
try (UnsynchronizedByteArrayOutputStream output = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream output = UnsynchronizedByteArrayOutputStream.builder().get()) {
try(Workbook wb = new SXSSFWorkbook()) {
Row r = wb.createSheet("Sheet").createRow(0);
r.createCell(0).setCellValue(1.2); /* A1: Number 1.2 */

View File

@ -72,7 +72,7 @@ public final class TestXSSFExportToXML {
XSSFMap map = mapInfo.getXSSFMapById(1);
XSSFExportToXml exporter = new XSSFExportToXml(map);
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xml = os.toString(StandardCharsets.UTF_8);
@ -120,7 +120,7 @@ public final class TestXSSFExportToXML {
XSSFMap map = mapInfo.getXSSFMapById(1);
XSSFExportToXml exporter = new XSSFExportToXml(map);
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xml = os.toString(StandardCharsets.UTF_8);
@ -194,7 +194,7 @@ public final class TestXSSFExportToXML {
XSSFExportToXml exporter = new XSSFExportToXml(map);
String xml;
try (UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get()) {
exporter.exportToXML(os, true);
xml = os.toString(StandardCharsets.UTF_8);
}
@ -231,7 +231,7 @@ public final class TestXSSFExportToXML {
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXMLMapping-singleattributenamespace.xlsx")) {
for (XSSFMap map : wb.getCustomXMLMappings()) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
SAXParseException ex = assertThrows(SAXParseException.class, () -> exporter.exportToXML(os, true));
assertTrue(p.matcher(ex.getMessage()).find(),
"Did not find pattern " + p + " in " + ex.getMessage());
@ -256,7 +256,7 @@ public final class TestXSSFExportToXML {
assertNotNull(map, "XSSFMap is null");
XSSFExportToXml exporter = new XSSFExportToXml(map);
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xmlData = os.toString(StandardCharsets.UTF_8);
@ -300,7 +300,7 @@ public final class TestXSSFExportToXML {
assertNotNull(map, "XSSFMap is null");
XSSFExportToXml exporter = new XSSFExportToXml(map);
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xmlData = os.toString(StandardCharsets.UTF_8);
@ -335,7 +335,7 @@ public final class TestXSSFExportToXML {
assertNotNull(map, "XSSFMap is null");
XSSFExportToXml exporter = new XSSFExportToXml(map);
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xmlData = os.toString(StandardCharsets.UTF_8);
@ -374,7 +374,7 @@ public final class TestXSSFExportToXML {
assertNotNull(map, "XSSFMap is null");
XSSFExportToXml exporter = new XSSFExportToXml(map);
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xmlData = os.toString(StandardCharsets.UTF_8);
@ -400,7 +400,7 @@ public final class TestXSSFExportToXML {
for (XSSFMap map : wb.getCustomXMLMappings()) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xmlData = os.toString(StandardCharsets.UTF_8);
@ -478,7 +478,7 @@ public final class TestXSSFExportToXML {
assertNotNull(map, "XSSFMap is null");
XSSFExportToXml exporter = new XSSFExportToXml(map);
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xmlData = os.toString(StandardCharsets.UTF_8);
@ -556,7 +556,7 @@ public final class TestXSSFExportToXML {
assertNotNull(map, "XSSFMap is null");
XSSFExportToXml exporter = new XSSFExportToXml(map);
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xmlData = os.toString(StandardCharsets.UTF_8);
@ -587,7 +587,7 @@ public final class TestXSSFExportToXML {
assertNotNull(map, "XSSFMap is null");
XSSFExportToXml exporter = new XSSFExportToXml(map);
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, false);
String xmlData = os.toString(StandardCharsets.UTF_8);
@ -619,7 +619,7 @@ public final class TestXSSFExportToXML {
assertNotNull(map, "XSSFMap is null");
XSSFExportToXml exporter = new XSSFExportToXml(map);
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xmlData = os.toString(StandardCharsets.UTF_8);
@ -645,7 +645,7 @@ public final class TestXSSFExportToXML {
for (XSSFMap map : mappings) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, false);
assertNotNull(os.toString(StandardCharsets.UTF_8));
}
@ -657,7 +657,7 @@ public final class TestXSSFExportToXML {
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("61281.xlsx")) {
for (XSSFMap map : wb.getCustomXMLMappings()) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(bos, true);
assertNotNull(DocumentHelper.readDocument(bos.toInputStream()));
String exportedXml = bos.toString(StandardCharsets.UTF_8);
@ -671,7 +671,7 @@ public final class TestXSSFExportToXML {
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("xxe_in_schema.xlsx")) {
for (XSSFMap map : wb.getCustomXMLMappings()) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
assertThrows(SAXParseException.class, () -> exporter.exportToXML(bos, true));
}
}

View File

@ -34,8 +34,8 @@ class OpcZipTest {
void compareOutput() throws Exception {
Map<String, String> contents = createContents();
try (
UnsynchronizedByteArrayOutputStream bos1 = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos2 = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos1 = UnsynchronizedByteArrayOutputStream.builder().get();
UnsynchronizedByteArrayOutputStream bos2 = UnsynchronizedByteArrayOutputStream.builder().get()
) {
try (OpcOutputStream zip = new OpcOutputStream(bos1)) {
for (Map.Entry<String, String> entry : contents.entrySet()) {

View File

@ -119,7 +119,7 @@ public final class TestSXSSFSheet extends BaseTestXSheet {
@Test
void flushBufferedDaat() throws IOException {
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
try (SXSSFWorkbook wb = new SXSSFWorkbook(1)) {
SXSSFSheet sheet = wb.createSheet("my-sheet");
@ -193,7 +193,7 @@ public final class TestSXSSFSheet extends BaseTestXSheet {
//one level
sheet.groupRow(9, 10);
try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
workbook.write(bos);
try(XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) {
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
@ -223,7 +223,7 @@ public final class TestSXSSFSheet extends BaseTestXSheet {
//two level
sheet.groupRow(10, 13);
try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
workbook.write(bos);
try(XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) {
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);

View File

@ -19,7 +19,6 @@
package org.apache.poi.xssf.streaming;
import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.poi.POITestCase.assertEndsWith;
import static org.apache.poi.POITestCase.assertStartsWith;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@ -37,6 +36,7 @@ import java.io.IOException;
import java.time.LocalDate;
import java.util.Arrays;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.common.usermodel.HyperlinkType;
@ -358,12 +358,12 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
void bug53515() throws Exception {
try (Workbook wb1 = new SXSSFWorkbook(10)) {
populateWorkbook(wb1);
assertDoesNotThrow(() -> wb1.write(NULL_OUTPUT_STREAM));
assertDoesNotThrow(() -> wb1.write(NULL_OUTPUT_STREAM));
assertDoesNotThrow(() -> wb1.write(NullOutputStream.INSTANCE));
assertDoesNotThrow(() -> wb1.write(NullOutputStream.INSTANCE));
try (Workbook wb2 = new XSSFWorkbook()) {
populateWorkbook(wb2);
assertDoesNotThrow(() -> wb2.write(NULL_OUTPUT_STREAM));
assertDoesNotThrow(() -> wb2.write(NULL_OUTPUT_STREAM));
assertDoesNotThrow(() -> wb2.write(NullOutputStream.INSTANCE));
assertDoesNotThrow(() -> wb2.write(NullOutputStream.INSTANCE));
}
}
}
@ -481,7 +481,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
}
}
assertDoesNotThrow(() -> swb.write(NULL_OUTPUT_STREAM));
assertDoesNotThrow(() -> swb.write(NullOutputStream.INSTANCE));
swb.dispose();
}
}
@ -499,7 +499,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
File input = XSSFTestDataSamples.getSampleFile("sample.xlsx");
try (OPCPackage pkg = OPCPackage.open(input, PackageAccess.READ)) {
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (XSSFWorkbook xssf = new XSSFWorkbook(pkg)) {
try (SXSSFWorkbook wb = new SXSSFWorkbook(xssf, 2)) {
Sheet s = wb.createSheet(sheetName);
@ -542,7 +542,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
void addHyperlink() throws Exception {
try (
SXSSFWorkbook wb = new SXSSFWorkbook();
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
SXSSFSheet sheet = wb.createSheet("s1");
SXSSFRow row = sheet.createRow(0);
@ -568,7 +568,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
void addDimension() throws IOException {
try (
SXSSFWorkbook wb = new SXSSFWorkbook();
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
SXSSFSheet sheet = wb.createSheet();
sheet.createRow(2).createCell(3).setCellValue("top left");
@ -587,7 +587,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
void addDimension1() throws IOException {
try (
SXSSFWorkbook wb = new SXSSFWorkbook(1);
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
SXSSFSheet sheet = wb.createSheet();
sheet.createRow(2).createCell(3).setCellValue("top left");
@ -612,7 +612,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
assertEquals(6, sheet.getLastRowNum());
try (
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(wb);
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
sxssfWorkbook.write(bos);
try (XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) {
@ -627,7 +627,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
void addDimensionDisabled() throws IOException {
try (
SXSSFWorkbook wb = new SXSSFWorkbook();
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
wb.setShouldCalculateSheetDimensions(false);
SXSSFSheet sheet = wb.createSheet();
@ -655,7 +655,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
void dateStyle() throws IOException {
try (
SXSSFWorkbook workbook = new SXSSFWorkbook();
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
SXSSFSheet sheet = workbook.createSheet();
SXSSFRow row = sheet.createRow(0);

View File

@ -20,7 +20,6 @@
package org.apache.poi.xssf.streaming;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -32,6 +31,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.OPCPackage;
@ -58,7 +58,7 @@ public final class TestSXSSFWorkbookWithCustomZipEntrySource {
// write an unencrypted workbook to disk, but any temporary files are encrypted
@Test
void customZipEntrySource() throws IOException {
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(8192);
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(8192).get();
try (SXSSFWorkbookWithCustomZipEntrySource workbook = new SXSSFWorkbookWithCustomZipEntrySource()) {
SXSSFSheet sheet1 = workbook.createSheet(sheetName);
SXSSFRow row1 = sheet1.createRow(1);
@ -113,7 +113,7 @@ public final class TestSXSSFWorkbookWithCustomZipEntrySource {
SXSSFRow row1 = sheet1.createRow(1);
SXSSFCell cell1 = row1.createCell(1);
cell1.setCellValue(cellValue);
workbook.write(NULL_OUTPUT_STREAM);
workbook.write(NullOutputStream.INSTANCE);
workbook.close();
List<File> tempFiles = workbook.getTempFiles();
assertEquals(1, tempFiles.size());

View File

@ -19,6 +19,7 @@
package org.apache.poi.xssf.streaming;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.common.usermodel.HyperlinkType;
@ -44,7 +45,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.poi.POITestCase.assertEndsWith;
import static org.apache.poi.POITestCase.assertStartsWith;
import static org.junit.jupiter.api.Assertions.*;
@ -337,12 +337,12 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook {
void bug53515() throws Exception {
try (Workbook wb1 = new SXSSFWorkbook(10)) {
populateWorkbook(wb1);
assertDoesNotThrow(() -> wb1.write(NULL_OUTPUT_STREAM));
assertDoesNotThrow(() -> wb1.write(NULL_OUTPUT_STREAM));
assertDoesNotThrow(() -> wb1.write(NullOutputStream.INSTANCE));
assertDoesNotThrow(() -> wb1.write(NullOutputStream.INSTANCE));
try (Workbook wb2 = new XSSFWorkbook()) {
populateWorkbook(wb2);
assertDoesNotThrow(() -> wb2.write(NULL_OUTPUT_STREAM));
assertDoesNotThrow(() -> wb2.write(NULL_OUTPUT_STREAM));
assertDoesNotThrow(() -> wb2.write(NullOutputStream.INSTANCE));
assertDoesNotThrow(() -> wb2.write(NullOutputStream.INSTANCE));
}
}
}
@ -460,7 +460,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook {
}
}
assertDoesNotThrow(() -> swb.write(NULL_OUTPUT_STREAM));
assertDoesNotThrow(() -> swb.write(NullOutputStream.INSTANCE));
swb.dispose();
}
}
@ -478,7 +478,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook {
File input = XSSFTestDataSamples.getSampleFile("sample.xlsx");
try (OPCPackage pkg = OPCPackage.open(input, PackageAccess.READ)) {
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (XSSFWorkbook xssf = new XSSFWorkbook(pkg)) {
try (SXSSFWorkbook wb = new SXSSFWorkbook(xssf, 2)) {
Sheet s = wb.createSheet(sheetName);
@ -521,7 +521,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook {
void addHyperlink() throws Exception {
try (
SXSSFWorkbook wb = new SXSSFWorkbook();
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
SXSSFSheet sheet = wb.createSheet("s1");
SXSSFRow row = sheet.createRow(0);
@ -547,7 +547,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook {
void addDimension() throws IOException {
try (
SXSSFWorkbook wb = new SXSSFWorkbook();
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
SXSSFSheet sheet = wb.createSheet();
sheet.createRow(2).createCell(3).setCellValue("top left");
@ -566,7 +566,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook {
void addDimension1() throws IOException {
try (
SXSSFWorkbook wb = new SXSSFWorkbook(1);
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
SXSSFSheet sheet = wb.createSheet();
sheet.createRow(2).createCell(3).setCellValue("top left");
@ -591,7 +591,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook {
assertEquals(6, sheet.getLastRowNum());
try (
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(wb);
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
sxssfWorkbook.write(bos);
try (XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) {
@ -606,7 +606,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook {
void addDimensionDisabled() throws IOException {
try (
SXSSFWorkbook wb = new SXSSFWorkbook();
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
wb.setShouldCalculateSheetDimensions(false);
SXSSFSheet sheet = wb.createSheet();

View File

@ -253,7 +253,7 @@ public final class TestSXSSFBugs extends BaseTestBugzillaIssues {
@Test
void test65619() throws Exception {
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
try (SXSSFWorkbook workbook = new SXSSFWorkbook(100)) {
SXSSFSheet sheet = workbook.createSheet("Test Sheet 1");
Font font = workbook.createFont();
@ -308,7 +308,7 @@ public final class TestSXSSFBugs extends BaseTestBugzillaIssues {
assertEquals(value, cell.getStringCellValue());
// so far so good
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(bos);
try (XSSFWorkbook testWb = new XSSFWorkbook(bos.toInputStream())) {
@ -356,7 +356,7 @@ public final class TestSXSSFBugs extends BaseTestBugzillaIssues {
assertEquals(blueStyle.getIndex(), r3.getCell(4).getCellStyle().getIndex());
assertEquals(pinkStyle.getIndex(), r3.getCell(6).getCellStyle().getIndex());
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(bos);
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
XSSFSheet wb2Sheet = wb2.getSheetAt(0);

View File

@ -278,7 +278,7 @@ public final class TestUnfixedBugs {
checkRow57423(testSheet, 17, "17");
checkRow57423(testSheet, 18, "18");
UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().get();
((XSSFSheet)testSheet).write(stream);
// verify that the resulting XML has the rows in correct order as required by Excel

View File

@ -19,7 +19,6 @@ package org.apache.poi.xssf.usermodel;
import static java.time.Duration.between;
import static java.time.Instant.now;
import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.logging.log4j.util.Unbox.box;
import static org.apache.poi.extractor.ExtractorFactory.OOXML_PACKAGE;
import static org.apache.poi.openxml4j.opc.TestContentType.isOldXercesActive;
@ -48,6 +47,7 @@ import java.util.*;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -1537,7 +1537,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
Thread.sleep(10);
}
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(8096);
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(8096).get();
wb.write(bos);
byte[] firstSave = bos.toByteArray();
bos.reset();
@ -2982,7 +2982,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
// we currently only populate the dimension during writing out
// to avoid having to iterate all rows/cells in each add/remove of a row or cell
wb.write(NULL_OUTPUT_STREAM);
wb.write(NullOutputStream.INSTANCE);
assertEquals("B2:H5", ((XSSFSheet) sheet).getCTWorksheet().getDimension().getRef());
}
@ -3003,7 +3003,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
// we currently only populate the dimension during writing out
// to avoid having to iterate all rows/cells in each add/remove of a row or cell
wb.write(NULL_OUTPUT_STREAM);
wb.write(NullOutputStream.INSTANCE);
assertEquals("B2:XFD5", ((XSSFSheet) sheet).getCTWorksheet().getDimension().getRef());
}
@ -3691,7 +3691,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
assertEquals(blueStyle.getIndex(), r3.getCell(4).getCellStyle().getIndex());
assertEquals(pinkStyle.getIndex(), r3.getCell(6).getCellStyle().getIndex());
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(bos);
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
XSSFSheet wb2Sheet = wb2.getSheetAt(0);
@ -3778,13 +3778,13 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
}
// read bytes of workbook before
UnsynchronizedByteArrayOutputStream bosOrig = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bosOrig = UnsynchronizedByteArrayOutputStream.builder().get();
try (FileInputStream fis = new FileInputStream(temp_excel_poi)) {
IOUtils.copy(fis, bosOrig);
}
// for the encrypted bytes
UnsynchronizedByteArrayOutputStream bosEnc = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bosEnc = UnsynchronizedByteArrayOutputStream.builder().get();
/* encrypt excel by poi */
try (POIFSFileSystem fs = new POIFSFileSystem()) {
@ -3810,7 +3810,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
}
// for the decrytped bytes
UnsynchronizedByteArrayOutputStream bosDec = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bosDec = UnsynchronizedByteArrayOutputStream.builder().get();
/* decrypt excel by poi */
try (POIFSFileSystem fileSystem = new POIFSFileSystem(temp_excel_poi_encrypt)) {

View File

@ -311,7 +311,7 @@ public final class TestXSSFComment extends BaseTestCellComment {
@Test
void bug59388CommentVisible() throws IOException {
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("59388.xlsx")) {
Sheet sheet = wb.getSheetAt(0);
Cell a1 = sheet.getRow(0).getCell(0);
@ -474,7 +474,7 @@ public final class TestXSSFComment extends BaseTestCellComment {
}
private void _testMoveIsSaved(Workbook workbook) throws Exception {
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
CreationHelper factory = workbook.getCreationHelper();
Sheet sheet = workbook.createSheet();
Row row = sheet.createRow(0);
@ -511,7 +511,7 @@ public final class TestXSSFComment extends BaseTestCellComment {
}
private void _testModificationIsSaved(Workbook workbook) throws Exception {
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
CreationHelper factory = workbook.getCreationHelper();
Sheet sheet = workbook.createSheet();
Row row = sheet.createRow(0);

View File

@ -386,7 +386,7 @@ public final class TestXSSFSheet extends BaseTestXSheet {
void saveGroupColumns() throws IOException {
try (
XSSFWorkbook workbook = new XSSFWorkbook();
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
XSSFSheet sheet = workbook.createSheet();
XSSFRow row0 = sheet.createRow(0);
@ -2268,7 +2268,7 @@ public final class TestXSSFSheet extends BaseTestXSheet {
void testBug64536() throws IOException {
try (
XSSFWorkbook xssfWorkbook = (XSSFWorkbook) _testDataProvider.openSampleWorkbook("1_NoIden.xlsx");
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
XSSFSheet fileSheet = xssfWorkbook.getSheetAt(0);
assertEquals(CellRangeAddress.valueOf("B1:D9"), fileSheet.getDimension());

View File

@ -651,7 +651,7 @@ public final class TestXSSFTable {
void testNamesWithNewLines() throws IOException {
try (
XSSFWorkbook wb = new XSSFWorkbook();
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
XSSFSheet sheet = wb.createSheet();
@ -739,7 +739,7 @@ public final class TestXSSFTable {
void bug66213() throws IOException {
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("table-sample.xlsx")) {
wb.cloneSheet(0, "Test");
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(bos);
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
XSSFSheet sheet0 = wb2.getSheetAt(0);
@ -757,7 +757,7 @@ public final class TestXSSFTable {
void testCloneConditionalFormattingSamples() throws IOException {
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("ConditionalFormattingSamples.xlsx")) {
wb.cloneSheet(0, "Test");
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(bos);
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
XSSFSheet sheet0 = wb2.getSheetAt(0);
@ -773,7 +773,7 @@ public final class TestXSSFTable {
void testCloneSingleCellTable() throws IOException {
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("SingleCellTable.xlsx")) {
wb.cloneSheet(0, "Test");
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(bos);
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
XSSFSheet sheet0 = wb2.getSheetAt(0);

View File

@ -103,7 +103,7 @@ class TestXSSFVMLDrawing {
assertEquals("[True]", cldata.getVisibleList().toString());
//serialize and read again
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
vml.write(out);
XSSFVMLDrawing vml2 = new XSSFVMLDrawing();

View File

@ -17,6 +17,7 @@
package org.apache.poi.xssf.usermodel;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
@ -80,7 +81,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.zip.CRC32;
import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.poi.hssf.HSSFTestDataSamples.openSampleFileStream;
import static org.apache.poi.xssf.XSSFTestDataSamples.openSampleWorkbook;
import static org.apache.poi.xssf.XSSFTestDataSamples.writeOut;
@ -573,7 +573,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
sheet.groupColumn((short) 4, (short) 5);
accessWorkbook(workbook);
workbook.write(NULL_OUTPUT_STREAM);
workbook.write(NullOutputStream.INSTANCE);
accessWorkbook(workbook);
}
}
@ -1240,7 +1240,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
@Test
void testNewWorkbookWithTempFilePackageParts() throws Exception {
try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
assertFalse(ZipPackage.useTempFilePackageParts(), "useTempFilePackageParts defaults to false?");
assertFalse(ZipPackage.encryptTempFilePackageParts(), "encryptTempFilePackageParts defaults to false?");
ZipPackage.setUseTempFilePackageParts(true);
@ -1264,7 +1264,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
@Test
void testNewWorkbookWithEncryptedTempFilePackageParts() throws Exception {
try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
assertFalse(ZipPackage.useTempFilePackageParts(), "useTempFilePackageParts defaults to false?");
assertFalse(ZipPackage.encryptTempFilePackageParts(), "encryptTempFilePackageParts defaults to false?");
ZipPackage.setUseTempFilePackageParts(true);
@ -1293,8 +1293,8 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
String nameA = "link-external-workbook-a.xlsx";
try (
UnsynchronizedByteArrayOutputStream bosA = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bosB = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bosA = UnsynchronizedByteArrayOutputStream.builder().get();
UnsynchronizedByteArrayOutputStream bosB = UnsynchronizedByteArrayOutputStream.builder().get();
XSSFWorkbook workbookA = new XSSFWorkbook();
XSSFWorkbook workbookB = new XSSFWorkbook()
) {
@ -1343,8 +1343,8 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
String nameA = "cache-external-workbook-a.xlsx";
try (
UnsynchronizedByteArrayOutputStream bosA = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bosB = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bosA = UnsynchronizedByteArrayOutputStream.builder().get();
UnsynchronizedByteArrayOutputStream bosB = UnsynchronizedByteArrayOutputStream.builder().get();
XSSFWorkbook workbookA = new XSSFWorkbook();
XSSFWorkbook workbookB = new XSSFWorkbook()
) {
@ -1381,7 +1381,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
@Test
void checkExistingFileForR1C1Refs() throws IOException {
try (
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
XSSFWorkbook wb = openSampleWorkbook("WithTable.xlsx")
) {
assertEquals(CellReferenceType.A1, wb.getCellReferenceType());
@ -1397,7 +1397,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
@Test
void checkNewFileForR1C1Refs() throws IOException {
try (
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
XSSFWorkbook wb = new XSSFWorkbook()
) {
assertEquals(CellReferenceType.UNKNOWN, wb.getCellReferenceType());

View File

@ -152,7 +152,7 @@ final class TestXSSFBubbleChartData {
setRoundedCorners(chart, false);
// Write the output to a file
try (UnsynchronizedByteArrayOutputStream outStream = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream outStream = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(outStream);
try (XSSFWorkbook wb2 = new XSSFWorkbook(outStream.toInputStream())) {
// see if this fails

View File

@ -69,7 +69,7 @@ public final class TestEvilUnclosedBRFixingInputStream {
// overflow or only part in the buffer
for(int i=5; i<orig.length; i++) {
try (EvilUnclosedBRFixingInputStream inp = new EvilUnclosedBRFixingInputStream(orig);
UnsynchronizedByteArrayOutputStream bout = new UnsynchronizedByteArrayOutputStream()) {
UnsynchronizedByteArrayOutputStream bout = UnsynchronizedByteArrayOutputStream.builder().get()) {
for (;;) {
byte[] b = new byte[i];
int r = inp.read(b);

View File

@ -32,7 +32,7 @@ public class XWPFTestDataSamples {
}
public static XWPFDocument writeOutAndReadBack(XWPFDocument doc) throws IOException {
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(4096);
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(4096).get();
doc.write(baos);
return new XWPFDocument(baos.toInputStream());
}

View File

@ -58,7 +58,7 @@ class TestChangeTracking {
r1.setText("Lorem ipsum dolor sit amet.");
doc.setTrackRevisions(true);
try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) {
doc.write(out);
try (InputStream inputStream = out.toInputStream()) {

View File

@ -185,7 +185,12 @@ public class OLE2ScratchpadExtractorFactory implements ExtractorProvider {
for (AttachmentChunks attachment : msg.getAttachmentFiles()) {
if (attachment.getAttachData() != null) {
byte[] data = attachment.getAttachData().getValue();
nonPOIFS.add( new UnsynchronizedByteArrayInputStream(data) );
try {
nonPOIFS.add(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get() );
} catch (IOException e) {
// is actually impossible with ByteArray, but still declared in the interface
throw new IllegalStateException(e);
}
} else if (attachment.getAttachmentDirectory() != null) {
dirs.add(attachment.getAttachmentDirectory().getDirectory());
}

View File

@ -53,7 +53,7 @@ public class HDGFLZW extends LZWDecompresser {
* @throws IOException when the InputStream can't be read
*/
public byte[] compress(InputStream src) throws IOException {
UnsynchronizedByteArrayOutputStream res = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream res = UnsynchronizedByteArrayOutputStream.builder().get();
compress(src,res);
return res.toByteArray();
}

View File

@ -92,7 +92,7 @@ public final class CompressedStreamStore extends StreamStore {
* Decompresses the given data, returning it as header + contents
*/
public static byte[][] decompress(byte[] data, int offset, int length) throws IOException {
try (UnsynchronizedByteArrayInputStream bais = new UnsynchronizedByteArrayInputStream(data, offset, length)) {
try (UnsynchronizedByteArrayInputStream bais = UnsynchronizedByteArrayInputStream.builder().setByteArray(data).setOffset(offset).setLength(length).get()) {
// Decompress
HDGFLZW lzw = new HDGFLZW();
byte[] decompressed = lzw.decompress(bais);

View File

@ -65,7 +65,7 @@ public class HemfImageRenderer implements ImageRenderer, EmbeddedExtractor {
if (!PictureData.PictureType.EMF.contentType.equals(contentType)) {
throw new IOException("Invalid picture type");
}
image = new HemfPicture(new UnsynchronizedByteArrayInputStream(data));
image = new HemfPicture(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get());
}
@Override

View File

@ -792,7 +792,7 @@ public final class HemfFill {
return (long)undefinedSpace1 + bitmap.init(leis, dibSize);
}
final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(cbBmi+cbBits);
final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(cbBmi+cbBits).get();
final long cbBmiSrcAct = IOUtils.copy(leis, bos, cbBmi);
assert (cbBmiSrcAct == cbBmi);
leis.skipFully(undefinedSpace2);

View File

@ -396,7 +396,7 @@ public class HemfPlusBrush {
public EmfPlusBrushData getBrushData(List<? extends EmfPlusObjectData> continuedObjectData) {
EmfPlusBrushData brushData = brushType.constructor.get();
byte[] buf = getRawData(continuedObjectData);
try (UnsynchronizedByteArrayInputStream bis = new UnsynchronizedByteArrayInputStream(buf)){
try (UnsynchronizedByteArrayInputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(buf).get()){
brushData.init(new LittleEndianInputStream(bis), buf.length);
} catch (IOException e) {
throw new IllegalStateException(e);
@ -410,7 +410,7 @@ public class HemfPlusBrush {
* @throws IllegalStateException if the data cannot be processed
*/
public byte[] getRawData(List<? extends EmfPlusObjectData> continuedObjectData) {
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
bos.write(getBrushBytes());
if (continuedObjectData != null) {
for (EmfPlusObjectData od : continuedObjectData) {

View File

@ -419,13 +419,13 @@ public class HemfPlusImage {
if (getBitmapType() == EmfPlusBitmapDataType.PIXEL) {
return new Rectangle2D.Double(0, 0, bitmapWidth, bitmapHeight);
} else {
try(UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(getRawData(continuedObjectData))) {
try(UnsynchronizedByteArrayInputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(getRawData(continuedObjectData)).get()) {
BufferedImage bi = ImageIO.read(is);
return new Rectangle2D.Double(bi.getMinX(), bi.getMinY(), bi.getWidth(), bi.getHeight());
}
}
case METAFILE:
try(UnsynchronizedByteArrayInputStream bis = new UnsynchronizedByteArrayInputStream(getRawData(continuedObjectData))) {
try(UnsynchronizedByteArrayInputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(getRawData(continuedObjectData)).get()) {
switch (getMetafileType()) {
case Wmf:
case WmfPlaceable:
@ -453,7 +453,7 @@ public class HemfPlusImage {
* @throws IllegalStateException if the data cannot be read
*/
public byte[] getRawData(List<? extends EmfPlusObjectData> continuedObjectData) {
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
bos.write(getImageData());
if (continuedObjectData != null) {
for (EmfPlusObjectData od : continuedObjectData) {

View File

@ -293,7 +293,7 @@ public class HemfEmbeddedIterator implements Iterator<HwmfEmbedded> {
private void compressGDIBitmap(EmfPlusImage img, HwmfEmbedded emb, HwmfEmbeddedType et) {
BufferedImage bi = img.readGDIImage(emb.getRawData());
try {
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
// use HwmfEmbeddedType literal for conversion
ImageIO.write(bi, et.toString(), bos);
emb.setData(bos.toByteArray());
@ -318,7 +318,7 @@ public class HemfEmbeddedIterator implements Iterator<HwmfEmbedded> {
: epo.getTotalObjectSize();
IOUtils.safelyAllocateCheck(totalSize, MAX_RECORD_LENGTH);
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(totalSize)) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(totalSize).get()) {
boolean hasNext = false;
do {
EmfPlusImage img = epo.getObjectData();

View File

@ -116,7 +116,7 @@ public class MAPIAttribute {
"instead received a " + parent.getProperty() + " one"
);
}
try(UnsynchronizedByteArrayInputStream inp = new UnsynchronizedByteArrayInputStream(parent.getData())) {
try(UnsynchronizedByteArrayInputStream inp = UnsynchronizedByteArrayInputStream.builder().setByteArray(parent.getData()).get()) {
// First up, get the number of attributes
int count = LittleEndian.readInt(inp);
List<MAPIAttribute> attrs = new ArrayList<>();

View File

@ -46,7 +46,7 @@ public final class MAPIRtfAttribute extends MAPIAttribute {
// Decompress it, removing any trailing padding as needed
CompressedRTF rtf = new CompressedRTF();
byte[] tmp;
try (InputStream is = new UnsynchronizedByteArrayInputStream(data)) {
try (InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get()) {
tmp = rtf.decompress(is);
}

View File

@ -83,7 +83,7 @@ public abstract class HPBFPart {
generateData();
// Write out
try (UnsynchronizedByteArrayInputStream bais = new UnsynchronizedByteArrayInputStream(data)) {
try (UnsynchronizedByteArrayInputStream bais = UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get()) {
dir.createDocument(path[path.length-1], bais);
}
}

View File

@ -91,7 +91,7 @@ public abstract class Bitmap extends HSLFPictureData {
@Override
public Dimension getImageDimension() {
try (InputStream is = new UnsynchronizedByteArrayInputStream(getData())){
try (InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(getData()).get()){
BufferedImage bi = ImageIO.read(is);
return new Dimension(
(int)Units.pixelToPoints(bi.getWidth()),

View File

@ -69,9 +69,9 @@ public final class EMF extends Metafile {
header.read(rawdata, CHECKSUM_SIZE);
try (
InputStream is = new UnsynchronizedByteArrayInputStream(rawdata);
InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(rawdata).get();
InflaterInputStream inflater = new InflaterInputStream(is);
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()
) {
long len = IOUtils.skipFully(is,header.getSize() + (long)CHECKSUM_SIZE);
assert(len == header.getSize() + CHECKSUM_SIZE);

View File

@ -91,7 +91,7 @@ public abstract class Metafile extends HSLFPictureData {
public void read(byte[] data, int offset) {
try (
LittleEndianInputStream leis = new LittleEndianInputStream(
new UnsynchronizedByteArrayInputStream(data, offset, RECORD_LENGTH))
UnsynchronizedByteArrayInputStream.builder().setByteArray(data).setOffset(offset).setLength(RECORD_LENGTH).get())
) {
wmfsize = leis.readInt();
@ -204,7 +204,7 @@ public abstract class Metafile extends HSLFPictureData {
}
protected static byte[] compress(byte[] bytes, int offset, int length) {
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
try (DeflaterOutputStream deflater = new DeflaterOutputStream(out)) {
deflater.write(bytes, offset, length);
} catch (IOException ignored) {

View File

@ -72,7 +72,7 @@ public final class PICT extends Metafile {
@Override
public byte[] getData(){
byte[] rawdata = getRawData();
try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) {
byte[] macheader = new byte[512];
out.write(macheader);
int pos = CHECKSUM_SIZE*getUIDInstanceCount();
@ -88,13 +88,13 @@ public final class PICT extends Metafile {
Header header = new Header();
header.read(data, pos);
long bs_exp = (long)pos + header.getSize();
try (InputStream bis = new UnsynchronizedByteArrayInputStream(data)) {
try (InputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get()) {
long bs_act = IOUtils.skipFully(bis, bs_exp);
if (bs_exp != bs_act) {
throw new EOFException();
}
byte[] chunk = new byte[4096];
try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(header.getWmfSize())) {
try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(header.getWmfSize()).get()) {
try (InflaterInputStream inflater = new InflaterInputStream(bis)) {
int count;
while ((count = inflater.read(chunk)) >= 0) {

View File

@ -65,7 +65,7 @@ public final class WMF extends Metafile {
@Override
public byte[] getData(){
byte[] rawdata = getRawData();
try (InputStream is = new UnsynchronizedByteArrayInputStream(rawdata)) {
try (InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(rawdata).get()) {
Header header = new Header();
@ -75,7 +75,7 @@ public final class WMF extends Metafile {
assert(skipped == skipLen);
ImageHeaderWMF aldus = new ImageHeaderWMF(header.getBounds());
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
aldus.write(out);
try (InflaterInputStream inflater = new InflaterInputStream( is )) {

View File

@ -65,7 +65,7 @@ public final class PPTXMLDump {
return null;
}
try (InputStream is = dn.createDocumentInputStream(entry);
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
IOUtils.copy(is, bos);
return bos.toByteArray();
}

View File

@ -147,7 +147,7 @@ public final class SlideIdListing {
}
// Increase the position by the on disk size
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
r.writeOut(baos);
pos += baos.size();
}

View File

@ -146,7 +146,7 @@ public final class SlideShowRecordDumper {
public int getDiskLen(org.apache.poi.hslf.record.Record r) throws IOException {
int diskLen = 0;
if (r != null) {
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
r.writeOut(baos);
diskLen = baos.size();
}
@ -158,7 +158,7 @@ public final class SlideShowRecordDumper {
return "<<null>>";
}
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
r.writeOut(baos);
byte[] b = baos.toByteArray();
return HexDump.dump(b, 0, 0);
@ -258,7 +258,7 @@ public final class SlideShowRecordDumper {
if (optEscher && cname.equals("PPDrawing")) {
DefaultEscherRecordFactory factory = new HSLFEscherRecordFactory();
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
r.writeOut(baos);
byte[] b = baos.toByteArray();

View File

@ -79,7 +79,7 @@ public final class UserEditAndPersistListing {
}
// Increase the position by the on disk size
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
r.writeOut(baos);
pos += baos.size();
}
@ -99,7 +99,7 @@ public final class UserEditAndPersistListing {
}
// Increase the position by the on disk size
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
r.writeOut(baos);
pos += baos.size();
}

View File

@ -379,7 +379,7 @@ public class TextPropCollection implements GenericRecord, Duplicatable {
out.append(" bytes that would be written: \n");
try {
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
writeOut(baos);
byte[] b = baos.toByteArray();
out.append(HexDump.dump(b, 0, 0));

View File

@ -154,7 +154,7 @@ public final class ColorSchemeAtom extends RecordAtom {
byte[] ret = new byte[3];
// Serialise to bytes, then grab the right ones out
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try {
writeLittleEndian(rgb,baos);
} catch(IOException ie) {

View File

@ -264,7 +264,7 @@ public class CurrentUserAtom {
*/
public void writeToFS(POIFSFileSystem fs) throws IOException {
// Grab contents
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
writeOut(baos);
try (InputStream is = baos.toInputStream()) {
// Write out

View File

@ -89,7 +89,7 @@ public final class EscherTextboxWrapper extends RecordContainer {
// Write out our children, and stuff them into the Escher layer
// Grab the children's data
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
for (org.apache.poi.hslf.record.Record r : _children) {
r.writeOut(baos);
}

View File

@ -124,7 +124,7 @@ public class ExOleObjStg extends PositionDependentRecordAtom implements PersistR
* @param data the embedded data.
*/
public void setData(byte[] data) throws IOException {
try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
DeflaterOutputStream def = new DeflaterOutputStream(out)) {
//first four bytes is the length of the raw data
byte[] b = new byte[4];

View File

@ -93,7 +93,7 @@ public class HSLFEscherClientDataRecord extends EscherClientDataRecord {
@Override
public byte[] getRemainingData() {
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
for (org.apache.poi.hslf.record.Record r : _childRecords) {
r.writeOut(bos);
}

Some files were not shown because too many files have changed in this diff Show More