mirror of https://github.com/apache/poi.git
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:
parent
c8f9fe4c2c
commit
d3e35e740a
|
@ -57,7 +57,7 @@ public class OSGiExtractorsIT extends BaseOSGiTestCase {
|
||||||
box.setText("Hello, World!");
|
box.setText("Hello, World!");
|
||||||
box.setAnchor(new Rectangle(36, 15, 648, 65));
|
box.setAnchor(new Rectangle(36, 15, 648, 65));
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
ppt.write(out);
|
ppt.write(out);
|
||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ public class OSGiExtractorsIT extends BaseOSGiTestCase {
|
||||||
Sheet s = wb.createSheet("OSGi");
|
Sheet s = wb.createSheet("OSGi");
|
||||||
s.createRow(0).createCell(0).setCellValue("Hello, World!");
|
s.createRow(0).createCell(0).setCellValue("Hello, World!");
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
wb.write(out);
|
wb.write(out);
|
||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class OSGiSlideShowIT extends BaseOSGiTestCase {
|
||||||
}
|
}
|
||||||
box2.setAnchor(new Rectangle(36, 80, 648, 400));
|
box2.setAnchor(new Rectangle(36, 80, 648, 400));
|
||||||
|
|
||||||
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
ppt.write(baos);
|
ppt.write(baos);
|
||||||
try (InputStream bais = baos.toInputStream()) {
|
try (InputStream bais = baos.toInputStream()) {
|
||||||
ppt = SlideShowFactory.create(bais);
|
ppt = SlideShowFactory.create(bais);
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class OSGiSpreadsheetIT extends BaseOSGiTestCase {
|
||||||
s.createRow(0).createCell(0).setCellValue("With OSGi");
|
s.createRow(0).createCell(0).setCellValue("With OSGi");
|
||||||
s.createRow(1).createCell(0).setCellFormula("SUM(A1:B3)");
|
s.createRow(1).createCell(0).setCellFormula("SUM(A1:B3)");
|
||||||
|
|
||||||
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
wb.write(baos);
|
wb.write(baos);
|
||||||
try (InputStream bais = baos.toInputStream()) {
|
try (InputStream bais = baos.toInputStream()) {
|
||||||
wb = WorkbookFactory.create(bais);
|
wb = WorkbookFactory.create(bais);
|
||||||
|
|
|
@ -192,7 +192,7 @@ public final class OfficeDrawing {
|
||||||
private static int loadPicture( String path, HSSFWorkbook wb ) throws IOException {
|
private static int loadPicture( String path, HSSFWorkbook wb ) throws IOException {
|
||||||
int pictureIndex;
|
int pictureIndex;
|
||||||
try (FileInputStream fis = new FileInputStream(path);
|
try (FileInputStream fis = new FileInputStream(path);
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
IOUtils.copy(fis, bos);
|
IOUtils.copy(fis, bos);
|
||||||
pictureIndex = wb.addPicture(bos.toByteArray(), Workbook.PICTURE_TYPE_PNG);
|
pictureIndex = wb.addPicture(bos.toByteArray(), Workbook.PICTURE_TYPE_PNG);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ public final class CustomXMLMapping {
|
||||||
for (XSSFMap map : wb.getCustomXMLMappings()) {
|
for (XSSFMap map : wb.getCustomXMLMappings()) {
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
exporter.exportToXML(os, true);
|
exporter.exportToXML(os, true);
|
||||||
String xml = os.toString(StandardCharsets.UTF_8);
|
String xml = os.toString(StandardCharsets.UTF_8);
|
||||||
System.out.println(xml);
|
System.out.println(xml);
|
||||||
|
|
|
@ -35,7 +35,7 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestXLSX2CSV {
|
public class TestXLSX2CSV {
|
||||||
private PrintStream err;
|
private PrintStream err;
|
||||||
private final UnsynchronizedByteArrayOutputStream errorBytes = new UnsynchronizedByteArrayOutputStream();
|
private final UnsynchronizedByteArrayOutputStream errorBytes = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws UnsupportedEncodingException {
|
public void setUp() throws UnsupportedEncodingException {
|
||||||
|
@ -77,7 +77,7 @@ public class TestXLSX2CSV {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSampleFile() throws Exception {
|
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());
|
PrintStream out = new PrintStream(outputBytes, true, StandardCharsets.UTF_8.name());
|
||||||
|
|
||||||
// The package open is instantaneous, as it should be.
|
// The package open is instantaneous, as it should be.
|
||||||
|
@ -96,7 +96,7 @@ public class TestXLSX2CSV {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMinColumns() throws Exception {
|
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());
|
PrintStream out = new PrintStream(outputBytes, true, StandardCharsets.UTF_8.name());
|
||||||
|
|
||||||
// The package open is instantaneous, as it should be.
|
// The package open is instantaneous, as it should be.
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class POIFSFileHandler extends AbstractFileHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handlePOIDocument(POIDocument doc) throws Exception {
|
protected void handlePOIDocument(POIDocument doc) throws Exception {
|
||||||
try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
doc.write(out);
|
doc.write(out);
|
||||||
|
|
||||||
try (InputStream in = out.toInputStream();
|
try (InputStream in = out.toInputStream();
|
||||||
|
|
|
@ -49,7 +49,7 @@ public abstract class SlideShowHandler extends POIFSFileHandler {
|
||||||
readPictures(ss);
|
readPictures(ss);
|
||||||
|
|
||||||
// write out the file
|
// write out the file
|
||||||
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
ss.write(out);
|
ss.write(out);
|
||||||
|
|
||||||
readContent(ss);
|
readContent(ss);
|
||||||
|
|
|
@ -61,7 +61,7 @@ public abstract class SpreadsheetHandler extends AbstractFileHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private UnsynchronizedByteArrayOutputStream writeToArray(Workbook wb) throws IOException {
|
private UnsynchronizedByteArrayOutputStream writeToArray(Workbook wb) throws IOException {
|
||||||
UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
wb.write(stream);
|
wb.write(stream);
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,11 +41,11 @@ public class XSSFBFileHandler extends AbstractFileHandler {
|
||||||
public void handleFile(InputStream stream, String path) throws Exception {
|
public void handleFile(InputStream stream, String path) throws Exception {
|
||||||
byte[] bytes = IOUtils.toByteArray(stream);
|
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);
|
testOne(opcPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
testNotHandledByWorkbookException(OPCPackage.open(new UnsynchronizedByteArrayInputStream(bytes)));
|
testNotHandledByWorkbookException(OPCPackage.open(UnsynchronizedByteArrayInputStream.builder().setByteArray(bytes).get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testNotHandledByWorkbookException(OPCPackage pkg) throws IOException {
|
private void testNotHandledByWorkbookException(OPCPackage pkg) throws IOException {
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.stress;
|
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.apache.poi.xssf.XSSFTestDataSamples.getSampleFile;
|
||||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
@ -36,6 +35,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import javax.xml.transform.TransformerException;
|
import javax.xml.transform.TransformerException;
|
||||||
|
|
||||||
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||||
import org.apache.poi.EncryptedDocumentException;
|
import org.apache.poi.EncryptedDocumentException;
|
||||||
import org.apache.poi.examples.ss.ExcelComparator;
|
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
|
// 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);
|
IOUtils.copy(stream, out);
|
||||||
|
|
||||||
if (pass != null) {
|
if (pass != null) {
|
||||||
|
@ -156,7 +156,7 @@ public class XSSFFileHandler extends SpreadsheetHandler {
|
||||||
TransformerException {
|
TransformerException {
|
||||||
for (XSSFMap map : wb.getCustomXMLMappings()) {
|
for (XSSFMap map : wb.getCustomXMLMappings()) {
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
exporter.exportToXML(NULL_OUTPUT_STREAM, true);
|
exporter.exportToXML(NullOutputStream.INSTANCE, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,12 @@ public final class MemoryPackagePart extends PackagePart {
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
data = new byte[0];
|
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
|
@Override
|
||||||
|
@ -113,7 +118,7 @@ public final class MemoryPackagePart extends PackagePart {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean load(InputStream is) throws InvalidFormatException {
|
public boolean load(InputStream is) throws InvalidFormatException {
|
||||||
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
// Grab the data
|
// Grab the data
|
||||||
IOUtils.copy(is, baos);
|
IOUtils.copy(is, baos);
|
||||||
// Save it
|
// Save it
|
||||||
|
|
|
@ -33,7 +33,7 @@ public final class MemoryPackagePartOutputStream extends OutputStream {
|
||||||
|
|
||||||
public MemoryPackagePartOutputStream(MemoryPackagePart part) {
|
public MemoryPackagePartOutputStream(MemoryPackagePart part) {
|
||||||
this._part = part;
|
this._part = part;
|
||||||
_buff = new UnsynchronizedByteArrayOutputStream();
|
_buff = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -104,7 +104,7 @@ import org.apache.poi.util.TempFile;
|
||||||
throw new IOException("temp file " + tempFile.getAbsolutePath() + " is missing");
|
throw new IOException("temp file " + tempFile.getAbsolutePath() + " is missing");
|
||||||
}
|
}
|
||||||
} else if (data != null) {
|
} else if (data != null) {
|
||||||
return new UnsynchronizedByteArrayInputStream(data);
|
return UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get();
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Cannot retrieve data from Zip Entry, probably because the Zip Entry was closed before the data was requested.");
|
throw new IOException("Cannot retrieve data from Zip Entry, probably because the Zip Entry was closed before the data was requested.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ import org.ietf.jgss.Oid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] sign() throws IOException, GeneralSecurityException {
|
public byte[] sign() throws IOException, GeneralSecurityException {
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
bos.write(getHashMagic());
|
bos.write(getHashMagic());
|
||||||
bos.write(md.digest());
|
bos.write(md.digest());
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ import org.ietf.jgss.Oid;
|
||||||
// in an earlier release the hashMagic (aka DigestAlgorithmIdentifier) contained only
|
// in an earlier release the hashMagic (aka DigestAlgorithmIdentifier) contained only
|
||||||
// an object identifier, but to conform with the header generated by the
|
// an object identifier, but to conform with the header generated by the
|
||||||
// javax-signature API, the empty <associated parameters> are also included
|
// 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();
|
final byte[] oidBytes = new Oid(algo.rsaOid).getDER();
|
||||||
|
|
||||||
bos.write(0x30);
|
bos.write(0x30);
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class OOXMLURIDereferencer implements URIDereferencer {
|
||||||
if (part.getPartName().toString().endsWith(".rels")) {
|
if (part.getPartName().toString().endsWith(".rels")) {
|
||||||
// although xmlsec has an option to ignore line breaks, currently this
|
// although xmlsec has an option to ignore line breaks, currently this
|
||||||
// only affects .rels files, so we only modify these
|
// 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; ) {
|
for (int ch; (ch = dataStream.read()) != -1; ) {
|
||||||
if (ch == 10 || ch == 13) continue;
|
if (ch == 10 || ch == 13) continue;
|
||||||
bos.write(ch);
|
bos.write(ch);
|
||||||
|
|
|
@ -341,7 +341,7 @@ public abstract class SignatureLine {
|
||||||
rnd.drawImage(gfx, new Rectangle2D.Double(0, 0, defaultWidth, defaultHeight));
|
rnd.drawImage(gfx, new Rectangle2D.Double(0, 0, defaultWidth, defaultHeight));
|
||||||
gfx.dispose();
|
gfx.dispose();
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
ImageIO.write(bi, "PNG", bos);
|
ImageIO.write(bi, "PNG", bos);
|
||||||
return bos.toByteArray();
|
return bos.toByteArray();
|
||||||
}
|
}
|
||||||
|
@ -426,7 +426,7 @@ public abstract class SignatureLine {
|
||||||
|
|
||||||
gfx.dispose();
|
gfx.dispose();
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
ImageIO.write(bi, "PNG", bos);
|
ImageIO.write(bi, "PNG", bos);
|
||||||
return bos.toByteArray();
|
return bos.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,9 +223,12 @@ public class XAdESXLSignatureFacet implements SignatureFacet {
|
||||||
X509CRL crl;
|
X509CRL crl;
|
||||||
try {
|
try {
|
||||||
crl = (X509CRL) this.certificateFactory
|
crl = (X509CRL) this.certificateFactory
|
||||||
.generateCRL(new UnsynchronizedByteArrayInputStream(encodedCrl));
|
.generateCRL(UnsynchronizedByteArrayInputStream.builder().setByteArray(encodedCrl).get());
|
||||||
} catch (CRLException e) {
|
} catch (CRLException e) {
|
||||||
throw new IllegalStateException("CRL parse error: " + e.getMessage(), 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();
|
CRLIdentifierType crlIdentifier = crlRef.addNewCRLIdentifier();
|
||||||
|
@ -299,7 +302,7 @@ public class XAdESXLSignatureFacet implements SignatureFacet {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] getC14nValue(List<Node> nodeList, String c14nAlgoId) {
|
private static byte[] getC14nValue(List<Node> nodeList, String c14nAlgoId) {
|
||||||
try (UnsynchronizedByteArrayOutputStream c14nValue = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream c14nValue = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
for (Node node : nodeList) {
|
for (Node node : nodeList) {
|
||||||
/*
|
/*
|
||||||
* Re-initialize the c14n else the namespaces will get cached
|
* Re-initialize the c14n else the namespaces will get cached
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class SVGImageRenderer implements ImageRenderer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadImage(byte[] data, String contentType) throws IOException {
|
public void loadImage(byte[] data, String contentType) throws IOException {
|
||||||
loadImage(new UnsynchronizedByteArrayInputStream(data), contentType);
|
loadImage(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get(), contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -310,7 +310,7 @@ public class SVGRenderExtension extends DefaultExtensionHandler {
|
||||||
}
|
}
|
||||||
if (imgData == null) {
|
if (imgData == null) {
|
||||||
BufferedImage bi = imgRdr.getImage();
|
BufferedImage bi = imgRdr.getImage();
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
try {
|
try {
|
||||||
ImageIO.write(bi, "PNG", bos);
|
ImageIO.write(bi, "PNG", bos);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class XSLFMetroShape implements MetroShapeProvider {
|
||||||
/** parses the metro bytes to a XSLF shape */
|
/** parses the metro bytes to a XSLF shape */
|
||||||
@Override
|
@Override
|
||||||
public XSLFShape parseShape(byte[] metroBytes) throws IOException {
|
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");
|
PackagePartName shapePN = PackagingURIHelper.createPartName("/drs/shapexml.xml");
|
||||||
PackagePart shapePart = pkg.getPart(shapePN);
|
PackagePart shapePart = pkg.getPart(shapePN);
|
||||||
if (shapePart == null) {
|
if (shapePart == null) {
|
||||||
|
|
|
@ -372,7 +372,7 @@ public class XSLFPictureShape extends XSLFSimpleShape
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferedImage thmBI = renderer.getImage(dim);
|
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"
|
// use extension instead of enum name, because of "jpeg"
|
||||||
ImageIO.write(thmBI, pt.extension.substring(1), bos);
|
ImageIO.write(thmBI, pt.extension.substring(1), bos);
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class DummyFormat implements OutputFormat {
|
||||||
|
|
||||||
public DummyFormat() {
|
public DummyFormat() {
|
||||||
try {
|
try {
|
||||||
bos = new UnsynchronizedByteArrayOutputStream();
|
bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
dummy2d = new DummyGraphics2d(new PrintStream(bos, true, StandardCharsets.UTF_8.name()));
|
dummy2d = new DummyGraphics2d(new PrintStream(bos, true, StandardCharsets.UTF_8.name()));
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
|
|
|
@ -1019,7 +1019,7 @@ public class SXSSFWorkbook implements Workbook {
|
||||||
flushSheets();
|
flushSheets();
|
||||||
|
|
||||||
//Save the template
|
//Save the template
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
_wb.write(bos);
|
_wb.write(bos);
|
||||||
|
|
||||||
//Substitute the template entries with the generated sheet data files
|
//Substitute the template entries with the generated sheet data files
|
||||||
|
|
|
@ -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
|
// 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
|
// - build a fake styles.xml file with just this built-in
|
||||||
StylesTable styles = new StylesTable();
|
StylesTable styles = new StylesTable();
|
||||||
try (UnsynchronizedByteArrayInputStream bis = new UnsynchronizedByteArrayInputStream(
|
try (UnsynchronizedByteArrayInputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(
|
||||||
styleXML(dxfsNode, tableStyleNode).getBytes(StandardCharsets.UTF_8))) {
|
styleXML(dxfsNode, tableStyleNode).getBytes(StandardCharsets.UTF_8)).get()) {
|
||||||
styles.readFrom(bis);
|
styles.readFrom(bis);
|
||||||
}
|
}
|
||||||
styleMap.put(builtIn, new XSSFBuiltinTypeStyleStyle(builtIn, styles.getExplicitTableStyle(styleName)));
|
styleMap.put(builtIn, new XSSFBuiltinTypeStyleStyle(builtIn, styles.getExplicitTableStyle(styleName)));
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class XSSFChartSheet extends XSSFSheet {
|
||||||
@Override
|
@Override
|
||||||
protected void read(InputStream is) throws IOException {
|
protected void read(InputStream is) throws IOException {
|
||||||
//initialize the supeclass with a blank worksheet
|
//initialize the supeclass with a blank worksheet
|
||||||
super.read(new UnsynchronizedByteArrayInputStream(BLANK_WORKSHEET));
|
super.read(UnsynchronizedByteArrayInputStream.builder().setByteArray(BLANK_WORKSHEET).get());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
chartsheet = ChartsheetDocument.Factory.parse(is, DEFAULT_XML_OPTIONS).getChartsheet();
|
chartsheet = ChartsheetDocument.Factory.parse(is, DEFAULT_XML_OPTIONS).getChartsheet();
|
||||||
|
@ -95,7 +95,7 @@ public class XSSFChartSheet extends XSSFSheet {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] blankWorksheet(){
|
private static byte[] blankWorksheet(){
|
||||||
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
try {
|
try {
|
||||||
new XSSFSheet().write(out);
|
new XSSFSheet().write(out);
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
|
|
|
@ -511,7 +511,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
|
||||||
protected static OPCPackage newPackage(XSSFWorkbookType workbookType) {
|
protected static OPCPackage newPackage(XSSFWorkbookType workbookType) {
|
||||||
OPCPackage pkg = null;
|
OPCPackage pkg = null;
|
||||||
try {
|
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
|
// Main part
|
||||||
PackagePartName corePartName = PackagingURIHelper.createPartName(XSSFRelation.WORKBOOK.getDefaultFileName());
|
PackagePartName corePartName = PackagingURIHelper.createPartName(XSSFRelation.WORKBOOK.getDefaultFileName());
|
||||||
// Create main part relationship
|
// 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);
|
srcSheet.write(out);
|
||||||
try (InputStream bis = out.toInputStream()) {
|
try (InputStream bis = out.toInputStream()) {
|
||||||
clonedSheet.read(bis);
|
clonedSheet.read(bis);
|
||||||
|
@ -2466,7 +2466,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
|
||||||
|
|
||||||
Ole10Native ole10 = new Ole10Native(label, fileName, command, oleData);
|
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);
|
ole10.writeOut(bos);
|
||||||
|
|
||||||
try (POIFSFileSystem poifs = new POIFSFileSystem()) {
|
try (POIFSFileSystem poifs = new POIFSFileSystem()) {
|
||||||
|
|
|
@ -174,7 +174,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
||||||
protected static OPCPackage newPackage() {
|
protected static OPCPackage newPackage() {
|
||||||
OPCPackage pkg = null;
|
OPCPackage pkg = null;
|
||||||
try {
|
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
|
// Main part
|
||||||
PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
|
PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
|
||||||
// Create main part relationship
|
// Create main part relationship
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
package org.apache.poi.ooxml;
|
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.assertDoesNotThrow;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
@ -38,6 +37,7 @@ import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart;
|
import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart;
|
||||||
import org.apache.poi.ooxml.util.PackageHelper;
|
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
|
// Should not be able to write a document that has been closed
|
||||||
doc.close();
|
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.");
|
"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());
|
assertEquals("Cannot write data, document seems to have been closed already", e2.getMessage());
|
||||||
|
|
||||||
|
|
|
@ -218,7 +218,7 @@ public final class TestPackage {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void createPackageWithCoreDocument() throws IOException, InvalidFormatException, URISyntaxException, SAXException {
|
void createPackageWithCoreDocument() throws IOException, InvalidFormatException, URISyntaxException, SAXException {
|
||||||
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
try (OPCPackage pkg = OPCPackage.create(baos)) {
|
try (OPCPackage pkg = OPCPackage.create(baos)) {
|
||||||
|
|
||||||
// Add a core document
|
// Add a core document
|
||||||
|
@ -676,7 +676,7 @@ public final class TestPackage {
|
||||||
@Test
|
@Test
|
||||||
void zipBombCreateAndHandle()
|
void zipBombCreateAndHandle()
|
||||||
throws IOException, EncryptedDocumentException {
|
throws IOException, EncryptedDocumentException {
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(2500000);
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(2500000).get();
|
||||||
|
|
||||||
try (ZipFile zipFile = ZipHelper.openZipFile(getSampleFile("sample.xlsx"));
|
try (ZipFile zipFile = ZipHelper.openZipFile(getSampleFile("sample.xlsx"));
|
||||||
ZipArchiveOutputStream append = new ZipArchiveOutputStream(bos)) {
|
ZipArchiveOutputStream append = new ZipArchiveOutputStream(bos)) {
|
||||||
|
|
|
@ -216,7 +216,7 @@ public final class TestPackageCoreProperties {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testGetPropertiesLO() throws Exception {
|
void testGetPropertiesLO() throws Exception {
|
||||||
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
// Open the package
|
// Open the package
|
||||||
try (OPCPackage pkg1 = OPCPackage.open(openSampleStream("51444.xlsx"))) {
|
try (OPCPackage pkg1 = OPCPackage.open(openSampleStream("51444.xlsx"))) {
|
||||||
PackageProperties props1 = pkg1.getPackageProperties();
|
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);
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ROOT);
|
||||||
df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
|
df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
try (InputStream is = openSampleStream("OPCCompliance_CoreProperties_AlternateTimezones.docx");
|
try (InputStream is = openSampleStream("OPCCompliance_CoreProperties_AlternateTimezones.docx");
|
||||||
OPCPackage pkg1 = OPCPackage.open(is)) {
|
OPCPackage pkg1 = OPCPackage.open(is)) {
|
||||||
PackagePropertiesPart props1 = (PackagePropertiesPart) pkg1.getPackageProperties();
|
PackagePropertiesPart props1 = (PackagePropertiesPart) pkg1.getPackageProperties();
|
||||||
|
|
|
@ -198,7 +198,7 @@ class TestRelationships {
|
||||||
|
|
||||||
|
|
||||||
// Write out and re-load
|
// Write out and re-load
|
||||||
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
pkg.save(baos);
|
pkg.save(baos);
|
||||||
|
|
||||||
// use revert to not re-write the input file
|
// use revert to not re-write the input file
|
||||||
|
@ -226,7 +226,7 @@ class TestRelationships {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCreateRelationsFromScratch() throws Exception {
|
void testCreateRelationsFromScratch() throws Exception {
|
||||||
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
OPCPackage pkg = OPCPackage.create(baos);
|
OPCPackage pkg = OPCPackage.create(baos);
|
||||||
|
|
||||||
PackagePart partA =
|
PackagePart partA =
|
||||||
|
@ -298,7 +298,7 @@ class TestRelationships {
|
||||||
OPCPackage pkg = OPCPackage.open(filepath);
|
OPCPackage pkg = OPCPackage.open(filepath);
|
||||||
assert_50154(pkg);
|
assert_50154(pkg);
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
pkg.save(baos);
|
pkg.save(baos);
|
||||||
|
|
||||||
// use revert to not re-write the input file
|
// use revert to not re-write the input file
|
||||||
|
@ -353,7 +353,7 @@ class TestRelationships {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSelfRelations_bug51187() throws Exception {
|
void testSelfRelations_bug51187() throws Exception {
|
||||||
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
PackageRelationship rel1;
|
PackageRelationship rel1;
|
||||||
try (OPCPackage pkg = OPCPackage.create(baos)) {
|
try (OPCPackage pkg = OPCPackage.create(baos)) {
|
||||||
|
|
||||||
|
@ -399,7 +399,7 @@ class TestRelationships {
|
||||||
assertEquals("mailto:nobody@nowhere.uk%C2%A0", targetUri.toASCIIString());
|
assertEquals("mailto:nobody@nowhere.uk%C2%A0", targetUri.toASCIIString());
|
||||||
assertEquals("nobody@nowhere.uk\u00A0", targetUri.getSchemeSpecificPart());
|
assertEquals("nobody@nowhere.uk\u00A0", targetUri.getSchemeSpecificPart());
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
pkg1.save(out);
|
pkg1.save(out);
|
||||||
|
|
||||||
try (OPCPackage pkg2 = OPCPackage.open(out.toInputStream())) {
|
try (OPCPackage pkg2 = OPCPackage.open(out.toInputStream())) {
|
||||||
|
|
|
@ -106,7 +106,7 @@ public final class ZipFileAssert {
|
||||||
while ((entree = zis.getNextEntry()) != null) {
|
while ((entree = zis.getNextEntry()) != null) {
|
||||||
|
|
||||||
/* Create an array for the current entry */
|
/* Create an array for the current entry */
|
||||||
UnsynchronizedByteArrayOutputStream byteArray = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream byteArray = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
IOUtils.copy(zis, byteArray);
|
IOUtils.copy(zis, byteArray);
|
||||||
zipContent.put(entree.getName(), byteArray);
|
zipContent.put(entree.getName(), byteArray);
|
||||||
}
|
}
|
||||||
|
|
|
@ -216,7 +216,7 @@ public final class TestOPCComplianceCoreProperties {
|
||||||
@Test
|
@Test
|
||||||
void testNoCoreProperties_saveNew() throws Exception {
|
void testNoCoreProperties_saveNew() throws Exception {
|
||||||
String sampleFileName = "OPCCompliance_NoCoreProperties.xlsx";
|
String sampleFileName = "OPCCompliance_NoCoreProperties.xlsx";
|
||||||
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
|
|
||||||
try (OPCPackage pkg = OPCPackage.open(getSampleFile(sampleFileName).getPath())) {
|
try (OPCPackage pkg = OPCPackage.open(getSampleFile(sampleFileName).getPath())) {
|
||||||
// Verify it has empty properties
|
// Verify it has empty properties
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
package org.apache.poi.openxml4j.opc.internal.marshallers;
|
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.apache.poi.openxml4j.opc.PackagingURIHelper.PACKAGE_RELATIONSHIPS_ROOT_URI;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
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.ArchiveEntry;
|
||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
|
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.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||||
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePartName;
|
import org.apache.poi.openxml4j.opc.PackagePartName;
|
||||||
|
@ -39,7 +39,7 @@ class TestZipPackagePropertiesMarshaller {
|
||||||
private final PartMarshaller marshaller = new ZipPackagePropertiesMarshaller();
|
private final PartMarshaller marshaller = new ZipPackagePropertiesMarshaller();
|
||||||
|
|
||||||
private boolean marshall() throws OpenXML4JException {
|
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 {
|
private boolean marshall(OutputStream zos) throws OpenXML4JException {
|
||||||
|
@ -51,7 +51,7 @@ class TestZipPackagePropertiesMarshaller {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nonZipOutputStream() {
|
void nonZipOutputStream() {
|
||||||
assertThrows(IllegalArgumentException.class, () -> marshall(NULL_OUTPUT_STREAM));
|
assertThrows(IllegalArgumentException.class, () -> marshall(NullOutputStream.INSTANCE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -61,7 +61,7 @@ class TestZipPackagePropertiesMarshaller {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void ioException() {
|
void ioException() {
|
||||||
ZipArchiveOutputStream zos = new ZipArchiveOutputStream(new UnsynchronizedByteArrayOutputStream()) {
|
ZipArchiveOutputStream zos = new ZipArchiveOutputStream(UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
@Override
|
@Override
|
||||||
public void putArchiveEntry(final ArchiveEntry archiveEntry) throws IOException {
|
public void putArchiveEntry(final ArchiveEntry archiveEntry) throws IOException {
|
||||||
throw new IOException("TestException");
|
throw new IOException("TestException");
|
||||||
|
|
|
@ -152,7 +152,7 @@ public class DummyKeystore {
|
||||||
public DummyKeystore(String pfxInput, String storePass) throws GeneralSecurityException, IOException {
|
public DummyKeystore(String pfxInput, String storePass) throws GeneralSecurityException, IOException {
|
||||||
CryptoFunctions.registerBouncyCastle();
|
CryptoFunctions.registerBouncyCastle();
|
||||||
keystore = KeyStore.getInstance("PKCS12");
|
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());
|
keystore.load(fis, storePass.toCharArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -209,7 +209,7 @@ class TestSignatureInfo {
|
||||||
SignatureInfo si = new SignatureInfo();
|
SignatureInfo si = new SignatureInfo();
|
||||||
si.setSignatureConfig(signatureConfig);
|
si.setSignatureConfig(signatureConfig);
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(100000);
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(100000).get();
|
||||||
try (XSSFWorkbook wb1 = new XSSFWorkbook()) {
|
try (XSSFWorkbook wb1 = new XSSFWorkbook()) {
|
||||||
wb1.createSheet().createRow(1).createCell(1).setCellValue("Test");
|
wb1.createSheet().createRow(1).createCell(1).setCellValue("Test");
|
||||||
wb1.write(bos);
|
wb1.write(bos);
|
||||||
|
@ -426,7 +426,7 @@ class TestSignatureInfo {
|
||||||
void testSignEnvelopingDocument() throws Exception {
|
void testSignEnvelopingDocument() throws Exception {
|
||||||
String testFile = "hello-world-unsigned.xlsx";
|
String testFile = "hello-world-unsigned.xlsx";
|
||||||
File sigCopy = testdata.getFile(testFile);
|
File sigCopy = testdata.getFile(testFile);
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(50000);
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(50000).get();
|
||||||
|
|
||||||
final String execTimestr;
|
final String execTimestr;
|
||||||
|
|
||||||
|
@ -698,7 +698,7 @@ class TestSignatureInfo {
|
||||||
DummyKeystore ks = new DummyKeystore(STORE_PASS);
|
DummyKeystore ks = new DummyKeystore(STORE_PASS);
|
||||||
KeyCertPair certPair = ks.createDummyKey();
|
KeyCertPair certPair = ks.createDummyKey();
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
try (XWPFDocument doc = new XWPFDocument()) {
|
try (XWPFDocument doc = new XWPFDocument()) {
|
||||||
XWPFHyperlinkRun r = doc.createParagraph().createHyperlinkRun("http://poi.apache.org");
|
XWPFHyperlinkRun r = doc.createParagraph().createHyperlinkRun("http://poi.apache.org");
|
||||||
r.setText("Hyperlink");
|
r.setText("Hyperlink");
|
||||||
|
@ -743,7 +743,7 @@ class TestSignatureInfo {
|
||||||
try (SXSSFWorkbook wb1 = new SXSSFWorkbook((XSSFWorkbook)WorkbookFactory.create(tpl), 10)) {
|
try (SXSSFWorkbook wb1 = new SXSSFWorkbook((XSSFWorkbook)WorkbookFactory.create(tpl), 10)) {
|
||||||
wb1.setCompressTempFiles(true);
|
wb1.setCompressTempFiles(true);
|
||||||
wb1.removeSheetAt(0);
|
wb1.removeSheetAt(0);
|
||||||
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
wb1.write(os);
|
wb1.write(os);
|
||||||
|
|
||||||
try (OPCPackage pkg = OPCPackage.open(os.toInputStream())) {
|
try (OPCPackage pkg = OPCPackage.open(os.toInputStream())) {
|
||||||
|
@ -888,7 +888,7 @@ class TestSignatureInfo {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
try (XSSFWorkbook wb = new XSSFWorkbook()) {
|
try (XSSFWorkbook wb = new XSSFWorkbook()) {
|
||||||
wb.createSheet().createRow(0).createCell(0).setCellValue("Test");
|
wb.createSheet().createRow(0).createCell(0).setCellValue("Test");
|
||||||
wb.write(bos);
|
wb.write(bos);
|
||||||
|
@ -1075,7 +1075,7 @@ class TestSignatureInfo {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
try (XSSFWorkbook wb = new XSSFWorkbook()) {
|
try (XSSFWorkbook wb = new XSSFWorkbook()) {
|
||||||
wb.createSheet().createRow(0).createCell(0).setCellValue("test");
|
wb.createSheet().createRow(0).createCell(0).setCellValue("test");
|
||||||
wb.write(bos);
|
wb.write(bos);
|
||||||
|
|
|
@ -93,7 +93,7 @@ class TestAgileEncryptionParameters {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a small sample workbook for encrypting
|
// create a small sample workbook for encrypting
|
||||||
UnsynchronizedByteArrayOutputStream bosOrig = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bosOrig = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
try (XSSFWorkbook workbook = new XSSFWorkbook()) {
|
try (XSSFWorkbook workbook = new XSSFWorkbook()) {
|
||||||
XSSFSheet sheet = workbook.createSheet();
|
XSSFSheet sheet = workbook.createSheet();
|
||||||
XSSFRow row = sheet.createRow(0);
|
XSSFRow row = sheet.createRow(0);
|
||||||
|
@ -136,7 +136,7 @@ class TestAgileEncryptionParameters {
|
||||||
os.write(testData);
|
os.write(testData);
|
||||||
}
|
}
|
||||||
|
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
fsEnc.writeFilesystem(bos);
|
fsEnc.writeFilesystem(bos);
|
||||||
|
|
||||||
bos.close();
|
bos.close();
|
||||||
|
|
|
@ -142,7 +142,7 @@ class TestDecryptor {
|
||||||
Decryptor d = Decryptor.getInstance(info);
|
Decryptor d = Decryptor.getInstance(info);
|
||||||
d.verifyPassword("pwd123");
|
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))) {
|
try (final ZipArchiveInputStream zis = new ZipArchiveInputStream(d.getDataStream(fs))) {
|
||||||
int[] sizes = { 3711, 1155, 445, 9376, 450, 588, 1337, 2593, 304, 7910 };
|
int[] sizes = { 3711, 1155, 445, 9376, 450, 588, 1337, 2593, 304, 7910 };
|
||||||
for (int size : sizes) {
|
for (int size : sizes) {
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.poifs.crypt.tests;
|
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.apache.poi.poifs.crypt.CryptoFunctions.getMessageDigest;
|
||||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
@ -38,6 +37,7 @@ import java.util.Random;
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
|
|
||||||
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.openxml4j.opc.ContentTypes;
|
import org.apache.poi.openxml4j.opc.ContentTypes;
|
||||||
|
@ -76,7 +76,7 @@ class TestEncryptor {
|
||||||
payloadExpected = IOUtils.toByteArray(is);
|
payloadExpected = IOUtils.toByteArray(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
try (POIFSFileSystem fs = new POIFSFileSystem()) {
|
try (POIFSFileSystem fs = new POIFSFileSystem()) {
|
||||||
EncryptionInfo ei = new EncryptionInfo(EncryptionMode.binaryRC4);
|
EncryptionInfo ei = new EncryptionInfo(EncryptionMode.binaryRC4);
|
||||||
Encryptor enc = ei.getEncryptor();
|
Encryptor enc = ei.getEncryptor();
|
||||||
|
@ -113,7 +113,7 @@ class TestEncryptor {
|
||||||
payloadExpected = IOUtils.toByteArray(is);
|
payloadExpected = IOUtils.toByteArray(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
try (POIFSFileSystem fs = new TempFilePOIFSFileSystem()) {
|
try (POIFSFileSystem fs = new TempFilePOIFSFileSystem()) {
|
||||||
EncryptionInfo ei = new EncryptionInfo(EncryptionMode.agile);
|
EncryptionInfo ei = new EncryptionInfo(EncryptionMode.agile);
|
||||||
Encryptor enc = ei.getEncryptor();
|
Encryptor enc = ei.getEncryptor();
|
||||||
|
@ -200,7 +200,7 @@ class TestEncryptor {
|
||||||
Encryptor e = Encryptor.getInstance(infoActual);
|
Encryptor e = Encryptor.getInstance(infoActual);
|
||||||
e.confirmPassword(pass, keySpec, keySalt, verifierExpected, verifierSaltExpected, integritySalt);
|
e.confirmPassword(pass, keySpec, keySalt, verifierExpected, verifierSaltExpected, integritySalt);
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
try (POIFSFileSystem fs = new POIFSFileSystem()) {
|
try (POIFSFileSystem fs = new POIFSFileSystem()) {
|
||||||
try (OutputStream os = e.getDataStream(fs)) {
|
try (OutputStream os = e.getDataStream(fs)) {
|
||||||
os.write(payloadExpected);
|
os.write(payloadExpected);
|
||||||
|
@ -287,7 +287,7 @@ class TestEncryptor {
|
||||||
// now we use a newly generated salt/verifier and check
|
// now we use a newly generated salt/verifier and check
|
||||||
// if the file content is still the same
|
// 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()) {
|
try (POIFSFileSystem fs = new POIFSFileSystem()) {
|
||||||
|
|
||||||
final EncryptionInfo infoActual2 = new EncryptionInfo(
|
final EncryptionInfo infoActual2 = new EncryptionInfo(
|
||||||
|
@ -331,7 +331,7 @@ class TestEncryptor {
|
||||||
@Test
|
@Test
|
||||||
void encryptPackageWithoutCoreProperties() throws Exception {
|
void encryptPackageWithoutCoreProperties() throws Exception {
|
||||||
// Open our file without core properties
|
// Open our file without core properties
|
||||||
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
try (InputStream is = POIDataSamples.getOpenXML4JInstance().openResourceAsStream("OPCCompliance_NoCoreProperties.xlsx");
|
try (InputStream is = POIDataSamples.getOpenXML4JInstance().openResourceAsStream("OPCCompliance_NoCoreProperties.xlsx");
|
||||||
OPCPackage pkg = OPCPackage.open(is)) {
|
OPCPackage pkg = OPCPackage.open(is)) {
|
||||||
|
|
||||||
|
@ -530,7 +530,7 @@ class TestEncryptor {
|
||||||
os.write(zipInput);
|
os.write(zipInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
fsNew.writeFilesystem(bos);
|
fsNew.writeFilesystem(bos);
|
||||||
|
|
||||||
try (POIFSFileSystem fsReload = new POIFSFileSystem(bos.toInputStream())) {
|
try (POIFSFileSystem fsReload = new POIFSFileSystem(bos.toInputStream())) {
|
||||||
|
@ -624,7 +624,7 @@ class TestEncryptor {
|
||||||
|
|
||||||
try (InputStream is = dec.getDataStream(poifs);
|
try (InputStream is = dec.getDataStream(poifs);
|
||||||
DigestInputStream dis = new DigestInputStream(is, md)) {
|
DigestInputStream dis = new DigestInputStream(is, md)) {
|
||||||
IOUtils.copy(dis, NULL_OUTPUT_STREAM);
|
IOUtils.copy(dis, NullOutputStream.INSTANCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ class TestHxxFEncryption {
|
||||||
File f = sampleDir.getFile(file);
|
File f = sampleDir.getFile(file);
|
||||||
Biff8EncryptionKey.setCurrentUserPassword(password);
|
Biff8EncryptionKey.setCurrentUserPassword(password);
|
||||||
try (POITextExtractor te1 = ExtractorFactory.createExtractor(f);
|
try (POITextExtractor te1 = ExtractorFactory.createExtractor(f);
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
Biff8EncryptionKey.setCurrentUserPassword(newPass);
|
Biff8EncryptionKey.setCurrentUserPassword(newPass);
|
||||||
try (POIDocument doc = (POIDocument) te1.getDocument()) {
|
try (POIDocument doc = (POIDocument) te1.getDocument()) {
|
||||||
doc.write(bos);
|
doc.write(bos);
|
||||||
|
@ -126,7 +126,7 @@ class TestHxxFEncryption {
|
||||||
File f = sampleDir.getFile(file);
|
File f = sampleDir.getFile(file);
|
||||||
Biff8EncryptionKey.setCurrentUserPassword(password);
|
Biff8EncryptionKey.setCurrentUserPassword(password);
|
||||||
try (POITextExtractor te1 = ExtractorFactory.createExtractor(f);
|
try (POITextExtractor te1 = ExtractorFactory.createExtractor(f);
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
// first remove encryption
|
// first remove encryption
|
||||||
Biff8EncryptionKey.setCurrentUserPassword(null);
|
Biff8EncryptionKey.setCurrentUserPassword(null);
|
||||||
try (POIDocument doc = (POIDocument) te1.getDocument()) {
|
try (POIDocument doc = (POIDocument) te1.getDocument()) {
|
||||||
|
@ -174,7 +174,7 @@ class TestHxxFEncryption {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void changeEncryptionMode() throws IOException {
|
public void changeEncryptionMode() throws IOException {
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(10_000);
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(10_000).get();
|
||||||
|
|
||||||
try (HSSFWorkbook wb = new HSSFWorkbook()) {
|
try (HSSFWorkbook wb = new HSSFWorkbook()) {
|
||||||
wb.createSheet().createRow(1).createCell(1).setCellValue("Test");
|
wb.createSheet().createRow(1).createCell(1).setCellValue("Test");
|
||||||
|
|
|
@ -113,7 +113,7 @@ class TestOleShape {
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("data")
|
@MethodSource("data")
|
||||||
void embedData(Api api, ObjectMetaData.Application app) throws IOException, ReflectiveOperationException {
|
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)) {
|
try (SlideShow<?,?> ppt = createSlideShow(api)) {
|
||||||
final PictureData picData = ppt.addPicture(pictureFile, PictureType.EMF);
|
final PictureData picData = ppt.addPicture(pictureFile, PictureType.EMF);
|
||||||
final Slide<?,?> slide = ppt.createSlide();
|
final Slide<?,?> slide = ppt.createSlide();
|
||||||
|
|
|
@ -55,7 +55,7 @@ class TestSlide {
|
||||||
ppt1.createSlide().setHidden(true);
|
ppt1.createSlide().setHidden(true);
|
||||||
ppt1.createSlide();
|
ppt1.createSlide();
|
||||||
|
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
ppt1.write(bos);
|
ppt1.write(bos);
|
||||||
|
|
||||||
try (InputStream is = bos.toInputStream();
|
try (InputStream is = bos.toInputStream();
|
||||||
|
|
|
@ -125,7 +125,7 @@ class TestTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
ppt1.write(bos);
|
ppt1.write(bos);
|
||||||
|
|
||||||
try (SlideShow<?,?> ppt2 = SlideShowFactory.create(bos.toInputStream())) {
|
try (SlideShow<?,?> ppt2 = SlideShowFactory.create(bos.toInputStream())) {
|
||||||
|
|
|
@ -123,7 +123,7 @@ class TestEmbedOLEPackage {
|
||||||
|
|
||||||
try (POIFSFileSystem scratchFS = new POIFSFileSystem();
|
try (POIFSFileSystem scratchFS = new POIFSFileSystem();
|
||||||
POIFSFileSystem ole1FS = new POIFSFileSystem(new ByteArrayInputStream(oleShapes.get(0).getObjectData()))) {
|
POIFSFileSystem ole1FS = new POIFSFileSystem(new ByteArrayInputStream(oleShapes.get(0).getObjectData()))) {
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
scratch.writeOut(bos);
|
scratch.writeOut(bos);
|
||||||
scratchFS.createDocument(bos.toInputStream(), Ole10Native.OLE10_NATIVE);
|
scratchFS.createDocument(bos.toInputStream(), Ole10Native.OLE10_NATIVE);
|
||||||
scratchFS.getRoot().setStorageClsid(ClassIDPredefined.OLE_V1_PACKAGE.getClassID());
|
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.setAnchor(new java.awt.Rectangle(50, 50, 100, 200));
|
||||||
sh1.setFillColor(java.awt.Color.red);
|
sh1.setFillColor(java.awt.Color.red);
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
ppt.write(bos);
|
ppt.write(bos);
|
||||||
ppt.close();
|
ppt.close();
|
||||||
|
|
||||||
|
|
|
@ -964,7 +964,7 @@ class TestXSLFBugs {
|
||||||
|
|
||||||
final List<Object> strings = new ArrayList<>();
|
final List<Object> strings = new ArrayList<>();
|
||||||
|
|
||||||
DummyGraphics2d dgfx = new DummyGraphics2d(new NullPrintStream()) {
|
DummyGraphics2d dgfx = new DummyGraphics2d(NullPrintStream.INSTANCE) {
|
||||||
@Override
|
@Override
|
||||||
public void drawString(AttributedCharacterIterator iterator, float x, float y) {
|
public void drawString(AttributedCharacterIterator iterator, float x, float y) {
|
||||||
// For the test file, common sl draws textruns one by one and not mixed
|
// 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 },
|
{ 79.58198774450841, 53.20887318960063, 109.13118501448272, 9.40935058567127 },
|
||||||
};
|
};
|
||||||
|
|
||||||
DummyGraphics2d dgfx = new DummyGraphics2d(new NullPrintStream()) {
|
DummyGraphics2d dgfx = new DummyGraphics2d(NullPrintStream.INSTANCE) {
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
@Override
|
@Override
|
||||||
public void clip(java.awt.Shape s) {
|
public void clip(java.awt.Shape s) {
|
||||||
|
@ -1065,7 +1065,7 @@ class TestXSLFBugs {
|
||||||
assertNotNull(targetSlide);
|
assertNotNull(targetSlide);
|
||||||
assertEquals(2, targetPresentation.getPictureData().size());
|
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<LinearGradientPaint> linearGradients = new ArrayList<>();
|
||||||
final ArrayList<RadialGradientPaint> radialGradients = 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) {
|
public void setPaint(final Paint paint) {
|
||||||
if (paint instanceof LinearGradientPaint) {
|
if (paint instanceof LinearGradientPaint) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ class TestXSLFSlideCopy {
|
||||||
try (
|
try (
|
||||||
InputStream stream = slTests.openResourceAsStream("copy-slide-demo.pptx");
|
InputStream stream = slTests.openResourceAsStream("copy-slide-demo.pptx");
|
||||||
XMLSlideShow slideShow = new XMLSlideShow(stream);
|
XMLSlideShow slideShow = new XMLSlideShow(stream);
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
XSLFSlide defaultSlide = getSlideByShapeName(slideShow, shapeName);
|
XSLFSlide defaultSlide = getSlideByShapeName(slideShow, shapeName);
|
||||||
int slideIndex = defaultSlide.getSlideNumber() - 1;
|
int slideIndex = defaultSlide.getSlideNumber() - 1;
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class XSLFTestDataSamples {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static XMLSlideShow writeOutAndReadBack(XMLSlideShow doc) throws IOException {
|
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);
|
doc.write(baos);
|
||||||
try (InputStream bais = baos.toInputStream()) {
|
try (InputStream bais = baos.toInputStream()) {
|
||||||
return new XMLSlideShow(bais);
|
return new XMLSlideShow(bais);
|
||||||
|
|
|
@ -90,7 +90,7 @@ class TestXSLFShape {
|
||||||
void testReplaceTextInShapes() throws IOException {
|
void testReplaceTextInShapes() throws IOException {
|
||||||
try (
|
try (
|
||||||
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
assertEquals(6, ppt.getSlides().size());
|
assertEquals(6, ppt.getSlides().size());
|
||||||
XSLFSlide slide0 = ppt.getSlides().get(0);
|
XSLFSlide slide0 = ppt.getSlides().get(0);
|
||||||
|
@ -135,7 +135,7 @@ class TestXSLFShape {
|
||||||
void testReplaceTextInShapesXDDF() throws IOException {
|
void testReplaceTextInShapesXDDF() throws IOException {
|
||||||
try (
|
try (
|
||||||
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
assertEquals(6, ppt.getSlides().size());
|
assertEquals(6, ppt.getSlides().size());
|
||||||
XSLFSlide slide0 = ppt.getSlides().get(0);
|
XSLFSlide slide0 = ppt.getSlides().get(0);
|
||||||
|
@ -180,7 +180,7 @@ class TestXSLFShape {
|
||||||
void testCloneSlideAndReplaceText() throws IOException {
|
void testCloneSlideAndReplaceText() throws IOException {
|
||||||
try (
|
try (
|
||||||
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
assertEquals(6, ppt.getSlides().size());
|
assertEquals(6, ppt.getSlides().size());
|
||||||
XSLFSlide slide0 = ppt.getSlides().get(0);
|
XSLFSlide slide0 = ppt.getSlides().get(0);
|
||||||
|
@ -245,7 +245,7 @@ class TestXSLFShape {
|
||||||
void testCloneSlideAndReplaceTextXDDF() throws IOException {
|
void testCloneSlideAndReplaceTextXDDF() throws IOException {
|
||||||
try (
|
try (
|
||||||
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
assertEquals(6, ppt.getSlides().size());
|
assertEquals(6, ppt.getSlides().size());
|
||||||
XSLFSlide slide0 = ppt.getSlides().get(0);
|
XSLFSlide slide0 = ppt.getSlides().get(0);
|
||||||
|
|
|
@ -452,7 +452,7 @@ class TestXSLFTextParagraph {
|
||||||
|
|
||||||
assertEquals("This is a highlight test", sh.getText());
|
assertEquals("This is a highlight test", sh.getText());
|
||||||
|
|
||||||
DummyGraphics2d dgfx = new DummyGraphics2d(new NullPrintStream()) {
|
DummyGraphics2d dgfx = new DummyGraphics2d(NullPrintStream.INSTANCE) {
|
||||||
@Override
|
@Override
|
||||||
public void drawString(AttributedCharacterIterator iterator, float x, float y) {
|
public void drawString(AttributedCharacterIterator iterator, float x, float y) {
|
||||||
// For the test file, common sl draws textruns one by one and not mixed
|
// For the test file, common sl draws textruns one by one and not mixed
|
||||||
|
|
|
@ -68,7 +68,7 @@ public final class DeferredSXSSFITestDataProvider implements ITestDataProvider {
|
||||||
throw new IllegalArgumentException("Expected an instance of XSSFWorkbook");
|
throw new IllegalArgumentException("Expected an instance of XSSFWorkbook");
|
||||||
}
|
}
|
||||||
|
|
||||||
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
wb.write(baos);
|
wb.write(baos);
|
||||||
try (InputStream is = baos.toInputStream()) {
|
try (InputStream is = baos.toInputStream()) {
|
||||||
return new XSSFWorkbook(is);
|
return new XSSFWorkbook(is);
|
||||||
|
@ -82,7 +82,7 @@ public final class DeferredSXSSFITestDataProvider implements ITestDataProvider {
|
||||||
* Returns an XSSFWorkbook since SXSSFWorkbook is write-only
|
* Returns an XSSFWorkbook since SXSSFWorkbook is write-only
|
||||||
*/
|
*/
|
||||||
public XSSFWorkbook inMemoryWriteOutAndReadBack(SXSSFWorkbook wb) {
|
public XSSFWorkbook inMemoryWriteOutAndReadBack(SXSSFWorkbook wb) {
|
||||||
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
wb.writeAvoidingTempFiles(baos);
|
wb.writeAvoidingTempFiles(baos);
|
||||||
try (InputStream is = baos.toInputStream()) {
|
try (InputStream is = baos.toInputStream()) {
|
||||||
return new XSSFWorkbook(is);
|
return new XSSFWorkbook(is);
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class SXSSFITestDataProvider implements ITestDataProvider {
|
||||||
throw new IllegalArgumentException("Expected an instance of SXSSFWorkbook");
|
throw new IllegalArgumentException("Expected an instance of SXSSFWorkbook");
|
||||||
}
|
}
|
||||||
|
|
||||||
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
wb.write(baos);
|
wb.write(baos);
|
||||||
try (InputStream is = baos.toInputStream()) {
|
try (InputStream is = baos.toInputStream()) {
|
||||||
return new XSSFWorkbook(is);
|
return new XSSFWorkbook(is);
|
||||||
|
|
|
@ -35,7 +35,7 @@ class TestSSUtilVsXSSFColor {
|
||||||
|
|
||||||
try (
|
try (
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
XSSFCellStyle cellStyle = workbook.createCellStyle();
|
XSSFCellStyle cellStyle = workbook.createCellStyle();
|
||||||
final String rgbS = "ffff00";
|
final String rgbS = "ffff00";
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class TestXSSFMemoryLeak {
|
||||||
// not freed until we free up the Cell itself
|
// not freed until we free up the Cell itself
|
||||||
//verifier.addObject(ctCell);
|
//verifier.addObject(ctCell);
|
||||||
|
|
||||||
try (OutputStream out = new UnsynchronizedByteArrayOutputStream(8192)) {
|
try (OutputStream out = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(8192).get()) {
|
||||||
wb.write(out);
|
wb.write(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ public class XSSFTestDataSamples {
|
||||||
* @throws IOException If writing the file fails
|
* @throws IOException If writing the file fails
|
||||||
*/
|
*/
|
||||||
public static <R extends Workbook> UnsynchronizedByteArrayOutputStream writeOut(R wb) throws IOException {
|
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);
|
wb.write(out);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -376,7 +376,7 @@ public final class TestXSSFReader {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBug65676() throws Exception {
|
void testBug65676() throws Exception {
|
||||||
try (UnsynchronizedByteArrayOutputStream output = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream output = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
try(Workbook wb = new SXSSFWorkbook()) {
|
try(Workbook wb = new SXSSFWorkbook()) {
|
||||||
Row r = wb.createSheet("Sheet").createRow(0);
|
Row r = wb.createSheet("Sheet").createRow(0);
|
||||||
r.createCell(0).setCellValue(1.2); /* A1: Number 1.2 */
|
r.createCell(0).setCellValue(1.2); /* A1: Number 1.2 */
|
||||||
|
|
|
@ -72,7 +72,7 @@ public final class TestXSSFExportToXML {
|
||||||
|
|
||||||
XSSFMap map = mapInfo.getXSSFMapById(1);
|
XSSFMap map = mapInfo.getXSSFMapById(1);
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
exporter.exportToXML(os, true);
|
exporter.exportToXML(os, true);
|
||||||
String xml = os.toString(StandardCharsets.UTF_8);
|
String xml = os.toString(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ public final class TestXSSFExportToXML {
|
||||||
|
|
||||||
XSSFMap map = mapInfo.getXSSFMapById(1);
|
XSSFMap map = mapInfo.getXSSFMapById(1);
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
exporter.exportToXML(os, true);
|
exporter.exportToXML(os, true);
|
||||||
String xml = os.toString(StandardCharsets.UTF_8);
|
String xml = os.toString(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ public final class TestXSSFExportToXML {
|
||||||
|
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
String xml;
|
String xml;
|
||||||
try (UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
exporter.exportToXML(os, true);
|
exporter.exportToXML(os, true);
|
||||||
xml = os.toString(StandardCharsets.UTF_8);
|
xml = os.toString(StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,7 @@ public final class TestXSSFExportToXML {
|
||||||
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXMLMapping-singleattributenamespace.xlsx")) {
|
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXMLMapping-singleattributenamespace.xlsx")) {
|
||||||
for (XSSFMap map : wb.getCustomXMLMappings()) {
|
for (XSSFMap map : wb.getCustomXMLMappings()) {
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
SAXParseException ex = assertThrows(SAXParseException.class, () -> exporter.exportToXML(os, true));
|
SAXParseException ex = assertThrows(SAXParseException.class, () -> exporter.exportToXML(os, true));
|
||||||
assertTrue(p.matcher(ex.getMessage()).find(),
|
assertTrue(p.matcher(ex.getMessage()).find(),
|
||||||
"Did not find pattern " + p + " in " + ex.getMessage());
|
"Did not find pattern " + p + " in " + ex.getMessage());
|
||||||
|
@ -256,7 +256,7 @@ public final class TestXSSFExportToXML {
|
||||||
assertNotNull(map, "XSSFMap is null");
|
assertNotNull(map, "XSSFMap is null");
|
||||||
|
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
exporter.exportToXML(os, true);
|
exporter.exportToXML(os, true);
|
||||||
String xmlData = os.toString(StandardCharsets.UTF_8);
|
String xmlData = os.toString(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
@ -300,7 +300,7 @@ public final class TestXSSFExportToXML {
|
||||||
assertNotNull(map, "XSSFMap is null");
|
assertNotNull(map, "XSSFMap is null");
|
||||||
|
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
exporter.exportToXML(os, true);
|
exporter.exportToXML(os, true);
|
||||||
String xmlData = os.toString(StandardCharsets.UTF_8);
|
String xmlData = os.toString(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
@ -335,7 +335,7 @@ public final class TestXSSFExportToXML {
|
||||||
assertNotNull(map, "XSSFMap is null");
|
assertNotNull(map, "XSSFMap is null");
|
||||||
|
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
exporter.exportToXML(os, true);
|
exporter.exportToXML(os, true);
|
||||||
String xmlData = os.toString(StandardCharsets.UTF_8);
|
String xmlData = os.toString(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
@ -374,7 +374,7 @@ public final class TestXSSFExportToXML {
|
||||||
assertNotNull(map, "XSSFMap is null");
|
assertNotNull(map, "XSSFMap is null");
|
||||||
|
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
exporter.exportToXML(os, true);
|
exporter.exportToXML(os, true);
|
||||||
String xmlData = os.toString(StandardCharsets.UTF_8);
|
String xmlData = os.toString(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
@ -400,7 +400,7 @@ public final class TestXSSFExportToXML {
|
||||||
for (XSSFMap map : wb.getCustomXMLMappings()) {
|
for (XSSFMap map : wb.getCustomXMLMappings()) {
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
exporter.exportToXML(os, true);
|
exporter.exportToXML(os, true);
|
||||||
String xmlData = os.toString(StandardCharsets.UTF_8);
|
String xmlData = os.toString(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
@ -478,7 +478,7 @@ public final class TestXSSFExportToXML {
|
||||||
assertNotNull(map, "XSSFMap is null");
|
assertNotNull(map, "XSSFMap is null");
|
||||||
|
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
exporter.exportToXML(os, true);
|
exporter.exportToXML(os, true);
|
||||||
String xmlData = os.toString(StandardCharsets.UTF_8);
|
String xmlData = os.toString(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
@ -556,7 +556,7 @@ public final class TestXSSFExportToXML {
|
||||||
assertNotNull(map, "XSSFMap is null");
|
assertNotNull(map, "XSSFMap is null");
|
||||||
|
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
exporter.exportToXML(os, true);
|
exporter.exportToXML(os, true);
|
||||||
String xmlData = os.toString(StandardCharsets.UTF_8);
|
String xmlData = os.toString(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
@ -587,7 +587,7 @@ public final class TestXSSFExportToXML {
|
||||||
assertNotNull(map, "XSSFMap is null");
|
assertNotNull(map, "XSSFMap is null");
|
||||||
|
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
exporter.exportToXML(os, false);
|
exporter.exportToXML(os, false);
|
||||||
String xmlData = os.toString(StandardCharsets.UTF_8);
|
String xmlData = os.toString(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
@ -619,7 +619,7 @@ public final class TestXSSFExportToXML {
|
||||||
assertNotNull(map, "XSSFMap is null");
|
assertNotNull(map, "XSSFMap is null");
|
||||||
|
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
exporter.exportToXML(os, true);
|
exporter.exportToXML(os, true);
|
||||||
String xmlData = os.toString(StandardCharsets.UTF_8);
|
String xmlData = os.toString(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
@ -645,7 +645,7 @@ public final class TestXSSFExportToXML {
|
||||||
for (XSSFMap map : mappings) {
|
for (XSSFMap map : mappings) {
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
exporter.exportToXML(os, false);
|
exporter.exportToXML(os, false);
|
||||||
assertNotNull(os.toString(StandardCharsets.UTF_8));
|
assertNotNull(os.toString(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
@ -657,7 +657,7 @@ public final class TestXSSFExportToXML {
|
||||||
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("61281.xlsx")) {
|
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("61281.xlsx")) {
|
||||||
for (XSSFMap map : wb.getCustomXMLMappings()) {
|
for (XSSFMap map : wb.getCustomXMLMappings()) {
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
exporter.exportToXML(bos, true);
|
exporter.exportToXML(bos, true);
|
||||||
assertNotNull(DocumentHelper.readDocument(bos.toInputStream()));
|
assertNotNull(DocumentHelper.readDocument(bos.toInputStream()));
|
||||||
String exportedXml = bos.toString(StandardCharsets.UTF_8);
|
String exportedXml = bos.toString(StandardCharsets.UTF_8);
|
||||||
|
@ -671,7 +671,7 @@ public final class TestXSSFExportToXML {
|
||||||
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("xxe_in_schema.xlsx")) {
|
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("xxe_in_schema.xlsx")) {
|
||||||
for (XSSFMap map : wb.getCustomXMLMappings()) {
|
for (XSSFMap map : wb.getCustomXMLMappings()) {
|
||||||
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
assertThrows(SAXParseException.class, () -> exporter.exportToXML(bos, true));
|
assertThrows(SAXParseException.class, () -> exporter.exportToXML(bos, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,8 @@ class OpcZipTest {
|
||||||
void compareOutput() throws Exception {
|
void compareOutput() throws Exception {
|
||||||
Map<String, String> contents = createContents();
|
Map<String, String> contents = createContents();
|
||||||
try (
|
try (
|
||||||
UnsynchronizedByteArrayOutputStream bos1 = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos1 = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
UnsynchronizedByteArrayOutputStream bos2 = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos2 = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
try (OpcOutputStream zip = new OpcOutputStream(bos1)) {
|
try (OpcOutputStream zip = new OpcOutputStream(bos1)) {
|
||||||
for (Map.Entry<String, String> entry : contents.entrySet()) {
|
for (Map.Entry<String, String> entry : contents.entrySet()) {
|
||||||
|
|
|
@ -119,7 +119,7 @@ public final class TestSXSSFSheet extends BaseTestXSheet {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void flushBufferedDaat() throws IOException {
|
void flushBufferedDaat() throws IOException {
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
try (SXSSFWorkbook wb = new SXSSFWorkbook(1)) {
|
try (SXSSFWorkbook wb = new SXSSFWorkbook(1)) {
|
||||||
SXSSFSheet sheet = wb.createSheet("my-sheet");
|
SXSSFSheet sheet = wb.createSheet("my-sheet");
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ public final class TestSXSSFSheet extends BaseTestXSheet {
|
||||||
//one level
|
//one level
|
||||||
sheet.groupRow(9, 10);
|
sheet.groupRow(9, 10);
|
||||||
|
|
||||||
try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
workbook.write(bos);
|
workbook.write(bos);
|
||||||
try(XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) {
|
try(XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) {
|
||||||
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
|
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
|
||||||
|
@ -223,7 +223,7 @@ public final class TestSXSSFSheet extends BaseTestXSheet {
|
||||||
//two level
|
//two level
|
||||||
sheet.groupRow(10, 13);
|
sheet.groupRow(10, 13);
|
||||||
|
|
||||||
try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
workbook.write(bos);
|
workbook.write(bos);
|
||||||
try(XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) {
|
try(XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) {
|
||||||
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
|
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
package org.apache.poi.xssf.streaming;
|
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.assertEndsWith;
|
||||||
import static org.apache.poi.POITestCase.assertStartsWith;
|
import static org.apache.poi.POITestCase.assertStartsWith;
|
||||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
@ -37,6 +36,7 @@ import java.io.IOException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||||
|
@ -358,12 +358,12 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
|
||||||
void bug53515() throws Exception {
|
void bug53515() throws Exception {
|
||||||
try (Workbook wb1 = new SXSSFWorkbook(10)) {
|
try (Workbook wb1 = new SXSSFWorkbook(10)) {
|
||||||
populateWorkbook(wb1);
|
populateWorkbook(wb1);
|
||||||
assertDoesNotThrow(() -> wb1.write(NULL_OUTPUT_STREAM));
|
assertDoesNotThrow(() -> wb1.write(NullOutputStream.INSTANCE));
|
||||||
assertDoesNotThrow(() -> wb1.write(NULL_OUTPUT_STREAM));
|
assertDoesNotThrow(() -> wb1.write(NullOutputStream.INSTANCE));
|
||||||
try (Workbook wb2 = new XSSFWorkbook()) {
|
try (Workbook wb2 = new XSSFWorkbook()) {
|
||||||
populateWorkbook(wb2);
|
populateWorkbook(wb2);
|
||||||
assertDoesNotThrow(() -> wb2.write(NULL_OUTPUT_STREAM));
|
assertDoesNotThrow(() -> wb2.write(NullOutputStream.INSTANCE));
|
||||||
assertDoesNotThrow(() -> wb2.write(NULL_OUTPUT_STREAM));
|
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();
|
swb.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -499,7 +499,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
|
||||||
File input = XSSFTestDataSamples.getSampleFile("sample.xlsx");
|
File input = XSSFTestDataSamples.getSampleFile("sample.xlsx");
|
||||||
|
|
||||||
try (OPCPackage pkg = OPCPackage.open(input, PackageAccess.READ)) {
|
try (OPCPackage pkg = OPCPackage.open(input, PackageAccess.READ)) {
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
try (XSSFWorkbook xssf = new XSSFWorkbook(pkg)) {
|
try (XSSFWorkbook xssf = new XSSFWorkbook(pkg)) {
|
||||||
try (SXSSFWorkbook wb = new SXSSFWorkbook(xssf, 2)) {
|
try (SXSSFWorkbook wb = new SXSSFWorkbook(xssf, 2)) {
|
||||||
Sheet s = wb.createSheet(sheetName);
|
Sheet s = wb.createSheet(sheetName);
|
||||||
|
@ -542,7 +542,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
|
||||||
void addHyperlink() throws Exception {
|
void addHyperlink() throws Exception {
|
||||||
try (
|
try (
|
||||||
SXSSFWorkbook wb = new SXSSFWorkbook();
|
SXSSFWorkbook wb = new SXSSFWorkbook();
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
SXSSFSheet sheet = wb.createSheet("s1");
|
SXSSFSheet sheet = wb.createSheet("s1");
|
||||||
SXSSFRow row = sheet.createRow(0);
|
SXSSFRow row = sheet.createRow(0);
|
||||||
|
@ -568,7 +568,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
|
||||||
void addDimension() throws IOException {
|
void addDimension() throws IOException {
|
||||||
try (
|
try (
|
||||||
SXSSFWorkbook wb = new SXSSFWorkbook();
|
SXSSFWorkbook wb = new SXSSFWorkbook();
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
SXSSFSheet sheet = wb.createSheet();
|
SXSSFSheet sheet = wb.createSheet();
|
||||||
sheet.createRow(2).createCell(3).setCellValue("top left");
|
sheet.createRow(2).createCell(3).setCellValue("top left");
|
||||||
|
@ -587,7 +587,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
|
||||||
void addDimension1() throws IOException {
|
void addDimension1() throws IOException {
|
||||||
try (
|
try (
|
||||||
SXSSFWorkbook wb = new SXSSFWorkbook(1);
|
SXSSFWorkbook wb = new SXSSFWorkbook(1);
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
SXSSFSheet sheet = wb.createSheet();
|
SXSSFSheet sheet = wb.createSheet();
|
||||||
sheet.createRow(2).createCell(3).setCellValue("top left");
|
sheet.createRow(2).createCell(3).setCellValue("top left");
|
||||||
|
@ -612,7 +612,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
|
||||||
assertEquals(6, sheet.getLastRowNum());
|
assertEquals(6, sheet.getLastRowNum());
|
||||||
try (
|
try (
|
||||||
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(wb);
|
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(wb);
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
sxssfWorkbook.write(bos);
|
sxssfWorkbook.write(bos);
|
||||||
try (XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) {
|
try (XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) {
|
||||||
|
@ -627,7 +627,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
|
||||||
void addDimensionDisabled() throws IOException {
|
void addDimensionDisabled() throws IOException {
|
||||||
try (
|
try (
|
||||||
SXSSFWorkbook wb = new SXSSFWorkbook();
|
SXSSFWorkbook wb = new SXSSFWorkbook();
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
wb.setShouldCalculateSheetDimensions(false);
|
wb.setShouldCalculateSheetDimensions(false);
|
||||||
SXSSFSheet sheet = wb.createSheet();
|
SXSSFSheet sheet = wb.createSheet();
|
||||||
|
@ -655,7 +655,7 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
|
||||||
void dateStyle() throws IOException {
|
void dateStyle() throws IOException {
|
||||||
try (
|
try (
|
||||||
SXSSFWorkbook workbook = new SXSSFWorkbook();
|
SXSSFWorkbook workbook = new SXSSFWorkbook();
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
SXSSFSheet sheet = workbook.createSheet();
|
SXSSFSheet sheet = workbook.createSheet();
|
||||||
SXSSFRow row = sheet.createRow(0);
|
SXSSFRow row = sheet.createRow(0);
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
package org.apache.poi.xssf.streaming;
|
package org.apache.poi.xssf.streaming;
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
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.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
@ -32,6 +31,7 @@ import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
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
|
// write an unencrypted workbook to disk, but any temporary files are encrypted
|
||||||
@Test
|
@Test
|
||||||
void customZipEntrySource() throws IOException {
|
void customZipEntrySource() throws IOException {
|
||||||
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(8192);
|
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(8192).get();
|
||||||
try (SXSSFWorkbookWithCustomZipEntrySource workbook = new SXSSFWorkbookWithCustomZipEntrySource()) {
|
try (SXSSFWorkbookWithCustomZipEntrySource workbook = new SXSSFWorkbookWithCustomZipEntrySource()) {
|
||||||
SXSSFSheet sheet1 = workbook.createSheet(sheetName);
|
SXSSFSheet sheet1 = workbook.createSheet(sheetName);
|
||||||
SXSSFRow row1 = sheet1.createRow(1);
|
SXSSFRow row1 = sheet1.createRow(1);
|
||||||
|
@ -113,7 +113,7 @@ public final class TestSXSSFWorkbookWithCustomZipEntrySource {
|
||||||
SXSSFRow row1 = sheet1.createRow(1);
|
SXSSFRow row1 = sheet1.createRow(1);
|
||||||
SXSSFCell cell1 = row1.createCell(1);
|
SXSSFCell cell1 = row1.createCell(1);
|
||||||
cell1.setCellValue(cellValue);
|
cell1.setCellValue(cellValue);
|
||||||
workbook.write(NULL_OUTPUT_STREAM);
|
workbook.write(NullOutputStream.INSTANCE);
|
||||||
workbook.close();
|
workbook.close();
|
||||||
List<File> tempFiles = workbook.getTempFiles();
|
List<File> tempFiles = workbook.getTempFiles();
|
||||||
assertEquals(1, tempFiles.size());
|
assertEquals(1, tempFiles.size());
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.apache.poi.xssf.streaming;
|
package org.apache.poi.xssf.streaming;
|
||||||
|
|
||||||
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||||
|
@ -44,7 +45,6 @@ import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
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.assertEndsWith;
|
||||||
import static org.apache.poi.POITestCase.assertStartsWith;
|
import static org.apache.poi.POITestCase.assertStartsWith;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
@ -337,12 +337,12 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook {
|
||||||
void bug53515() throws Exception {
|
void bug53515() throws Exception {
|
||||||
try (Workbook wb1 = new SXSSFWorkbook(10)) {
|
try (Workbook wb1 = new SXSSFWorkbook(10)) {
|
||||||
populateWorkbook(wb1);
|
populateWorkbook(wb1);
|
||||||
assertDoesNotThrow(() -> wb1.write(NULL_OUTPUT_STREAM));
|
assertDoesNotThrow(() -> wb1.write(NullOutputStream.INSTANCE));
|
||||||
assertDoesNotThrow(() -> wb1.write(NULL_OUTPUT_STREAM));
|
assertDoesNotThrow(() -> wb1.write(NullOutputStream.INSTANCE));
|
||||||
try (Workbook wb2 = new XSSFWorkbook()) {
|
try (Workbook wb2 = new XSSFWorkbook()) {
|
||||||
populateWorkbook(wb2);
|
populateWorkbook(wb2);
|
||||||
assertDoesNotThrow(() -> wb2.write(NULL_OUTPUT_STREAM));
|
assertDoesNotThrow(() -> wb2.write(NullOutputStream.INSTANCE));
|
||||||
assertDoesNotThrow(() -> wb2.write(NULL_OUTPUT_STREAM));
|
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();
|
swb.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -478,7 +478,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook {
|
||||||
File input = XSSFTestDataSamples.getSampleFile("sample.xlsx");
|
File input = XSSFTestDataSamples.getSampleFile("sample.xlsx");
|
||||||
|
|
||||||
try (OPCPackage pkg = OPCPackage.open(input, PackageAccess.READ)) {
|
try (OPCPackage pkg = OPCPackage.open(input, PackageAccess.READ)) {
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
try (XSSFWorkbook xssf = new XSSFWorkbook(pkg)) {
|
try (XSSFWorkbook xssf = new XSSFWorkbook(pkg)) {
|
||||||
try (SXSSFWorkbook wb = new SXSSFWorkbook(xssf, 2)) {
|
try (SXSSFWorkbook wb = new SXSSFWorkbook(xssf, 2)) {
|
||||||
Sheet s = wb.createSheet(sheetName);
|
Sheet s = wb.createSheet(sheetName);
|
||||||
|
@ -521,7 +521,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook {
|
||||||
void addHyperlink() throws Exception {
|
void addHyperlink() throws Exception {
|
||||||
try (
|
try (
|
||||||
SXSSFWorkbook wb = new SXSSFWorkbook();
|
SXSSFWorkbook wb = new SXSSFWorkbook();
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
SXSSFSheet sheet = wb.createSheet("s1");
|
SXSSFSheet sheet = wb.createSheet("s1");
|
||||||
SXSSFRow row = sheet.createRow(0);
|
SXSSFRow row = sheet.createRow(0);
|
||||||
|
@ -547,7 +547,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook {
|
||||||
void addDimension() throws IOException {
|
void addDimension() throws IOException {
|
||||||
try (
|
try (
|
||||||
SXSSFWorkbook wb = new SXSSFWorkbook();
|
SXSSFWorkbook wb = new SXSSFWorkbook();
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
SXSSFSheet sheet = wb.createSheet();
|
SXSSFSheet sheet = wb.createSheet();
|
||||||
sheet.createRow(2).createCell(3).setCellValue("top left");
|
sheet.createRow(2).createCell(3).setCellValue("top left");
|
||||||
|
@ -566,7 +566,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook {
|
||||||
void addDimension1() throws IOException {
|
void addDimension1() throws IOException {
|
||||||
try (
|
try (
|
||||||
SXSSFWorkbook wb = new SXSSFWorkbook(1);
|
SXSSFWorkbook wb = new SXSSFWorkbook(1);
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
SXSSFSheet sheet = wb.createSheet();
|
SXSSFSheet sheet = wb.createSheet();
|
||||||
sheet.createRow(2).createCell(3).setCellValue("top left");
|
sheet.createRow(2).createCell(3).setCellValue("top left");
|
||||||
|
@ -591,7 +591,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook {
|
||||||
assertEquals(6, sheet.getLastRowNum());
|
assertEquals(6, sheet.getLastRowNum());
|
||||||
try (
|
try (
|
||||||
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(wb);
|
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(wb);
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
sxssfWorkbook.write(bos);
|
sxssfWorkbook.write(bos);
|
||||||
try (XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) {
|
try (XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) {
|
||||||
|
@ -606,7 +606,7 @@ final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook {
|
||||||
void addDimensionDisabled() throws IOException {
|
void addDimensionDisabled() throws IOException {
|
||||||
try (
|
try (
|
||||||
SXSSFWorkbook wb = new SXSSFWorkbook();
|
SXSSFWorkbook wb = new SXSSFWorkbook();
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
wb.setShouldCalculateSheetDimensions(false);
|
wb.setShouldCalculateSheetDimensions(false);
|
||||||
SXSSFSheet sheet = wb.createSheet();
|
SXSSFSheet sheet = wb.createSheet();
|
||||||
|
|
|
@ -253,7 +253,7 @@ public final class TestSXSSFBugs extends BaseTestBugzillaIssues {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test65619() throws Exception {
|
void test65619() throws Exception {
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
try (SXSSFWorkbook workbook = new SXSSFWorkbook(100)) {
|
try (SXSSFWorkbook workbook = new SXSSFWorkbook(100)) {
|
||||||
SXSSFSheet sheet = workbook.createSheet("Test Sheet 1");
|
SXSSFSheet sheet = workbook.createSheet("Test Sheet 1");
|
||||||
Font font = workbook.createFont();
|
Font font = workbook.createFont();
|
||||||
|
@ -308,7 +308,7 @@ public final class TestSXSSFBugs extends BaseTestBugzillaIssues {
|
||||||
assertEquals(value, cell.getStringCellValue());
|
assertEquals(value, cell.getStringCellValue());
|
||||||
// so far so good
|
// so far so good
|
||||||
|
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
wb.write(bos);
|
wb.write(bos);
|
||||||
|
|
||||||
try (XSSFWorkbook testWb = new XSSFWorkbook(bos.toInputStream())) {
|
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(blueStyle.getIndex(), r3.getCell(4).getCellStyle().getIndex());
|
||||||
assertEquals(pinkStyle.getIndex(), r3.getCell(6).getCellStyle().getIndex());
|
assertEquals(pinkStyle.getIndex(), r3.getCell(6).getCellStyle().getIndex());
|
||||||
|
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
wb.write(bos);
|
wb.write(bos);
|
||||||
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
|
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
|
||||||
XSSFSheet wb2Sheet = wb2.getSheetAt(0);
|
XSSFSheet wb2Sheet = wb2.getSheetAt(0);
|
||||||
|
|
|
@ -278,7 +278,7 @@ public final class TestUnfixedBugs {
|
||||||
checkRow57423(testSheet, 17, "17");
|
checkRow57423(testSheet, 17, "17");
|
||||||
checkRow57423(testSheet, 18, "18");
|
checkRow57423(testSheet, 18, "18");
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
((XSSFSheet)testSheet).write(stream);
|
((XSSFSheet)testSheet).write(stream);
|
||||||
|
|
||||||
// verify that the resulting XML has the rows in correct order as required by Excel
|
// verify that the resulting XML has the rows in correct order as required by Excel
|
||||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
import static java.time.Duration.between;
|
import static java.time.Duration.between;
|
||||||
import static java.time.Instant.now;
|
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.logging.log4j.util.Unbox.box;
|
||||||
import static org.apache.poi.extractor.ExtractorFactory.OOXML_PACKAGE;
|
import static org.apache.poi.extractor.ExtractorFactory.OOXML_PACKAGE;
|
||||||
import static org.apache.poi.openxml4j.opc.TestContentType.isOldXercesActive;
|
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.ZipArchiveEntry;
|
||||||
import org.apache.commons.compress.archivers.zip.ZipFile;
|
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.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
@ -1537,7 +1537,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
||||||
Thread.sleep(10);
|
Thread.sleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(8096);
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(8096).get();
|
||||||
wb.write(bos);
|
wb.write(bos);
|
||||||
byte[] firstSave = bos.toByteArray();
|
byte[] firstSave = bos.toByteArray();
|
||||||
bos.reset();
|
bos.reset();
|
||||||
|
@ -2982,7 +2982,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
||||||
|
|
||||||
// we currently only populate the dimension during writing out
|
// 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
|
// 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());
|
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
|
// 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
|
// 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());
|
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(blueStyle.getIndex(), r3.getCell(4).getCellStyle().getIndex());
|
||||||
assertEquals(pinkStyle.getIndex(), r3.getCell(6).getCellStyle().getIndex());
|
assertEquals(pinkStyle.getIndex(), r3.getCell(6).getCellStyle().getIndex());
|
||||||
|
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
wb.write(bos);
|
wb.write(bos);
|
||||||
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
|
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
|
||||||
XSSFSheet wb2Sheet = wb2.getSheetAt(0);
|
XSSFSheet wb2Sheet = wb2.getSheetAt(0);
|
||||||
|
@ -3778,13 +3778,13 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
||||||
}
|
}
|
||||||
|
|
||||||
// read bytes of workbook before
|
// read bytes of workbook before
|
||||||
UnsynchronizedByteArrayOutputStream bosOrig = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bosOrig = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
try (FileInputStream fis = new FileInputStream(temp_excel_poi)) {
|
try (FileInputStream fis = new FileInputStream(temp_excel_poi)) {
|
||||||
IOUtils.copy(fis, bosOrig);
|
IOUtils.copy(fis, bosOrig);
|
||||||
}
|
}
|
||||||
|
|
||||||
// for the encrypted bytes
|
// for the encrypted bytes
|
||||||
UnsynchronizedByteArrayOutputStream bosEnc = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bosEnc = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
|
|
||||||
/* encrypt excel by poi */
|
/* encrypt excel by poi */
|
||||||
try (POIFSFileSystem fs = new POIFSFileSystem()) {
|
try (POIFSFileSystem fs = new POIFSFileSystem()) {
|
||||||
|
@ -3810,7 +3810,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
||||||
}
|
}
|
||||||
|
|
||||||
// for the decrytped bytes
|
// for the decrytped bytes
|
||||||
UnsynchronizedByteArrayOutputStream bosDec = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bosDec = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
|
|
||||||
/* decrypt excel by poi */
|
/* decrypt excel by poi */
|
||||||
try (POIFSFileSystem fileSystem = new POIFSFileSystem(temp_excel_poi_encrypt)) {
|
try (POIFSFileSystem fileSystem = new POIFSFileSystem(temp_excel_poi_encrypt)) {
|
||||||
|
|
|
@ -311,7 +311,7 @@ public final class TestXSSFComment extends BaseTestCellComment {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void bug59388CommentVisible() throws IOException {
|
void bug59388CommentVisible() throws IOException {
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("59388.xlsx")) {
|
try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("59388.xlsx")) {
|
||||||
Sheet sheet = wb.getSheetAt(0);
|
Sheet sheet = wb.getSheetAt(0);
|
||||||
Cell a1 = sheet.getRow(0).getCell(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 {
|
private void _testMoveIsSaved(Workbook workbook) throws Exception {
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
CreationHelper factory = workbook.getCreationHelper();
|
CreationHelper factory = workbook.getCreationHelper();
|
||||||
Sheet sheet = workbook.createSheet();
|
Sheet sheet = workbook.createSheet();
|
||||||
Row row = sheet.createRow(0);
|
Row row = sheet.createRow(0);
|
||||||
|
@ -511,7 +511,7 @@ public final class TestXSSFComment extends BaseTestCellComment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _testModificationIsSaved(Workbook workbook) throws Exception {
|
private void _testModificationIsSaved(Workbook workbook) throws Exception {
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
CreationHelper factory = workbook.getCreationHelper();
|
CreationHelper factory = workbook.getCreationHelper();
|
||||||
Sheet sheet = workbook.createSheet();
|
Sheet sheet = workbook.createSheet();
|
||||||
Row row = sheet.createRow(0);
|
Row row = sheet.createRow(0);
|
||||||
|
|
|
@ -386,7 +386,7 @@ public final class TestXSSFSheet extends BaseTestXSheet {
|
||||||
void saveGroupColumns() throws IOException {
|
void saveGroupColumns() throws IOException {
|
||||||
try (
|
try (
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
XSSFSheet sheet = workbook.createSheet();
|
XSSFSheet sheet = workbook.createSheet();
|
||||||
XSSFRow row0 = sheet.createRow(0);
|
XSSFRow row0 = sheet.createRow(0);
|
||||||
|
@ -2268,7 +2268,7 @@ public final class TestXSSFSheet extends BaseTestXSheet {
|
||||||
void testBug64536() throws IOException {
|
void testBug64536() throws IOException {
|
||||||
try (
|
try (
|
||||||
XSSFWorkbook xssfWorkbook = (XSSFWorkbook) _testDataProvider.openSampleWorkbook("1_NoIden.xlsx");
|
XSSFWorkbook xssfWorkbook = (XSSFWorkbook) _testDataProvider.openSampleWorkbook("1_NoIden.xlsx");
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
XSSFSheet fileSheet = xssfWorkbook.getSheetAt(0);
|
XSSFSheet fileSheet = xssfWorkbook.getSheetAt(0);
|
||||||
assertEquals(CellRangeAddress.valueOf("B1:D9"), fileSheet.getDimension());
|
assertEquals(CellRangeAddress.valueOf("B1:D9"), fileSheet.getDimension());
|
||||||
|
|
|
@ -651,7 +651,7 @@ public final class TestXSSFTable {
|
||||||
void testNamesWithNewLines() throws IOException {
|
void testNamesWithNewLines() throws IOException {
|
||||||
try (
|
try (
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
XSSFSheet sheet = wb.createSheet();
|
XSSFSheet sheet = wb.createSheet();
|
||||||
|
|
||||||
|
@ -739,7 +739,7 @@ public final class TestXSSFTable {
|
||||||
void bug66213() throws IOException {
|
void bug66213() throws IOException {
|
||||||
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("table-sample.xlsx")) {
|
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("table-sample.xlsx")) {
|
||||||
wb.cloneSheet(0, "Test");
|
wb.cloneSheet(0, "Test");
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
wb.write(bos);
|
wb.write(bos);
|
||||||
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
|
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
|
||||||
XSSFSheet sheet0 = wb2.getSheetAt(0);
|
XSSFSheet sheet0 = wb2.getSheetAt(0);
|
||||||
|
@ -757,7 +757,7 @@ public final class TestXSSFTable {
|
||||||
void testCloneConditionalFormattingSamples() throws IOException {
|
void testCloneConditionalFormattingSamples() throws IOException {
|
||||||
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("ConditionalFormattingSamples.xlsx")) {
|
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("ConditionalFormattingSamples.xlsx")) {
|
||||||
wb.cloneSheet(0, "Test");
|
wb.cloneSheet(0, "Test");
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
wb.write(bos);
|
wb.write(bos);
|
||||||
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
|
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
|
||||||
XSSFSheet sheet0 = wb2.getSheetAt(0);
|
XSSFSheet sheet0 = wb2.getSheetAt(0);
|
||||||
|
@ -773,7 +773,7 @@ public final class TestXSSFTable {
|
||||||
void testCloneSingleCellTable() throws IOException {
|
void testCloneSingleCellTable() throws IOException {
|
||||||
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("SingleCellTable.xlsx")) {
|
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("SingleCellTable.xlsx")) {
|
||||||
wb.cloneSheet(0, "Test");
|
wb.cloneSheet(0, "Test");
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
wb.write(bos);
|
wb.write(bos);
|
||||||
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
|
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
|
||||||
XSSFSheet sheet0 = wb2.getSheetAt(0);
|
XSSFSheet sheet0 = wb2.getSheetAt(0);
|
||||||
|
|
|
@ -103,7 +103,7 @@ class TestXSSFVMLDrawing {
|
||||||
assertEquals("[True]", cldata.getVisibleList().toString());
|
assertEquals("[True]", cldata.getVisibleList().toString());
|
||||||
|
|
||||||
//serialize and read again
|
//serialize and read again
|
||||||
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
vml.write(out);
|
vml.write(out);
|
||||||
|
|
||||||
XSSFVMLDrawing vml2 = new XSSFVMLDrawing();
|
XSSFVMLDrawing vml2 = new XSSFVMLDrawing();
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package org.apache.poi.xssf.usermodel;
|
package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
|
@ -80,7 +81,6 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.zip.CRC32;
|
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.hssf.HSSFTestDataSamples.openSampleFileStream;
|
||||||
import static org.apache.poi.xssf.XSSFTestDataSamples.openSampleWorkbook;
|
import static org.apache.poi.xssf.XSSFTestDataSamples.openSampleWorkbook;
|
||||||
import static org.apache.poi.xssf.XSSFTestDataSamples.writeOut;
|
import static org.apache.poi.xssf.XSSFTestDataSamples.writeOut;
|
||||||
|
@ -573,7 +573,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
|
||||||
sheet.groupColumn((short) 4, (short) 5);
|
sheet.groupColumn((short) 4, (short) 5);
|
||||||
|
|
||||||
accessWorkbook(workbook);
|
accessWorkbook(workbook);
|
||||||
workbook.write(NULL_OUTPUT_STREAM);
|
workbook.write(NullOutputStream.INSTANCE);
|
||||||
accessWorkbook(workbook);
|
accessWorkbook(workbook);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1240,7 +1240,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testNewWorkbookWithTempFilePackageParts() throws Exception {
|
void testNewWorkbookWithTempFilePackageParts() throws Exception {
|
||||||
try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
assertFalse(ZipPackage.useTempFilePackageParts(), "useTempFilePackageParts defaults to false?");
|
assertFalse(ZipPackage.useTempFilePackageParts(), "useTempFilePackageParts defaults to false?");
|
||||||
assertFalse(ZipPackage.encryptTempFilePackageParts(), "encryptTempFilePackageParts defaults to false?");
|
assertFalse(ZipPackage.encryptTempFilePackageParts(), "encryptTempFilePackageParts defaults to false?");
|
||||||
ZipPackage.setUseTempFilePackageParts(true);
|
ZipPackage.setUseTempFilePackageParts(true);
|
||||||
|
@ -1264,7 +1264,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testNewWorkbookWithEncryptedTempFilePackageParts() throws Exception {
|
void testNewWorkbookWithEncryptedTempFilePackageParts() throws Exception {
|
||||||
try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
assertFalse(ZipPackage.useTempFilePackageParts(), "useTempFilePackageParts defaults to false?");
|
assertFalse(ZipPackage.useTempFilePackageParts(), "useTempFilePackageParts defaults to false?");
|
||||||
assertFalse(ZipPackage.encryptTempFilePackageParts(), "encryptTempFilePackageParts defaults to false?");
|
assertFalse(ZipPackage.encryptTempFilePackageParts(), "encryptTempFilePackageParts defaults to false?");
|
||||||
ZipPackage.setUseTempFilePackageParts(true);
|
ZipPackage.setUseTempFilePackageParts(true);
|
||||||
|
@ -1293,8 +1293,8 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
|
||||||
String nameA = "link-external-workbook-a.xlsx";
|
String nameA = "link-external-workbook-a.xlsx";
|
||||||
|
|
||||||
try (
|
try (
|
||||||
UnsynchronizedByteArrayOutputStream bosA = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bosA = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
UnsynchronizedByteArrayOutputStream bosB = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bosB = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
XSSFWorkbook workbookA = new XSSFWorkbook();
|
XSSFWorkbook workbookA = new XSSFWorkbook();
|
||||||
XSSFWorkbook workbookB = new XSSFWorkbook()
|
XSSFWorkbook workbookB = new XSSFWorkbook()
|
||||||
) {
|
) {
|
||||||
|
@ -1343,8 +1343,8 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
|
||||||
String nameA = "cache-external-workbook-a.xlsx";
|
String nameA = "cache-external-workbook-a.xlsx";
|
||||||
|
|
||||||
try (
|
try (
|
||||||
UnsynchronizedByteArrayOutputStream bosA = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bosA = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
UnsynchronizedByteArrayOutputStream bosB = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bosB = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
XSSFWorkbook workbookA = new XSSFWorkbook();
|
XSSFWorkbook workbookA = new XSSFWorkbook();
|
||||||
XSSFWorkbook workbookB = new XSSFWorkbook()
|
XSSFWorkbook workbookB = new XSSFWorkbook()
|
||||||
) {
|
) {
|
||||||
|
@ -1381,7 +1381,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
|
||||||
@Test
|
@Test
|
||||||
void checkExistingFileForR1C1Refs() throws IOException {
|
void checkExistingFileForR1C1Refs() throws IOException {
|
||||||
try (
|
try (
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
XSSFWorkbook wb = openSampleWorkbook("WithTable.xlsx")
|
XSSFWorkbook wb = openSampleWorkbook("WithTable.xlsx")
|
||||||
) {
|
) {
|
||||||
assertEquals(CellReferenceType.A1, wb.getCellReferenceType());
|
assertEquals(CellReferenceType.A1, wb.getCellReferenceType());
|
||||||
|
@ -1397,7 +1397,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
|
||||||
@Test
|
@Test
|
||||||
void checkNewFileForR1C1Refs() throws IOException {
|
void checkNewFileForR1C1Refs() throws IOException {
|
||||||
try (
|
try (
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
XSSFWorkbook wb = new XSSFWorkbook()
|
XSSFWorkbook wb = new XSSFWorkbook()
|
||||||
) {
|
) {
|
||||||
assertEquals(CellReferenceType.UNKNOWN, wb.getCellReferenceType());
|
assertEquals(CellReferenceType.UNKNOWN, wb.getCellReferenceType());
|
||||||
|
|
|
@ -152,7 +152,7 @@ final class TestXSSFBubbleChartData {
|
||||||
setRoundedCorners(chart, false);
|
setRoundedCorners(chart, false);
|
||||||
|
|
||||||
// Write the output to a file
|
// Write the output to a file
|
||||||
try (UnsynchronizedByteArrayOutputStream outStream = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream outStream = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
wb.write(outStream);
|
wb.write(outStream);
|
||||||
try (XSSFWorkbook wb2 = new XSSFWorkbook(outStream.toInputStream())) {
|
try (XSSFWorkbook wb2 = new XSSFWorkbook(outStream.toInputStream())) {
|
||||||
// see if this fails
|
// see if this fails
|
||||||
|
|
|
@ -69,7 +69,7 @@ public final class TestEvilUnclosedBRFixingInputStream {
|
||||||
// overflow or only part in the buffer
|
// overflow or only part in the buffer
|
||||||
for(int i=5; i<orig.length; i++) {
|
for(int i=5; i<orig.length; i++) {
|
||||||
try (EvilUnclosedBRFixingInputStream inp = new EvilUnclosedBRFixingInputStream(orig);
|
try (EvilUnclosedBRFixingInputStream inp = new EvilUnclosedBRFixingInputStream(orig);
|
||||||
UnsynchronizedByteArrayOutputStream bout = new UnsynchronizedByteArrayOutputStream()) {
|
UnsynchronizedByteArrayOutputStream bout = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
byte[] b = new byte[i];
|
byte[] b = new byte[i];
|
||||||
int r = inp.read(b);
|
int r = inp.read(b);
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class XWPFTestDataSamples {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static XWPFDocument writeOutAndReadBack(XWPFDocument doc) throws IOException {
|
public static XWPFDocument writeOutAndReadBack(XWPFDocument doc) throws IOException {
|
||||||
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(4096);
|
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(4096).get();
|
||||||
doc.write(baos);
|
doc.write(baos);
|
||||||
return new XWPFDocument(baos.toInputStream());
|
return new XWPFDocument(baos.toInputStream());
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ class TestChangeTracking {
|
||||||
r1.setText("Lorem ipsum dolor sit amet.");
|
r1.setText("Lorem ipsum dolor sit amet.");
|
||||||
doc.setTrackRevisions(true);
|
doc.setTrackRevisions(true);
|
||||||
|
|
||||||
try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
doc.write(out);
|
doc.write(out);
|
||||||
|
|
||||||
try (InputStream inputStream = out.toInputStream()) {
|
try (InputStream inputStream = out.toInputStream()) {
|
||||||
|
|
|
@ -185,7 +185,12 @@ public class OLE2ScratchpadExtractorFactory implements ExtractorProvider {
|
||||||
for (AttachmentChunks attachment : msg.getAttachmentFiles()) {
|
for (AttachmentChunks attachment : msg.getAttachmentFiles()) {
|
||||||
if (attachment.getAttachData() != null) {
|
if (attachment.getAttachData() != null) {
|
||||||
byte[] data = attachment.getAttachData().getValue();
|
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) {
|
} else if (attachment.getAttachmentDirectory() != null) {
|
||||||
dirs.add(attachment.getAttachmentDirectory().getDirectory());
|
dirs.add(attachment.getAttachmentDirectory().getDirectory());
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class HDGFLZW extends LZWDecompresser {
|
||||||
* @throws IOException when the InputStream can't be read
|
* @throws IOException when the InputStream can't be read
|
||||||
*/
|
*/
|
||||||
public byte[] compress(InputStream src) throws IOException {
|
public byte[] compress(InputStream src) throws IOException {
|
||||||
UnsynchronizedByteArrayOutputStream res = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream res = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
compress(src,res);
|
compress(src,res);
|
||||||
return res.toByteArray();
|
return res.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ public final class CompressedStreamStore extends StreamStore {
|
||||||
* Decompresses the given data, returning it as header + contents
|
* Decompresses the given data, returning it as header + contents
|
||||||
*/
|
*/
|
||||||
public static byte[][] decompress(byte[] data, int offset, int length) throws IOException {
|
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
|
// Decompress
|
||||||
HDGFLZW lzw = new HDGFLZW();
|
HDGFLZW lzw = new HDGFLZW();
|
||||||
byte[] decompressed = lzw.decompress(bais);
|
byte[] decompressed = lzw.decompress(bais);
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class HemfImageRenderer implements ImageRenderer, EmbeddedExtractor {
|
||||||
if (!PictureData.PictureType.EMF.contentType.equals(contentType)) {
|
if (!PictureData.PictureType.EMF.contentType.equals(contentType)) {
|
||||||
throw new IOException("Invalid picture type");
|
throw new IOException("Invalid picture type");
|
||||||
}
|
}
|
||||||
image = new HemfPicture(new UnsynchronizedByteArrayInputStream(data));
|
image = new HemfPicture(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -792,7 +792,7 @@ public final class HemfFill {
|
||||||
return (long)undefinedSpace1 + bitmap.init(leis, dibSize);
|
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);
|
final long cbBmiSrcAct = IOUtils.copy(leis, bos, cbBmi);
|
||||||
assert (cbBmiSrcAct == cbBmi);
|
assert (cbBmiSrcAct == cbBmi);
|
||||||
leis.skipFully(undefinedSpace2);
|
leis.skipFully(undefinedSpace2);
|
||||||
|
|
|
@ -396,7 +396,7 @@ public class HemfPlusBrush {
|
||||||
public EmfPlusBrushData getBrushData(List<? extends EmfPlusObjectData> continuedObjectData) {
|
public EmfPlusBrushData getBrushData(List<? extends EmfPlusObjectData> continuedObjectData) {
|
||||||
EmfPlusBrushData brushData = brushType.constructor.get();
|
EmfPlusBrushData brushData = brushType.constructor.get();
|
||||||
byte[] buf = getRawData(continuedObjectData);
|
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);
|
brushData.init(new LittleEndianInputStream(bis), buf.length);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
|
@ -410,7 +410,7 @@ public class HemfPlusBrush {
|
||||||
* @throws IllegalStateException if the data cannot be processed
|
* @throws IllegalStateException if the data cannot be processed
|
||||||
*/
|
*/
|
||||||
public byte[] getRawData(List<? extends EmfPlusObjectData> continuedObjectData) {
|
public byte[] getRawData(List<? extends EmfPlusObjectData> continuedObjectData) {
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
bos.write(getBrushBytes());
|
bos.write(getBrushBytes());
|
||||||
if (continuedObjectData != null) {
|
if (continuedObjectData != null) {
|
||||||
for (EmfPlusObjectData od : continuedObjectData) {
|
for (EmfPlusObjectData od : continuedObjectData) {
|
||||||
|
|
|
@ -419,13 +419,13 @@ public class HemfPlusImage {
|
||||||
if (getBitmapType() == EmfPlusBitmapDataType.PIXEL) {
|
if (getBitmapType() == EmfPlusBitmapDataType.PIXEL) {
|
||||||
return new Rectangle2D.Double(0, 0, bitmapWidth, bitmapHeight);
|
return new Rectangle2D.Double(0, 0, bitmapWidth, bitmapHeight);
|
||||||
} else {
|
} else {
|
||||||
try(UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(getRawData(continuedObjectData))) {
|
try(UnsynchronizedByteArrayInputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(getRawData(continuedObjectData)).get()) {
|
||||||
BufferedImage bi = ImageIO.read(is);
|
BufferedImage bi = ImageIO.read(is);
|
||||||
return new Rectangle2D.Double(bi.getMinX(), bi.getMinY(), bi.getWidth(), bi.getHeight());
|
return new Rectangle2D.Double(bi.getMinX(), bi.getMinY(), bi.getWidth(), bi.getHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case METAFILE:
|
case METAFILE:
|
||||||
try(UnsynchronizedByteArrayInputStream bis = new UnsynchronizedByteArrayInputStream(getRawData(continuedObjectData))) {
|
try(UnsynchronizedByteArrayInputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(getRawData(continuedObjectData)).get()) {
|
||||||
switch (getMetafileType()) {
|
switch (getMetafileType()) {
|
||||||
case Wmf:
|
case Wmf:
|
||||||
case WmfPlaceable:
|
case WmfPlaceable:
|
||||||
|
@ -453,7 +453,7 @@ public class HemfPlusImage {
|
||||||
* @throws IllegalStateException if the data cannot be read
|
* @throws IllegalStateException if the data cannot be read
|
||||||
*/
|
*/
|
||||||
public byte[] getRawData(List<? extends EmfPlusObjectData> continuedObjectData) {
|
public byte[] getRawData(List<? extends EmfPlusObjectData> continuedObjectData) {
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
bos.write(getImageData());
|
bos.write(getImageData());
|
||||||
if (continuedObjectData != null) {
|
if (continuedObjectData != null) {
|
||||||
for (EmfPlusObjectData od : continuedObjectData) {
|
for (EmfPlusObjectData od : continuedObjectData) {
|
||||||
|
|
|
@ -293,7 +293,7 @@ public class HemfEmbeddedIterator implements Iterator<HwmfEmbedded> {
|
||||||
private void compressGDIBitmap(EmfPlusImage img, HwmfEmbedded emb, HwmfEmbeddedType et) {
|
private void compressGDIBitmap(EmfPlusImage img, HwmfEmbedded emb, HwmfEmbeddedType et) {
|
||||||
BufferedImage bi = img.readGDIImage(emb.getRawData());
|
BufferedImage bi = img.readGDIImage(emb.getRawData());
|
||||||
try {
|
try {
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
// use HwmfEmbeddedType literal for conversion
|
// use HwmfEmbeddedType literal for conversion
|
||||||
ImageIO.write(bi, et.toString(), bos);
|
ImageIO.write(bi, et.toString(), bos);
|
||||||
emb.setData(bos.toByteArray());
|
emb.setData(bos.toByteArray());
|
||||||
|
@ -318,7 +318,7 @@ public class HemfEmbeddedIterator implements Iterator<HwmfEmbedded> {
|
||||||
: epo.getTotalObjectSize();
|
: epo.getTotalObjectSize();
|
||||||
IOUtils.safelyAllocateCheck(totalSize, MAX_RECORD_LENGTH);
|
IOUtils.safelyAllocateCheck(totalSize, MAX_RECORD_LENGTH);
|
||||||
|
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(totalSize)) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(totalSize).get()) {
|
||||||
boolean hasNext = false;
|
boolean hasNext = false;
|
||||||
do {
|
do {
|
||||||
EmfPlusImage img = epo.getObjectData();
|
EmfPlusImage img = epo.getObjectData();
|
||||||
|
|
|
@ -116,7 +116,7 @@ public class MAPIAttribute {
|
||||||
"instead received a " + parent.getProperty() + " one"
|
"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
|
// First up, get the number of attributes
|
||||||
int count = LittleEndian.readInt(inp);
|
int count = LittleEndian.readInt(inp);
|
||||||
List<MAPIAttribute> attrs = new ArrayList<>();
|
List<MAPIAttribute> attrs = new ArrayList<>();
|
||||||
|
|
|
@ -46,7 +46,7 @@ public final class MAPIRtfAttribute extends MAPIAttribute {
|
||||||
// Decompress it, removing any trailing padding as needed
|
// Decompress it, removing any trailing padding as needed
|
||||||
CompressedRTF rtf = new CompressedRTF();
|
CompressedRTF rtf = new CompressedRTF();
|
||||||
byte[] tmp;
|
byte[] tmp;
|
||||||
try (InputStream is = new UnsynchronizedByteArrayInputStream(data)) {
|
try (InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get()) {
|
||||||
tmp = rtf.decompress(is);
|
tmp = rtf.decompress(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ public abstract class HPBFPart {
|
||||||
generateData();
|
generateData();
|
||||||
|
|
||||||
// Write out
|
// Write out
|
||||||
try (UnsynchronizedByteArrayInputStream bais = new UnsynchronizedByteArrayInputStream(data)) {
|
try (UnsynchronizedByteArrayInputStream bais = UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get()) {
|
||||||
dir.createDocument(path[path.length-1], bais);
|
dir.createDocument(path[path.length-1], bais);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ public abstract class Bitmap extends HSLFPictureData {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getImageDimension() {
|
public Dimension getImageDimension() {
|
||||||
try (InputStream is = new UnsynchronizedByteArrayInputStream(getData())){
|
try (InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(getData()).get()){
|
||||||
BufferedImage bi = ImageIO.read(is);
|
BufferedImage bi = ImageIO.read(is);
|
||||||
return new Dimension(
|
return new Dimension(
|
||||||
(int)Units.pixelToPoints(bi.getWidth()),
|
(int)Units.pixelToPoints(bi.getWidth()),
|
||||||
|
|
|
@ -69,9 +69,9 @@ public final class EMF extends Metafile {
|
||||||
header.read(rawdata, CHECKSUM_SIZE);
|
header.read(rawdata, CHECKSUM_SIZE);
|
||||||
|
|
||||||
try (
|
try (
|
||||||
InputStream is = new UnsynchronizedByteArrayInputStream(rawdata);
|
InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(rawdata).get();
|
||||||
InflaterInputStream inflater = new InflaterInputStream(is);
|
InflaterInputStream inflater = new InflaterInputStream(is);
|
||||||
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()
|
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()
|
||||||
) {
|
) {
|
||||||
long len = IOUtils.skipFully(is,header.getSize() + (long)CHECKSUM_SIZE);
|
long len = IOUtils.skipFully(is,header.getSize() + (long)CHECKSUM_SIZE);
|
||||||
assert(len == header.getSize() + CHECKSUM_SIZE);
|
assert(len == header.getSize() + CHECKSUM_SIZE);
|
||||||
|
|
|
@ -91,7 +91,7 @@ public abstract class Metafile extends HSLFPictureData {
|
||||||
public void read(byte[] data, int offset) {
|
public void read(byte[] data, int offset) {
|
||||||
try (
|
try (
|
||||||
LittleEndianInputStream leis = new LittleEndianInputStream(
|
LittleEndianInputStream leis = new LittleEndianInputStream(
|
||||||
new UnsynchronizedByteArrayInputStream(data, offset, RECORD_LENGTH))
|
UnsynchronizedByteArrayInputStream.builder().setByteArray(data).setOffset(offset).setLength(RECORD_LENGTH).get())
|
||||||
) {
|
) {
|
||||||
wmfsize = leis.readInt();
|
wmfsize = leis.readInt();
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ public abstract class Metafile extends HSLFPictureData {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static byte[] compress(byte[] bytes, int offset, int length) {
|
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)) {
|
try (DeflaterOutputStream deflater = new DeflaterOutputStream(out)) {
|
||||||
deflater.write(bytes, offset, length);
|
deflater.write(bytes, offset, length);
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
|
|
|
@ -72,7 +72,7 @@ public final class PICT extends Metafile {
|
||||||
@Override
|
@Override
|
||||||
public byte[] getData(){
|
public byte[] getData(){
|
||||||
byte[] rawdata = getRawData();
|
byte[] rawdata = getRawData();
|
||||||
try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
byte[] macheader = new byte[512];
|
byte[] macheader = new byte[512];
|
||||||
out.write(macheader);
|
out.write(macheader);
|
||||||
int pos = CHECKSUM_SIZE*getUIDInstanceCount();
|
int pos = CHECKSUM_SIZE*getUIDInstanceCount();
|
||||||
|
@ -88,13 +88,13 @@ public final class PICT extends Metafile {
|
||||||
Header header = new Header();
|
Header header = new Header();
|
||||||
header.read(data, pos);
|
header.read(data, pos);
|
||||||
long bs_exp = (long)pos + header.getSize();
|
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);
|
long bs_act = IOUtils.skipFully(bis, bs_exp);
|
||||||
if (bs_exp != bs_act) {
|
if (bs_exp != bs_act) {
|
||||||
throw new EOFException();
|
throw new EOFException();
|
||||||
}
|
}
|
||||||
byte[] chunk = new byte[4096];
|
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)) {
|
try (InflaterInputStream inflater = new InflaterInputStream(bis)) {
|
||||||
int count;
|
int count;
|
||||||
while ((count = inflater.read(chunk)) >= 0) {
|
while ((count = inflater.read(chunk)) >= 0) {
|
||||||
|
|
|
@ -65,7 +65,7 @@ public final class WMF extends Metafile {
|
||||||
@Override
|
@Override
|
||||||
public byte[] getData(){
|
public byte[] getData(){
|
||||||
byte[] rawdata = getRawData();
|
byte[] rawdata = getRawData();
|
||||||
try (InputStream is = new UnsynchronizedByteArrayInputStream(rawdata)) {
|
try (InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(rawdata).get()) {
|
||||||
|
|
||||||
|
|
||||||
Header header = new Header();
|
Header header = new Header();
|
||||||
|
@ -75,7 +75,7 @@ public final class WMF extends Metafile {
|
||||||
assert(skipped == skipLen);
|
assert(skipped == skipLen);
|
||||||
|
|
||||||
ImageHeaderWMF aldus = new ImageHeaderWMF(header.getBounds());
|
ImageHeaderWMF aldus = new ImageHeaderWMF(header.getBounds());
|
||||||
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
aldus.write(out);
|
aldus.write(out);
|
||||||
|
|
||||||
try (InflaterInputStream inflater = new InflaterInputStream( is )) {
|
try (InflaterInputStream inflater = new InflaterInputStream( is )) {
|
||||||
|
|
|
@ -65,7 +65,7 @@ public final class PPTXMLDump {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try (InputStream is = dn.createDocumentInputStream(entry);
|
try (InputStream is = dn.createDocumentInputStream(entry);
|
||||||
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
IOUtils.copy(is, bos);
|
IOUtils.copy(is, bos);
|
||||||
return bos.toByteArray();
|
return bos.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,7 +147,7 @@ public final class SlideIdListing {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increase the position by the on disk size
|
// Increase the position by the on disk size
|
||||||
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
r.writeOut(baos);
|
r.writeOut(baos);
|
||||||
pos += baos.size();
|
pos += baos.size();
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,7 @@ public final class SlideShowRecordDumper {
|
||||||
public int getDiskLen(org.apache.poi.hslf.record.Record r) throws IOException {
|
public int getDiskLen(org.apache.poi.hslf.record.Record r) throws IOException {
|
||||||
int diskLen = 0;
|
int diskLen = 0;
|
||||||
if (r != null) {
|
if (r != null) {
|
||||||
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
r.writeOut(baos);
|
r.writeOut(baos);
|
||||||
diskLen = baos.size();
|
diskLen = baos.size();
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ public final class SlideShowRecordDumper {
|
||||||
return "<<null>>";
|
return "<<null>>";
|
||||||
}
|
}
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
r.writeOut(baos);
|
r.writeOut(baos);
|
||||||
byte[] b = baos.toByteArray();
|
byte[] b = baos.toByteArray();
|
||||||
return HexDump.dump(b, 0, 0);
|
return HexDump.dump(b, 0, 0);
|
||||||
|
@ -258,7 +258,7 @@ public final class SlideShowRecordDumper {
|
||||||
if (optEscher && cname.equals("PPDrawing")) {
|
if (optEscher && cname.equals("PPDrawing")) {
|
||||||
DefaultEscherRecordFactory factory = new HSLFEscherRecordFactory();
|
DefaultEscherRecordFactory factory = new HSLFEscherRecordFactory();
|
||||||
|
|
||||||
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
r.writeOut(baos);
|
r.writeOut(baos);
|
||||||
byte[] b = baos.toByteArray();
|
byte[] b = baos.toByteArray();
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ public final class UserEditAndPersistListing {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increase the position by the on disk size
|
// Increase the position by the on disk size
|
||||||
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
r.writeOut(baos);
|
r.writeOut(baos);
|
||||||
pos += baos.size();
|
pos += baos.size();
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ public final class UserEditAndPersistListing {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increase the position by the on disk size
|
// Increase the position by the on disk size
|
||||||
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
r.writeOut(baos);
|
r.writeOut(baos);
|
||||||
pos += baos.size();
|
pos += baos.size();
|
||||||
}
|
}
|
||||||
|
|
|
@ -379,7 +379,7 @@ public class TextPropCollection implements GenericRecord, Duplicatable {
|
||||||
out.append(" bytes that would be written: \n");
|
out.append(" bytes that would be written: \n");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
writeOut(baos);
|
writeOut(baos);
|
||||||
byte[] b = baos.toByteArray();
|
byte[] b = baos.toByteArray();
|
||||||
out.append(HexDump.dump(b, 0, 0));
|
out.append(HexDump.dump(b, 0, 0));
|
||||||
|
|
|
@ -154,7 +154,7 @@ public final class ColorSchemeAtom extends RecordAtom {
|
||||||
byte[] ret = new byte[3];
|
byte[] ret = new byte[3];
|
||||||
|
|
||||||
// Serialise to bytes, then grab the right ones out
|
// Serialise to bytes, then grab the right ones out
|
||||||
UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
|
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
try {
|
try {
|
||||||
writeLittleEndian(rgb,baos);
|
writeLittleEndian(rgb,baos);
|
||||||
} catch(IOException ie) {
|
} catch(IOException ie) {
|
||||||
|
|
|
@ -264,7 +264,7 @@ public class CurrentUserAtom {
|
||||||
*/
|
*/
|
||||||
public void writeToFS(POIFSFileSystem fs) throws IOException {
|
public void writeToFS(POIFSFileSystem fs) throws IOException {
|
||||||
// Grab contents
|
// Grab contents
|
||||||
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
writeOut(baos);
|
writeOut(baos);
|
||||||
try (InputStream is = baos.toInputStream()) {
|
try (InputStream is = baos.toInputStream()) {
|
||||||
// Write out
|
// Write out
|
||||||
|
|
|
@ -89,7 +89,7 @@ public final class EscherTextboxWrapper extends RecordContainer {
|
||||||
// Write out our children, and stuff them into the Escher layer
|
// Write out our children, and stuff them into the Escher layer
|
||||||
|
|
||||||
// Grab the children's data
|
// 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) {
|
for (org.apache.poi.hslf.record.Record r : _children) {
|
||||||
r.writeOut(baos);
|
r.writeOut(baos);
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ public class ExOleObjStg extends PositionDependentRecordAtom implements PersistR
|
||||||
* @param data the embedded data.
|
* @param data the embedded data.
|
||||||
*/
|
*/
|
||||||
public void setData(byte[] data) throws IOException {
|
public void setData(byte[] data) throws IOException {
|
||||||
try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
|
try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
|
||||||
DeflaterOutputStream def = new DeflaterOutputStream(out)) {
|
DeflaterOutputStream def = new DeflaterOutputStream(out)) {
|
||||||
//first four bytes is the length of the raw data
|
//first four bytes is the length of the raw data
|
||||||
byte[] b = new byte[4];
|
byte[] b = new byte[4];
|
||||||
|
|
|
@ -93,7 +93,7 @@ public class HSLFEscherClientDataRecord extends EscherClientDataRecord {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getRemainingData() {
|
public byte[] getRemainingData() {
|
||||||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
|
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
|
||||||
for (org.apache.poi.hslf.record.Record r : _childRecords) {
|
for (org.apache.poi.hslf.record.Record r : _childRecords) {
|
||||||
r.writeOut(bos);
|
r.writeOut(bos);
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue