box.setText("Hello, World!");
box.setAnchor(new Rectangle(36, 15, 648, 65));
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
ppt.write(out);
return out.toByteArray();
}
Sheet s = wb.createSheet("OSGi");
s.createRow(0).createCell(0).setCellValue("Hello, World!");
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
wb.write(out);
return out.toByteArray();
}
box2.setAnchor(new Rectangle(36, 80, 648, 400));
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
ppt.write(baos);
try (InputStream bais = baos.toInputStream()) {
ppt = SlideShowFactory.create(bais);
s.createRow(0).createCell(0).setCellValue("With OSGi");
s.createRow(1).createCell(0).setCellFormula("SUM(A1:B3)");
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(baos);
try (InputStream bais = baos.toInputStream()) {
wb = WorkbookFactory.create(bais);
private static int loadPicture( String path, HSSFWorkbook wb ) throws IOException {
int pictureIndex;
try (FileInputStream fis = new FileInputStream(path);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
IOUtils.copy(fis, bos);
pictureIndex = wb.addPicture(bos.toByteArray(), Workbook.PICTURE_TYPE_PNG);
}
for (XSSFMap map : wb.getCustomXMLMappings()) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
- UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xml = os.toString(StandardCharsets.UTF_8);
System.out.println(xml);
public class TestXLSX2CSV {
private PrintStream err;
- private final UnsynchronizedByteArrayOutputStream errorBytes = new UnsynchronizedByteArrayOutputStream();
+ private final UnsynchronizedByteArrayOutputStream errorBytes = UnsynchronizedByteArrayOutputStream.builder().get();
@BeforeEach
public void setUp() throws UnsupportedEncodingException {
@Test
public void testSampleFile() throws Exception {
- final UnsynchronizedByteArrayOutputStream outputBytes = new UnsynchronizedByteArrayOutputStream();
+ final UnsynchronizedByteArrayOutputStream outputBytes = UnsynchronizedByteArrayOutputStream.builder().get();
PrintStream out = new PrintStream(outputBytes, true, StandardCharsets.UTF_8.name());
// The package open is instantaneous, as it should be.
@Test
public void testMinColumns() throws Exception {
- final UnsynchronizedByteArrayOutputStream outputBytes = new UnsynchronizedByteArrayOutputStream();
+ final UnsynchronizedByteArrayOutputStream outputBytes = UnsynchronizedByteArrayOutputStream.builder().get();
PrintStream out = new PrintStream(outputBytes, true, StandardCharsets.UTF_8.name());
// The package open is instantaneous, as it should be.
}
protected void handlePOIDocument(POIDocument doc) throws Exception {
- try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) {
doc.write(out);
try (InputStream in = out.toInputStream();
readPictures(ss);
// write out the file
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
ss.write(out);
readContent(ss);
}
private UnsynchronizedByteArrayOutputStream writeToArray(Workbook wb) throws IOException {
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().get();
wb.write(stream);
return stream;
}
public void handleFile(InputStream stream, String path) throws Exception {
byte[] bytes = IOUtils.toByteArray(stream);
- try (OPCPackage opcPackage = OPCPackage.open(new UnsynchronizedByteArrayInputStream(bytes))) {
+ try (OPCPackage opcPackage = OPCPackage.open(UnsynchronizedByteArrayInputStream.builder().setByteArray(bytes).get())) {
testOne(opcPackage);
}
- testNotHandledByWorkbookException(OPCPackage.open(new UnsynchronizedByteArrayInputStream(bytes)));
+ testNotHandledByWorkbookException(OPCPackage.open(UnsynchronizedByteArrayInputStream.builder().setByteArray(bytes).get()));
}
private void testNotHandledByWorkbookException(OPCPackage pkg) throws IOException {
==================================================================== */
package org.apache.poi.stress;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.poi.xssf.XSSFTestDataSamples.getSampleFile;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import javax.xml.transform.TransformerException;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.examples.ss.ExcelComparator;
// make sure the potentially large byte-array is freed up quickly again
{
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
IOUtils.copy(stream, out);
if (pass != null) {
TransformerException {
for (XSSFMap map : wb.getCustomXMLMappings()) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
- exporter.exportToXML(NULL_OUTPUT_STREAM, true);
+ exporter.exportToXML(NullOutputStream.INSTANCE, true);
}
}
if (data == null) {
data = new byte[0];
}
- return new UnsynchronizedByteArrayInputStream(data);
+ try {
+ return UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get();
+ } catch (IOException e) {
+ // not possible with ByteArray but still declared in the API
+ throw new IllegalStateException(e);
+ }
}
@Override
@Override
public boolean load(InputStream is) throws InvalidFormatException {
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
// Grab the data
IOUtils.copy(is, baos);
// Save it
public MemoryPackagePartOutputStream(MemoryPackagePart part) {
this._part = part;
- _buff = new UnsynchronizedByteArrayOutputStream();
+ _buff = UnsynchronizedByteArrayOutputStream.builder().get();
}
@Override
throw new IOException("temp file " + tempFile.getAbsolutePath() + " is missing");
}
} else if (data != null) {
- return new UnsynchronizedByteArrayInputStream(data);
+ return UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get();
} else {
throw new IOException("Cannot retrieve data from Zip Entry, probably because the Zip Entry was closed before the data was requested.");
}
}
public byte[] sign() throws IOException, GeneralSecurityException {
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
bos.write(getHashMagic());
bos.write(md.digest());
// in an earlier release the hashMagic (aka DigestAlgorithmIdentifier) contained only
// an object identifier, but to conform with the header generated by the
// javax-signature API, the empty <associated parameters> are also included
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
final byte[] oidBytes = new Oid(algo.rsaOid).getDER();
bos.write(0x30);
if (part.getPartName().toString().endsWith(".rels")) {
// although xmlsec has an option to ignore line breaks, currently this
// only affects .rels files, so we only modify these
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
for (int ch; (ch = dataStream.read()) != -1; ) {
if (ch == 10 || ch == 13) continue;
bos.write(ch);
rnd.drawImage(gfx, new Rectangle2D.Double(0, 0, defaultWidth, defaultHeight));
gfx.dispose();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
ImageIO.write(bi, "PNG", bos);
return bos.toByteArray();
}
gfx.dispose();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
ImageIO.write(bi, "PNG", bos);
return bos.toByteArray();
}
X509CRL crl;
try {
crl = (X509CRL) this.certificateFactory
- .generateCRL(new UnsynchronizedByteArrayInputStream(encodedCrl));
+ .generateCRL(UnsynchronizedByteArrayInputStream.builder().setByteArray(encodedCrl).get());
} catch (CRLException e) {
throw new IllegalStateException("CRL parse error: " + e.getMessage(), e);
+ } catch (IOException e) {
+ // not possible with ByteArray but still declared in the API
+ throw new IllegalStateException(e);
}
CRLIdentifierType crlIdentifier = crlRef.addNewCRLIdentifier();
}
private static byte[] getC14nValue(List<Node> nodeList, String c14nAlgoId) {
- try (UnsynchronizedByteArrayOutputStream c14nValue = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream c14nValue = UnsynchronizedByteArrayOutputStream.builder().get()) {
for (Node node : nodeList) {
/*
* Re-initialize the c14n else the namespaces will get cached
@Override
public void loadImage(byte[] data, String contentType) throws IOException {
- loadImage(new UnsynchronizedByteArrayInputStream(data), contentType);
+ loadImage(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get(), contentType);
}
@Override
}
if (imgData == null) {
BufferedImage bi = imgRdr.getImage();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try {
ImageIO.write(bi, "PNG", bos);
} catch (IOException e) {
/** parses the metro bytes to a XSLF shape */
@Override
public XSLFShape parseShape(byte[] metroBytes) throws IOException {
- try (OPCPackage pkg = OPCPackage.open(new UnsynchronizedByteArrayInputStream(metroBytes))) {
+ try (OPCPackage pkg = OPCPackage.open(UnsynchronizedByteArrayInputStream.builder().setByteArray(metroBytes).get())) {
PackagePartName shapePN = PackagingURIHelper.createPartName("/drs/shapexml.xml");
PackagePart shapePart = pkg.getPart(shapePN);
if (shapePart == null) {
}
BufferedImage thmBI = renderer.getImage(dim);
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(100000)) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(100000).get()) {
// use extension instead of enum name, because of "jpeg"
ImageIO.write(thmBI, pt.extension.substring(1), bos);
public DummyFormat() {
try {
- bos = new UnsynchronizedByteArrayOutputStream();
+ bos = UnsynchronizedByteArrayOutputStream.builder().get();
dummy2d = new DummyGraphics2d(new PrintStream(bos, true, StandardCharsets.UTF_8.name()));
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
flushSheets();
//Save the template
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
_wb.write(bos);
//Substitute the template entries with the generated sheet data files
// hack because I can't figure out how to get XMLBeans to parse a sub-element in a standalone manner
// - build a fake styles.xml file with just this built-in
StylesTable styles = new StylesTable();
- try (UnsynchronizedByteArrayInputStream bis = new UnsynchronizedByteArrayInputStream(
- styleXML(dxfsNode, tableStyleNode).getBytes(StandardCharsets.UTF_8))) {
+ try (UnsynchronizedByteArrayInputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(
+ styleXML(dxfsNode, tableStyleNode).getBytes(StandardCharsets.UTF_8)).get()) {
styles.readFrom(bis);
}
styleMap.put(builtIn, new XSSFBuiltinTypeStyleStyle(builtIn, styles.getExplicitTableStyle(styleName)));
@Override
protected void read(InputStream is) throws IOException {
//initialize the supeclass with a blank worksheet
- super.read(new UnsynchronizedByteArrayInputStream(BLANK_WORKSHEET));
+ super.read(UnsynchronizedByteArrayInputStream.builder().setByteArray(BLANK_WORKSHEET).get());
try {
chartsheet = ChartsheetDocument.Factory.parse(is, DEFAULT_XML_OPTIONS).getChartsheet();
}
private static byte[] blankWorksheet(){
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
try {
new XSSFSheet().write(out);
} catch (IOException e){
protected static OPCPackage newPackage(XSSFWorkbookType workbookType) {
OPCPackage pkg = null;
try {
- pkg = OPCPackage.create(new UnsynchronizedByteArrayOutputStream()); // NOSONAR - we do not want to close this here
+ pkg = OPCPackage.create(UnsynchronizedByteArrayOutputStream.builder().get()); // NOSONAR - we do not want to close this here
// Main part
PackagePartName corePartName = PackagingURIHelper.createPartName(XSSFRelation.WORKBOOK.getDefaultFileName());
// Create main part relationship
}
- try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) {
srcSheet.write(out);
try (InputStream bis = out.toInputStream()) {
clonedSheet.read(bis);
Ole10Native ole10 = new Ole10Native(label, fileName, command, oleData);
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(oleData.length+500)) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(oleData.length+500).get()) {
ole10.writeOut(bos);
try (POIFSFileSystem poifs = new POIFSFileSystem()) {
protected static OPCPackage newPackage() {
OPCPackage pkg = null;
try {
- pkg = OPCPackage.create(new UnsynchronizedByteArrayOutputStream()); // NOSONAR - we do not want to close this here
+ pkg = OPCPackage.create(UnsynchronizedByteArrayOutputStream.builder().get()); // NOSONAR - we do not want to close this here
// Main part
PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
// Create main part relationship
package org.apache.poi.ooxml;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import java.util.HashSet;
import java.util.List;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart;
import org.apache.poi.ooxml.util.PackageHelper;
// Should not be able to write a document that has been closed
doc.close();
- IOException e2 = assertThrows(IOException.class, () -> doc.write(NULL_OUTPUT_STREAM),
+ IOException e2 = assertThrows(IOException.class, () -> doc.write(NullOutputStream.INSTANCE),
"Should not be able to write a document that has been closed.");
assertEquals("Cannot write data, document seems to have been closed already", e2.getMessage());
*/
@Test
void createPackageWithCoreDocument() throws IOException, InvalidFormatException, URISyntaxException, SAXException {
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (OPCPackage pkg = OPCPackage.create(baos)) {
// Add a core document
@Test
void zipBombCreateAndHandle()
throws IOException, EncryptedDocumentException {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(2500000);
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(2500000).get();
try (ZipFile zipFile = ZipHelper.openZipFile(getSampleFile("sample.xlsx"));
ZipArchiveOutputStream append = new ZipArchiveOutputStream(bos)) {
@Test
void testGetPropertiesLO() throws Exception {
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
// Open the package
try (OPCPackage pkg1 = OPCPackage.open(openSampleStream("51444.xlsx"))) {
PackageProperties props1 = pkg1.getPackageProperties();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ROOT);
df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (InputStream is = openSampleStream("OPCCompliance_CoreProperties_AlternateTimezones.docx");
OPCPackage pkg1 = OPCPackage.open(is)) {
PackagePropertiesPart props1 = (PackagePropertiesPart) pkg1.getPackageProperties();
// Write out and re-load
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
pkg.save(baos);
// use revert to not re-write the input file
@Test
void testCreateRelationsFromScratch() throws Exception {
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
OPCPackage pkg = OPCPackage.create(baos);
PackagePart partA =
OPCPackage pkg = OPCPackage.open(filepath);
assert_50154(pkg);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
pkg.save(baos);
// use revert to not re-write the input file
@Test
void testSelfRelations_bug51187() throws Exception {
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
PackageRelationship rel1;
try (OPCPackage pkg = OPCPackage.create(baos)) {
assertEquals("mailto:nobody@nowhere.uk%C2%A0", targetUri.toASCIIString());
assertEquals("nobody@nowhere.uk\u00A0", targetUri.getSchemeSpecificPart());
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
pkg1.save(out);
try (OPCPackage pkg2 = OPCPackage.open(out.toInputStream())) {
while ((entree = zis.getNextEntry()) != null) {
/* Create an array for the current entry */
- UnsynchronizedByteArrayOutputStream byteArray = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream byteArray = UnsynchronizedByteArrayOutputStream.builder().get();
IOUtils.copy(zis, byteArray);
zipContent.put(entree.getName(), byteArray);
}
@Test
void testNoCoreProperties_saveNew() throws Exception {
String sampleFileName = "OPCCompliance_NoCoreProperties.xlsx";
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (OPCPackage pkg = OPCPackage.open(getSampleFile(sampleFileName).getPath())) {
// Verify it has empty properties
package org.apache.poi.openxml4j.opc.internal.marshallers;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.poi.openxml4j.opc.PackagingURIHelper.PACKAGE_RELATIONSHIPS_ROOT_URI;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.PackagePartName;
private final PartMarshaller marshaller = new ZipPackagePropertiesMarshaller();
private boolean marshall() throws OpenXML4JException {
- return marshall(new ZipArchiveOutputStream(new UnsynchronizedByteArrayOutputStream()));
+ return marshall(new ZipArchiveOutputStream(UnsynchronizedByteArrayOutputStream.builder().get()));
}
private boolean marshall(OutputStream zos) throws OpenXML4JException {
@Test
void nonZipOutputStream() {
- assertThrows(IllegalArgumentException.class, () -> marshall(NULL_OUTPUT_STREAM));
+ assertThrows(IllegalArgumentException.class, () -> marshall(NullOutputStream.INSTANCE));
}
@Test
@Test
void ioException() {
- ZipArchiveOutputStream zos = new ZipArchiveOutputStream(new UnsynchronizedByteArrayOutputStream()) {
+ ZipArchiveOutputStream zos = new ZipArchiveOutputStream(UnsynchronizedByteArrayOutputStream.builder().get()) {
@Override
public void putArchiveEntry(final ArchiveEntry archiveEntry) throws IOException {
throw new IOException("TestException");
public DummyKeystore(String pfxInput, String storePass) throws GeneralSecurityException, IOException {
CryptoFunctions.registerBouncyCastle();
keystore = KeyStore.getInstance("PKCS12");
- try (InputStream fis = new UnsynchronizedByteArrayInputStream(RawDataUtil.decompress(pfxInput))) {
+ try (InputStream fis = UnsynchronizedByteArrayInputStream.builder().setByteArray(RawDataUtil.decompress(pfxInput)).get()) {
keystore.load(fis, storePass.toCharArray());
}
}
SignatureInfo si = new SignatureInfo();
si.setSignatureConfig(signatureConfig);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(100000);
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(100000).get();
try (XSSFWorkbook wb1 = new XSSFWorkbook()) {
wb1.createSheet().createRow(1).createCell(1).setCellValue("Test");
wb1.write(bos);
void testSignEnvelopingDocument() throws Exception {
String testFile = "hello-world-unsigned.xlsx";
File sigCopy = testdata.getFile(testFile);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(50000);
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(50000).get();
final String execTimestr;
DummyKeystore ks = new DummyKeystore(STORE_PASS);
KeyCertPair certPair = ks.createDummyKey();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (XWPFDocument doc = new XWPFDocument()) {
XWPFHyperlinkRun r = doc.createParagraph().createHyperlinkRun("http://poi.apache.org");
r.setText("Hyperlink");
try (SXSSFWorkbook wb1 = new SXSSFWorkbook((XSSFWorkbook)WorkbookFactory.create(tpl), 10)) {
wb1.setCompressTempFiles(true);
wb1.removeSheetAt(0);
- UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
wb1.write(os);
try (OPCPackage pkg = OPCPackage.open(os.toInputStream())) {
throw e;
}
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (XSSFWorkbook wb = new XSSFWorkbook()) {
wb.createSheet().createRow(0).createCell(0).setCellValue("Test");
wb.write(bos);
throw e;
}
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (XSSFWorkbook wb = new XSSFWorkbook()) {
wb.createSheet().createRow(0).createCell(0).setCellValue("test");
wb.write(bos);
}
// create a small sample workbook for encrypting
- UnsynchronizedByteArrayOutputStream bosOrig = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bosOrig = UnsynchronizedByteArrayOutputStream.builder().get();
try (XSSFWorkbook workbook = new XSSFWorkbook()) {
XSSFSheet sheet = workbook.createSheet();
XSSFRow row = sheet.createRow(0);
os.write(testData);
}
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
fsEnc.writeFilesystem(bos);
bos.close();
Decryptor d = Decryptor.getInstance(info);
d.verifyPassword("pwd123");
- final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(10000);
+ final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(10000).get();
try (final ZipArchiveInputStream zis = new ZipArchiveInputStream(d.getDataStream(fs))) {
int[] sizes = { 3711, 1155, 445, 9376, 450, 588, 1337, 2593, 304, 7910 };
for (int size : sizes) {
==================================================================== */
package org.apache.poi.poifs.crypt.tests;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.poi.poifs.crypt.CryptoFunctions.getMessageDigest;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import javax.crypto.Cipher;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.openxml4j.opc.ContentTypes;
payloadExpected = IOUtils.toByteArray(is);
}
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (POIFSFileSystem fs = new POIFSFileSystem()) {
EncryptionInfo ei = new EncryptionInfo(EncryptionMode.binaryRC4);
Encryptor enc = ei.getEncryptor();
payloadExpected = IOUtils.toByteArray(is);
}
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (POIFSFileSystem fs = new TempFilePOIFSFileSystem()) {
EncryptionInfo ei = new EncryptionInfo(EncryptionMode.agile);
Encryptor enc = ei.getEncryptor();
Encryptor e = Encryptor.getInstance(infoActual);
e.confirmPassword(pass, keySpec, keySalt, verifierExpected, verifierSaltExpected, integritySalt);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (POIFSFileSystem fs = new POIFSFileSystem()) {
try (OutputStream os = e.getDataStream(fs)) {
os.write(payloadExpected);
// now we use a newly generated salt/verifier and check
// if the file content is still the same
- final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(50000);
+ final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(50000).get();
try (POIFSFileSystem fs = new POIFSFileSystem()) {
final EncryptionInfo infoActual2 = new EncryptionInfo(
@Test
void encryptPackageWithoutCoreProperties() throws Exception {
// Open our file without core properties
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (InputStream is = POIDataSamples.getOpenXML4JInstance().openResourceAsStream("OPCCompliance_NoCoreProperties.xlsx");
OPCPackage pkg = OPCPackage.open(is)) {
os.write(zipInput);
}
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
fsNew.writeFilesystem(bos);
try (POIFSFileSystem fsReload = new POIFSFileSystem(bos.toInputStream())) {
try (InputStream is = dec.getDataStream(poifs);
DigestInputStream dis = new DigestInputStream(is, md)) {
- IOUtils.copy(dis, NULL_OUTPUT_STREAM);
+ IOUtils.copy(dis, NullOutputStream.INSTANCE);
}
}
File f = sampleDir.getFile(file);
Biff8EncryptionKey.setCurrentUserPassword(password);
try (POITextExtractor te1 = ExtractorFactory.createExtractor(f);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
Biff8EncryptionKey.setCurrentUserPassword(newPass);
try (POIDocument doc = (POIDocument) te1.getDocument()) {
doc.write(bos);
File f = sampleDir.getFile(file);
Biff8EncryptionKey.setCurrentUserPassword(password);
try (POITextExtractor te1 = ExtractorFactory.createExtractor(f);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
// first remove encryption
Biff8EncryptionKey.setCurrentUserPassword(null);
try (POIDocument doc = (POIDocument) te1.getDocument()) {
@Test
public void changeEncryptionMode() throws IOException {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(10_000);
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(10_000).get();
try (HSSFWorkbook wb = new HSSFWorkbook()) {
wb.createSheet().createRow(1).createCell(1).setCellValue("Test");
@ParameterizedTest
@MethodSource("data")
void embedData(Api api, ObjectMetaData.Application app) throws IOException, ReflectiveOperationException {
- final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(50000);
+ final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(50000).get();
try (SlideShow<?,?> ppt = createSlideShow(api)) {
final PictureData picData = ppt.addPicture(pictureFile, PictureType.EMF);
final Slide<?,?> slide = ppt.createSlide();
ppt1.createSlide().setHidden(true);
ppt1.createSlide();
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
ppt1.write(bos);
try (InputStream is = bos.toInputStream();
}
}
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
ppt1.write(bos);
try (SlideShow<?,?> ppt2 = SlideShowFactory.create(bos.toInputStream())) {
try (POIFSFileSystem scratchFS = new POIFSFileSystem();
POIFSFileSystem ole1FS = new POIFSFileSystem(new ByteArrayInputStream(oleShapes.get(0).getObjectData()))) {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
scratch.writeOut(bos);
scratchFS.createDocument(bos.toInputStream(), Ole10Native.OLE10_NATIVE);
scratchFS.getRoot().setStorageClsid(ClassIDPredefined.OLE_V1_PACKAGE.getClassID());
sh1.setAnchor(new java.awt.Rectangle(50, 50, 100, 200));
sh1.setFillColor(java.awt.Color.red);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
ppt.write(bos);
ppt.close();
final List<Object> strings = new ArrayList<>();
- DummyGraphics2d dgfx = new DummyGraphics2d(new NullPrintStream()) {
+ DummyGraphics2d dgfx = new DummyGraphics2d(NullPrintStream.INSTANCE) {
@Override
public void drawString(AttributedCharacterIterator iterator, float x, float y) {
// For the test file, common sl draws textruns one by one and not mixed
{ 79.58198774450841, 53.20887318960063, 109.13118501448272, 9.40935058567127 },
};
- DummyGraphics2d dgfx = new DummyGraphics2d(new NullPrintStream()) {
+ DummyGraphics2d dgfx = new DummyGraphics2d(NullPrintStream.INSTANCE) {
int idx = 0;
@Override
public void clip(java.awt.Shape s) {
assertNotNull(targetSlide);
assertEquals(2, targetPresentation.getPictureData().size());
- targetPresentation.write(NullOutputStream.NULL_OUTPUT_STREAM);
+ targetPresentation.write(NullOutputStream.INSTANCE);
}
}
final ArrayList<LinearGradientPaint> linearGradients = new ArrayList<>();
final ArrayList<RadialGradientPaint> radialGradients = new ArrayList<>();
- final DummyGraphics2d dgfx = new DummyGraphics2d(new NullPrintStream())
+ final DummyGraphics2d dgfx = new DummyGraphics2d(NullPrintStream.INSTANCE)
{
public void setPaint(final Paint paint) {
if (paint instanceof LinearGradientPaint) {
try (
InputStream stream = slTests.openResourceAsStream("copy-slide-demo.pptx");
XMLSlideShow slideShow = new XMLSlideShow(stream);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
XSLFSlide defaultSlide = getSlideByShapeName(slideShow, shapeName);
int slideIndex = defaultSlide.getSlideNumber() - 1;
}
public static XMLSlideShow writeOutAndReadBack(XMLSlideShow doc) throws IOException {
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(4096)) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(4096).get()) {
doc.write(baos);
try (InputStream bais = baos.toInputStream()) {
return new XMLSlideShow(bais);
void testReplaceTextInShapes() throws IOException {
try (
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
assertEquals(6, ppt.getSlides().size());
XSLFSlide slide0 = ppt.getSlides().get(0);
void testReplaceTextInShapesXDDF() throws IOException {
try (
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
assertEquals(6, ppt.getSlides().size());
XSLFSlide slide0 = ppt.getSlides().get(0);
void testCloneSlideAndReplaceText() throws IOException {
try (
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
assertEquals(6, ppt.getSlides().size());
XSLFSlide slide0 = ppt.getSlides().get(0);
void testCloneSlideAndReplaceTextXDDF() throws IOException {
try (
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
assertEquals(6, ppt.getSlides().size());
XSLFSlide slide0 = ppt.getSlides().get(0);
assertEquals("This is a highlight test", sh.getText());
- DummyGraphics2d dgfx = new DummyGraphics2d(new NullPrintStream()) {
+ DummyGraphics2d dgfx = new DummyGraphics2d(NullPrintStream.INSTANCE) {
@Override
public void drawString(AttributedCharacterIterator iterator, float x, float y) {
// For the test file, common sl draws textruns one by one and not mixed
throw new IllegalArgumentException("Expected an instance of XSSFWorkbook");
}
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(baos);
try (InputStream is = baos.toInputStream()) {
return new XSSFWorkbook(is);
* Returns an XSSFWorkbook since SXSSFWorkbook is write-only
*/
public XSSFWorkbook inMemoryWriteOutAndReadBack(SXSSFWorkbook wb) {
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.writeAvoidingTempFiles(baos);
try (InputStream is = baos.toInputStream()) {
return new XSSFWorkbook(is);
throw new IllegalArgumentException("Expected an instance of SXSSFWorkbook");
}
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(baos);
try (InputStream is = baos.toInputStream()) {
return new XSSFWorkbook(is);
try (
XSSFWorkbook workbook = new XSSFWorkbook();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
XSSFCellStyle cellStyle = workbook.createCellStyle();
final String rgbS = "ffff00";
// not freed until we free up the Cell itself
//verifier.addObject(ctCell);
- try (OutputStream out = new UnsynchronizedByteArrayOutputStream(8192)) {
+ try (OutputStream out = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(8192).get()) {
wb.write(out);
}
* @throws IOException If writing the file fails
*/
public static <R extends Workbook> UnsynchronizedByteArrayOutputStream writeOut(R wb) throws IOException {
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(8192);
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(8192).get();
wb.write(out);
return out;
}
@Test
void testBug65676() throws Exception {
- try (UnsynchronizedByteArrayOutputStream output = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream output = UnsynchronizedByteArrayOutputStream.builder().get()) {
try(Workbook wb = new SXSSFWorkbook()) {
Row r = wb.createSheet("Sheet").createRow(0);
r.createCell(0).setCellValue(1.2); /* A1: Number 1.2 */
XSSFMap map = mapInfo.getXSSFMapById(1);
XSSFExportToXml exporter = new XSSFExportToXml(map);
- UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xml = os.toString(StandardCharsets.UTF_8);
XSSFMap map = mapInfo.getXSSFMapById(1);
XSSFExportToXml exporter = new XSSFExportToXml(map);
- UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xml = os.toString(StandardCharsets.UTF_8);
XSSFExportToXml exporter = new XSSFExportToXml(map);
String xml;
- try (UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get()) {
exporter.exportToXML(os, true);
xml = os.toString(StandardCharsets.UTF_8);
}
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXMLMapping-singleattributenamespace.xlsx")) {
for (XSSFMap map : wb.getCustomXMLMappings()) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
- UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
SAXParseException ex = assertThrows(SAXParseException.class, () -> exporter.exportToXML(os, true));
assertTrue(p.matcher(ex.getMessage()).find(),
"Did not find pattern " + p + " in " + ex.getMessage());
assertNotNull(map, "XSSFMap is null");
XSSFExportToXml exporter = new XSSFExportToXml(map);
- UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xmlData = os.toString(StandardCharsets.UTF_8);
assertNotNull(map, "XSSFMap is null");
XSSFExportToXml exporter = new XSSFExportToXml(map);
- UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xmlData = os.toString(StandardCharsets.UTF_8);
assertNotNull(map, "XSSFMap is null");
XSSFExportToXml exporter = new XSSFExportToXml(map);
- UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xmlData = os.toString(StandardCharsets.UTF_8);
assertNotNull(map, "XSSFMap is null");
XSSFExportToXml exporter = new XSSFExportToXml(map);
- UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xmlData = os.toString(StandardCharsets.UTF_8);
for (XSSFMap map : wb.getCustomXMLMappings()) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
- UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xmlData = os.toString(StandardCharsets.UTF_8);
assertNotNull(map, "XSSFMap is null");
XSSFExportToXml exporter = new XSSFExportToXml(map);
- UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xmlData = os.toString(StandardCharsets.UTF_8);
assertNotNull(map, "XSSFMap is null");
XSSFExportToXml exporter = new XSSFExportToXml(map);
- UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xmlData = os.toString(StandardCharsets.UTF_8);
assertNotNull(map, "XSSFMap is null");
XSSFExportToXml exporter = new XSSFExportToXml(map);
- UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, false);
String xmlData = os.toString(StandardCharsets.UTF_8);
assertNotNull(map, "XSSFMap is null");
XSSFExportToXml exporter = new XSSFExportToXml(map);
- UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, true);
String xmlData = os.toString(StandardCharsets.UTF_8);
for (XSSFMap map : mappings) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
- UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(os, false);
assertNotNull(os.toString(StandardCharsets.UTF_8));
}
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("61281.xlsx")) {
for (XSSFMap map : wb.getCustomXMLMappings()) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
exporter.exportToXML(bos, true);
assertNotNull(DocumentHelper.readDocument(bos.toInputStream()));
String exportedXml = bos.toString(StandardCharsets.UTF_8);
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("xxe_in_schema.xlsx")) {
for (XSSFMap map : wb.getCustomXMLMappings()) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
assertThrows(SAXParseException.class, () -> exporter.exportToXML(bos, true));
}
}
void compareOutput() throws Exception {
Map<String, String> contents = createContents();
try (
- UnsynchronizedByteArrayOutputStream bos1 = new UnsynchronizedByteArrayOutputStream();
- UnsynchronizedByteArrayOutputStream bos2 = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos1 = UnsynchronizedByteArrayOutputStream.builder().get();
+ UnsynchronizedByteArrayOutputStream bos2 = UnsynchronizedByteArrayOutputStream.builder().get()
) {
try (OpcOutputStream zip = new OpcOutputStream(bos1)) {
for (Map.Entry<String, String> entry : contents.entrySet()) {
@Test
void flushBufferedDaat() throws IOException {
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
try (SXSSFWorkbook wb = new SXSSFWorkbook(1)) {
SXSSFSheet sheet = wb.createSheet("my-sheet");
//one level
sheet.groupRow(9, 10);
- try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
workbook.write(bos);
try(XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) {
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
//two level
sheet.groupRow(10, 13);
- try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
workbook.write(bos);
try(XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) {
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
package org.apache.poi.xssf.streaming;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.poi.POITestCase.assertEndsWith;
import static org.apache.poi.POITestCase.assertStartsWith;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import java.time.LocalDate;
import java.util.Arrays;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.common.usermodel.HyperlinkType;
void bug53515() throws Exception {
try (Workbook wb1 = new SXSSFWorkbook(10)) {
populateWorkbook(wb1);
- assertDoesNotThrow(() -> wb1.write(NULL_OUTPUT_STREAM));
- assertDoesNotThrow(() -> wb1.write(NULL_OUTPUT_STREAM));
+ assertDoesNotThrow(() -> wb1.write(NullOutputStream.INSTANCE));
+ assertDoesNotThrow(() -> wb1.write(NullOutputStream.INSTANCE));
try (Workbook wb2 = new XSSFWorkbook()) {
populateWorkbook(wb2);
- assertDoesNotThrow(() -> wb2.write(NULL_OUTPUT_STREAM));
- assertDoesNotThrow(() -> wb2.write(NULL_OUTPUT_STREAM));
+ assertDoesNotThrow(() -> wb2.write(NullOutputStream.INSTANCE));
+ assertDoesNotThrow(() -> wb2.write(NullOutputStream.INSTANCE));
}
}
}
}
}
- assertDoesNotThrow(() -> swb.write(NULL_OUTPUT_STREAM));
+ assertDoesNotThrow(() -> swb.write(NullOutputStream.INSTANCE));
swb.dispose();
}
}
File input = XSSFTestDataSamples.getSampleFile("sample.xlsx");
try (OPCPackage pkg = OPCPackage.open(input, PackageAccess.READ)) {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (XSSFWorkbook xssf = new XSSFWorkbook(pkg)) {
try (SXSSFWorkbook wb = new SXSSFWorkbook(xssf, 2)) {
Sheet s = wb.createSheet(sheetName);
void addHyperlink() throws Exception {
try (
SXSSFWorkbook wb = new SXSSFWorkbook();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
SXSSFSheet sheet = wb.createSheet("s1");
SXSSFRow row = sheet.createRow(0);
void addDimension() throws IOException {
try (
SXSSFWorkbook wb = new SXSSFWorkbook();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
SXSSFSheet sheet = wb.createSheet();
sheet.createRow(2).createCell(3).setCellValue("top left");
void addDimension1() throws IOException {
try (
SXSSFWorkbook wb = new SXSSFWorkbook(1);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
SXSSFSheet sheet = wb.createSheet();
sheet.createRow(2).createCell(3).setCellValue("top left");
assertEquals(6, sheet.getLastRowNum());
try (
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(wb);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
sxssfWorkbook.write(bos);
try (XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) {
void addDimensionDisabled() throws IOException {
try (
SXSSFWorkbook wb = new SXSSFWorkbook();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
wb.setShouldCalculateSheetDimensions(false);
SXSSFSheet sheet = wb.createSheet();
void dateStyle() throws IOException {
try (
SXSSFWorkbook workbook = new SXSSFWorkbook();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
SXSSFSheet sheet = workbook.createSheet();
SXSSFRow row = sheet.createRow(0);
package org.apache.poi.xssf.streaming;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.OutputStream;
import java.util.List;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.OPCPackage;
// write an unencrypted workbook to disk, but any temporary files are encrypted
@Test
void customZipEntrySource() throws IOException {
- UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(8192);
+ UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(8192).get();
try (SXSSFWorkbookWithCustomZipEntrySource workbook = new SXSSFWorkbookWithCustomZipEntrySource()) {
SXSSFSheet sheet1 = workbook.createSheet(sheetName);
SXSSFRow row1 = sheet1.createRow(1);
SXSSFRow row1 = sheet1.createRow(1);
SXSSFCell cell1 = row1.createCell(1);
cell1.setCellValue(cellValue);
- workbook.write(NULL_OUTPUT_STREAM);
+ workbook.write(NullOutputStream.INSTANCE);
workbook.close();
List<File> tempFiles = workbook.getTempFiles();
assertEquals(1, tempFiles.size());
package org.apache.poi.xssf.streaming;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.common.usermodel.HyperlinkType;
import java.io.IOException;
import java.util.Arrays;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.poi.POITestCase.assertEndsWith;
import static org.apache.poi.POITestCase.assertStartsWith;
import static org.junit.jupiter.api.Assertions.*;
void bug53515() throws Exception {
try (Workbook wb1 = new SXSSFWorkbook(10)) {
populateWorkbook(wb1);
- assertDoesNotThrow(() -> wb1.write(NULL_OUTPUT_STREAM));
- assertDoesNotThrow(() -> wb1.write(NULL_OUTPUT_STREAM));
+ assertDoesNotThrow(() -> wb1.write(NullOutputStream.INSTANCE));
+ assertDoesNotThrow(() -> wb1.write(NullOutputStream.INSTANCE));
try (Workbook wb2 = new XSSFWorkbook()) {
populateWorkbook(wb2);
- assertDoesNotThrow(() -> wb2.write(NULL_OUTPUT_STREAM));
- assertDoesNotThrow(() -> wb2.write(NULL_OUTPUT_STREAM));
+ assertDoesNotThrow(() -> wb2.write(NullOutputStream.INSTANCE));
+ assertDoesNotThrow(() -> wb2.write(NullOutputStream.INSTANCE));
}
}
}
}
}
- assertDoesNotThrow(() -> swb.write(NULL_OUTPUT_STREAM));
+ assertDoesNotThrow(() -> swb.write(NullOutputStream.INSTANCE));
swb.dispose();
}
}
File input = XSSFTestDataSamples.getSampleFile("sample.xlsx");
try (OPCPackage pkg = OPCPackage.open(input, PackageAccess.READ)) {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (XSSFWorkbook xssf = new XSSFWorkbook(pkg)) {
try (SXSSFWorkbook wb = new SXSSFWorkbook(xssf, 2)) {
Sheet s = wb.createSheet(sheetName);
void addHyperlink() throws Exception {
try (
SXSSFWorkbook wb = new SXSSFWorkbook();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
SXSSFSheet sheet = wb.createSheet("s1");
SXSSFRow row = sheet.createRow(0);
void addDimension() throws IOException {
try (
SXSSFWorkbook wb = new SXSSFWorkbook();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
SXSSFSheet sheet = wb.createSheet();
sheet.createRow(2).createCell(3).setCellValue("top left");
void addDimension1() throws IOException {
try (
SXSSFWorkbook wb = new SXSSFWorkbook(1);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
SXSSFSheet sheet = wb.createSheet();
sheet.createRow(2).createCell(3).setCellValue("top left");
assertEquals(6, sheet.getLastRowNum());
try (
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(wb);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
sxssfWorkbook.write(bos);
try (XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) {
void addDimensionDisabled() throws IOException {
try (
SXSSFWorkbook wb = new SXSSFWorkbook();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
wb.setShouldCalculateSheetDimensions(false);
SXSSFSheet sheet = wb.createSheet();
@Test
void test65619() throws Exception {
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
try (SXSSFWorkbook workbook = new SXSSFWorkbook(100)) {
SXSSFSheet sheet = workbook.createSheet("Test Sheet 1");
Font font = workbook.createFont();
assertEquals(value, cell.getStringCellValue());
// so far so good
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(bos);
try (XSSFWorkbook testWb = new XSSFWorkbook(bos.toInputStream())) {
assertEquals(blueStyle.getIndex(), r3.getCell(4).getCellStyle().getIndex());
assertEquals(pinkStyle.getIndex(), r3.getCell(6).getCellStyle().getIndex());
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(bos);
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
XSSFSheet wb2Sheet = wb2.getSheetAt(0);
checkRow57423(testSheet, 17, "17");
checkRow57423(testSheet, 18, "18");
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().get();
((XSSFSheet)testSheet).write(stream);
// verify that the resulting XML has the rows in correct order as required by Excel
import static java.time.Duration.between;
import static java.time.Instant.now;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.logging.log4j.util.Unbox.box;
import static org.apache.poi.extractor.ExtractorFactory.OOXML_PACKAGE;
import static org.apache.poi.openxml4j.opc.TestContentType.isOldXercesActive;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Thread.sleep(10);
}
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(8096);
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(8096).get();
wb.write(bos);
byte[] firstSave = bos.toByteArray();
bos.reset();
// we currently only populate the dimension during writing out
// to avoid having to iterate all rows/cells in each add/remove of a row or cell
- wb.write(NULL_OUTPUT_STREAM);
+ wb.write(NullOutputStream.INSTANCE);
assertEquals("B2:H5", ((XSSFSheet) sheet).getCTWorksheet().getDimension().getRef());
}
// we currently only populate the dimension during writing out
// to avoid having to iterate all rows/cells in each add/remove of a row or cell
- wb.write(NULL_OUTPUT_STREAM);
+ wb.write(NullOutputStream.INSTANCE);
assertEquals("B2:XFD5", ((XSSFSheet) sheet).getCTWorksheet().getDimension().getRef());
}
assertEquals(blueStyle.getIndex(), r3.getCell(4).getCellStyle().getIndex());
assertEquals(pinkStyle.getIndex(), r3.getCell(6).getCellStyle().getIndex());
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(bos);
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
XSSFSheet wb2Sheet = wb2.getSheetAt(0);
}
// read bytes of workbook before
- UnsynchronizedByteArrayOutputStream bosOrig = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bosOrig = UnsynchronizedByteArrayOutputStream.builder().get();
try (FileInputStream fis = new FileInputStream(temp_excel_poi)) {
IOUtils.copy(fis, bosOrig);
}
// for the encrypted bytes
- UnsynchronizedByteArrayOutputStream bosEnc = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bosEnc = UnsynchronizedByteArrayOutputStream.builder().get();
/* encrypt excel by poi */
try (POIFSFileSystem fs = new POIFSFileSystem()) {
}
// for the decrytped bytes
- UnsynchronizedByteArrayOutputStream bosDec = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bosDec = UnsynchronizedByteArrayOutputStream.builder().get();
/* decrypt excel by poi */
try (POIFSFileSystem fileSystem = new POIFSFileSystem(temp_excel_poi_encrypt)) {
@Test
void bug59388CommentVisible() throws IOException {
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("59388.xlsx")) {
Sheet sheet = wb.getSheetAt(0);
Cell a1 = sheet.getRow(0).getCell(0);
}
private void _testMoveIsSaved(Workbook workbook) throws Exception {
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
CreationHelper factory = workbook.getCreationHelper();
Sheet sheet = workbook.createSheet();
Row row = sheet.createRow(0);
}
private void _testModificationIsSaved(Workbook workbook) throws Exception {
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
CreationHelper factory = workbook.getCreationHelper();
Sheet sheet = workbook.createSheet();
Row row = sheet.createRow(0);
void saveGroupColumns() throws IOException {
try (
XSSFWorkbook workbook = new XSSFWorkbook();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
XSSFSheet sheet = workbook.createSheet();
XSSFRow row0 = sheet.createRow(0);
void testBug64536() throws IOException {
try (
XSSFWorkbook xssfWorkbook = (XSSFWorkbook) _testDataProvider.openSampleWorkbook("1_NoIden.xlsx");
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
XSSFSheet fileSheet = xssfWorkbook.getSheetAt(0);
assertEquals(CellRangeAddress.valueOf("B1:D9"), fileSheet.getDimension());
void testNamesWithNewLines() throws IOException {
try (
XSSFWorkbook wb = new XSSFWorkbook();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
XSSFSheet sheet = wb.createSheet();
void bug66213() throws IOException {
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("table-sample.xlsx")) {
wb.cloneSheet(0, "Test");
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(bos);
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
XSSFSheet sheet0 = wb2.getSheetAt(0);
void testCloneConditionalFormattingSamples() throws IOException {
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("ConditionalFormattingSamples.xlsx")) {
wb.cloneSheet(0, "Test");
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(bos);
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
XSSFSheet sheet0 = wb2.getSheetAt(0);
void testCloneSingleCellTable() throws IOException {
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("SingleCellTable.xlsx")) {
wb.cloneSheet(0, "Test");
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(bos);
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
XSSFSheet sheet0 = wb2.getSheetAt(0);
assertEquals("[True]", cldata.getVisibleList().toString());
//serialize and read again
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
vml.write(out);
XSSFVMLDrawing vml2 = new XSSFVMLDrawing();
package org.apache.poi.xssf.usermodel;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
import java.util.List;
import java.util.zip.CRC32;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.poi.hssf.HSSFTestDataSamples.openSampleFileStream;
import static org.apache.poi.xssf.XSSFTestDataSamples.openSampleWorkbook;
import static org.apache.poi.xssf.XSSFTestDataSamples.writeOut;
sheet.groupColumn((short) 4, (short) 5);
accessWorkbook(workbook);
- workbook.write(NULL_OUTPUT_STREAM);
+ workbook.write(NullOutputStream.INSTANCE);
accessWorkbook(workbook);
}
}
@Test
void testNewWorkbookWithTempFilePackageParts() throws Exception {
- try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
assertFalse(ZipPackage.useTempFilePackageParts(), "useTempFilePackageParts defaults to false?");
assertFalse(ZipPackage.encryptTempFilePackageParts(), "encryptTempFilePackageParts defaults to false?");
ZipPackage.setUseTempFilePackageParts(true);
@Test
void testNewWorkbookWithEncryptedTempFilePackageParts() throws Exception {
- try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
assertFalse(ZipPackage.useTempFilePackageParts(), "useTempFilePackageParts defaults to false?");
assertFalse(ZipPackage.encryptTempFilePackageParts(), "encryptTempFilePackageParts defaults to false?");
ZipPackage.setUseTempFilePackageParts(true);
String nameA = "link-external-workbook-a.xlsx";
try (
- UnsynchronizedByteArrayOutputStream bosA = new UnsynchronizedByteArrayOutputStream();
- UnsynchronizedByteArrayOutputStream bosB = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bosA = UnsynchronizedByteArrayOutputStream.builder().get();
+ UnsynchronizedByteArrayOutputStream bosB = UnsynchronizedByteArrayOutputStream.builder().get();
XSSFWorkbook workbookA = new XSSFWorkbook();
XSSFWorkbook workbookB = new XSSFWorkbook()
) {
String nameA = "cache-external-workbook-a.xlsx";
try (
- UnsynchronizedByteArrayOutputStream bosA = new UnsynchronizedByteArrayOutputStream();
- UnsynchronizedByteArrayOutputStream bosB = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bosA = UnsynchronizedByteArrayOutputStream.builder().get();
+ UnsynchronizedByteArrayOutputStream bosB = UnsynchronizedByteArrayOutputStream.builder().get();
XSSFWorkbook workbookA = new XSSFWorkbook();
XSSFWorkbook workbookB = new XSSFWorkbook()
) {
@Test
void checkExistingFileForR1C1Refs() throws IOException {
try (
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
XSSFWorkbook wb = openSampleWorkbook("WithTable.xlsx")
) {
assertEquals(CellReferenceType.A1, wb.getCellReferenceType());
@Test
void checkNewFileForR1C1Refs() throws IOException {
try (
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
XSSFWorkbook wb = new XSSFWorkbook()
) {
assertEquals(CellReferenceType.UNKNOWN, wb.getCellReferenceType());
setRoundedCorners(chart, false);
// Write the output to a file
- try (UnsynchronizedByteArrayOutputStream outStream = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream outStream = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(outStream);
try (XSSFWorkbook wb2 = new XSSFWorkbook(outStream.toInputStream())) {
// see if this fails
// overflow or only part in the buffer
for(int i=5; i<orig.length; i++) {
try (EvilUnclosedBRFixingInputStream inp = new EvilUnclosedBRFixingInputStream(orig);
- UnsynchronizedByteArrayOutputStream bout = new UnsynchronizedByteArrayOutputStream()) {
+ UnsynchronizedByteArrayOutputStream bout = UnsynchronizedByteArrayOutputStream.builder().get()) {
for (;;) {
byte[] b = new byte[i];
int r = inp.read(b);
}
public static XWPFDocument writeOutAndReadBack(XWPFDocument doc) throws IOException {
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(4096);
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(4096).get();
doc.write(baos);
return new XWPFDocument(baos.toInputStream());
}
r1.setText("Lorem ipsum dolor sit amet.");
doc.setTrackRevisions(true);
- try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) {
doc.write(out);
try (InputStream inputStream = out.toInputStream()) {
for (AttachmentChunks attachment : msg.getAttachmentFiles()) {
if (attachment.getAttachData() != null) {
byte[] data = attachment.getAttachData().getValue();
- nonPOIFS.add( new UnsynchronizedByteArrayInputStream(data) );
+ try {
+ nonPOIFS.add(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get() );
+ } catch (IOException e) {
+ // is actually impossible with ByteArray, but still declared in the interface
+ throw new IllegalStateException(e);
+ }
} else if (attachment.getAttachmentDirectory() != null) {
dirs.add(attachment.getAttachmentDirectory().getDirectory());
}
* @throws IOException when the InputStream can't be read
*/
public byte[] compress(InputStream src) throws IOException {
- UnsynchronizedByteArrayOutputStream res = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream res = UnsynchronizedByteArrayOutputStream.builder().get();
compress(src,res);
return res.toByteArray();
}
* Decompresses the given data, returning it as header + contents
*/
public static byte[][] decompress(byte[] data, int offset, int length) throws IOException {
- try (UnsynchronizedByteArrayInputStream bais = new UnsynchronizedByteArrayInputStream(data, offset, length)) {
+ try (UnsynchronizedByteArrayInputStream bais = UnsynchronizedByteArrayInputStream.builder().setByteArray(data).setOffset(offset).setLength(length).get()) {
// Decompress
HDGFLZW lzw = new HDGFLZW();
byte[] decompressed = lzw.decompress(bais);
if (!PictureData.PictureType.EMF.contentType.equals(contentType)) {
throw new IOException("Invalid picture type");
}
- image = new HemfPicture(new UnsynchronizedByteArrayInputStream(data));
+ image = new HemfPicture(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get());
}
@Override
return (long)undefinedSpace1 + bitmap.init(leis, dibSize);
}
- final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(cbBmi+cbBits);
+ final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(cbBmi+cbBits).get();
final long cbBmiSrcAct = IOUtils.copy(leis, bos, cbBmi);
assert (cbBmiSrcAct == cbBmi);
leis.skipFully(undefinedSpace2);
public EmfPlusBrushData getBrushData(List<? extends EmfPlusObjectData> continuedObjectData) {
EmfPlusBrushData brushData = brushType.constructor.get();
byte[] buf = getRawData(continuedObjectData);
- try (UnsynchronizedByteArrayInputStream bis = new UnsynchronizedByteArrayInputStream(buf)){
+ try (UnsynchronizedByteArrayInputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(buf).get()){
brushData.init(new LittleEndianInputStream(bis), buf.length);
} catch (IOException e) {
throw new IllegalStateException(e);
* @throws IllegalStateException if the data cannot be processed
*/
public byte[] getRawData(List<? extends EmfPlusObjectData> continuedObjectData) {
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
bos.write(getBrushBytes());
if (continuedObjectData != null) {
for (EmfPlusObjectData od : continuedObjectData) {
if (getBitmapType() == EmfPlusBitmapDataType.PIXEL) {
return new Rectangle2D.Double(0, 0, bitmapWidth, bitmapHeight);
} else {
- try(UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(getRawData(continuedObjectData))) {
+ try(UnsynchronizedByteArrayInputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(getRawData(continuedObjectData)).get()) {
BufferedImage bi = ImageIO.read(is);
return new Rectangle2D.Double(bi.getMinX(), bi.getMinY(), bi.getWidth(), bi.getHeight());
}
}
case METAFILE:
- try(UnsynchronizedByteArrayInputStream bis = new UnsynchronizedByteArrayInputStream(getRawData(continuedObjectData))) {
+ try(UnsynchronizedByteArrayInputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(getRawData(continuedObjectData)).get()) {
switch (getMetafileType()) {
case Wmf:
case WmfPlaceable:
* @throws IllegalStateException if the data cannot be read
*/
public byte[] getRawData(List<? extends EmfPlusObjectData> continuedObjectData) {
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
bos.write(getImageData());
if (continuedObjectData != null) {
for (EmfPlusObjectData od : continuedObjectData) {
private void compressGDIBitmap(EmfPlusImage img, HwmfEmbedded emb, HwmfEmbeddedType et) {
BufferedImage bi = img.readGDIImage(emb.getRawData());
try {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
// use HwmfEmbeddedType literal for conversion
ImageIO.write(bi, et.toString(), bos);
emb.setData(bos.toByteArray());
: epo.getTotalObjectSize();
IOUtils.safelyAllocateCheck(totalSize, MAX_RECORD_LENGTH);
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(totalSize)) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(totalSize).get()) {
boolean hasNext = false;
do {
EmfPlusImage img = epo.getObjectData();
"instead received a " + parent.getProperty() + " one"
);
}
- try(UnsynchronizedByteArrayInputStream inp = new UnsynchronizedByteArrayInputStream(parent.getData())) {
+ try(UnsynchronizedByteArrayInputStream inp = UnsynchronizedByteArrayInputStream.builder().setByteArray(parent.getData()).get()) {
// First up, get the number of attributes
int count = LittleEndian.readInt(inp);
List<MAPIAttribute> attrs = new ArrayList<>();
// Decompress it, removing any trailing padding as needed
CompressedRTF rtf = new CompressedRTF();
byte[] tmp;
- try (InputStream is = new UnsynchronizedByteArrayInputStream(data)) {
+ try (InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get()) {
tmp = rtf.decompress(is);
}
generateData();
// Write out
- try (UnsynchronizedByteArrayInputStream bais = new UnsynchronizedByteArrayInputStream(data)) {
+ try (UnsynchronizedByteArrayInputStream bais = UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get()) {
dir.createDocument(path[path.length-1], bais);
}
}
@Override
public Dimension getImageDimension() {
- try (InputStream is = new UnsynchronizedByteArrayInputStream(getData())){
+ try (InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(getData()).get()){
BufferedImage bi = ImageIO.read(is);
return new Dimension(
(int)Units.pixelToPoints(bi.getWidth()),
header.read(rawdata, CHECKSUM_SIZE);
try (
- InputStream is = new UnsynchronizedByteArrayInputStream(rawdata);
+ InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(rawdata).get();
InflaterInputStream inflater = new InflaterInputStream(is);
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()
) {
long len = IOUtils.skipFully(is,header.getSize() + (long)CHECKSUM_SIZE);
assert(len == header.getSize() + CHECKSUM_SIZE);
public void read(byte[] data, int offset) {
try (
LittleEndianInputStream leis = new LittleEndianInputStream(
- new UnsynchronizedByteArrayInputStream(data, offset, RECORD_LENGTH))
+ UnsynchronizedByteArrayInputStream.builder().setByteArray(data).setOffset(offset).setLength(RECORD_LENGTH).get())
) {
wmfsize = leis.readInt();
}
protected static byte[] compress(byte[] bytes, int offset, int length) {
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
try (DeflaterOutputStream deflater = new DeflaterOutputStream(out)) {
deflater.write(bytes, offset, length);
} catch (IOException ignored) {
@Override
public byte[] getData(){
byte[] rawdata = getRawData();
- try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) {
byte[] macheader = new byte[512];
out.write(macheader);
int pos = CHECKSUM_SIZE*getUIDInstanceCount();
Header header = new Header();
header.read(data, pos);
long bs_exp = (long)pos + header.getSize();
- try (InputStream bis = new UnsynchronizedByteArrayInputStream(data)) {
+ try (InputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get()) {
long bs_act = IOUtils.skipFully(bis, bs_exp);
if (bs_exp != bs_act) {
throw new EOFException();
}
byte[] chunk = new byte[4096];
- try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(header.getWmfSize())) {
+ try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(header.getWmfSize()).get()) {
try (InflaterInputStream inflater = new InflaterInputStream(bis)) {
int count;
while ((count = inflater.read(chunk)) >= 0) {
@Override
public byte[] getData(){
byte[] rawdata = getRawData();
- try (InputStream is = new UnsynchronizedByteArrayInputStream(rawdata)) {
+ try (InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(rawdata).get()) {
Header header = new Header();
assert(skipped == skipLen);
ImageHeaderWMF aldus = new ImageHeaderWMF(header.getBounds());
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
aldus.write(out);
try (InflaterInputStream inflater = new InflaterInputStream( is )) {
return null;
}
try (InputStream is = dn.createDocumentInputStream(entry);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
IOUtils.copy(is, bos);
return bos.toByteArray();
}
}
// Increase the position by the on disk size
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
r.writeOut(baos);
pos += baos.size();
}
public int getDiskLen(org.apache.poi.hslf.record.Record r) throws IOException {
int diskLen = 0;
if (r != null) {
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
r.writeOut(baos);
diskLen = baos.size();
}
return "<<null>>";
}
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
r.writeOut(baos);
byte[] b = baos.toByteArray();
return HexDump.dump(b, 0, 0);
if (optEscher && cname.equals("PPDrawing")) {
DefaultEscherRecordFactory factory = new HSLFEscherRecordFactory();
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
r.writeOut(baos);
byte[] b = baos.toByteArray();
}
// Increase the position by the on disk size
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
r.writeOut(baos);
pos += baos.size();
}
}
// Increase the position by the on disk size
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
r.writeOut(baos);
pos += baos.size();
}
out.append(" bytes that would be written: \n");
try {
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
writeOut(baos);
byte[] b = baos.toByteArray();
out.append(HexDump.dump(b, 0, 0));
byte[] ret = new byte[3];
// Serialise to bytes, then grab the right ones out
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try {
writeLittleEndian(rgb,baos);
} catch(IOException ie) {
*/
public void writeToFS(POIFSFileSystem fs) throws IOException {
// Grab contents
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
writeOut(baos);
try (InputStream is = baos.toInputStream()) {
// Write out
// Write out our children, and stuff them into the Escher layer
// Grab the children's data
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
for (org.apache.poi.hslf.record.Record r : _children) {
r.writeOut(baos);
}
* @param data the embedded data.
*/
public void setData(byte[] data) throws IOException {
- try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
DeflaterOutputStream def = new DeflaterOutputStream(out)) {
//first four bytes is the length of the raw data
byte[] b = new byte[4];
@Override
public byte[] getRemainingData() {
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
for (org.apache.poi.hslf.record.Record r : _childRecords) {
r.writeOut(bos);
}
public void writeOut(OutputStream out) throws IOException {
byte[] bstorehead = new byte[8];
byte[] recordBytes = new byte[36 + 8];
- try (UnsynchronizedByteArrayOutputStream bout = new UnsynchronizedByteArrayOutputStream();
- UnsynchronizedByteArrayOutputStream recordBuf = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bout = UnsynchronizedByteArrayOutputStream.builder().get();
+ UnsynchronizedByteArrayOutputStream recordBuf = UnsynchronizedByteArrayOutputStream.builder().get()) {
for (EscherRecord r : dggContainer) {
if (r.getRecordId() == EscherContainerRecord.BSTORE_CONTAINER) {
EscherContainerRecord bstore = (EscherContainerRecord) r;
*/
public void writeOut(byte headerA, byte headerB, long type, Record[] children, OutputStream out) throws IOException {
// Create a UnsynchronizedByteArrayOutputStream to hold everything in
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
// Write out our header, less the size
baos.write(new byte[]{headerA, headerB});
private void updateRawContents() throws IOException {
if (initialised) {
// Only update the style bytes, if the styles have been potentially changed
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
// First up, we need to serialise the paragraph properties
for (TextPropCollection tpc : paragraphStyles) {
tpc.writeOut(baos);
*/
@Override
public void writeOut(final OutputStream out) throws IOException {
- final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(200);
+ final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(200).get();
final LittleEndianOutputStream lbos = new LittleEndianOutputStream(bos);
int mask = 0;
mask |= writeIf(lbos, numLevels, C_LEVELS);
*/
public void reset(int size){
TextSpecInfoRun sir = new TextSpecInfoRun(size);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try {
sir.writeOut(bos);
} catch (IOException e) {
public void setParentSize(int size) {
assert(size > 0);
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
TextSpecInfoRun[] runs = getTextSpecInfoRuns();
int remaining = size;
int idx = 0;
int type = getTextType();
try {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
LittleEndianOutputStream leos = new LittleEndianOutputStream(bos);
int levels = paragraphStyles.size();
leos.writeShort(levels);
ExOleObjStg exOleObjStg = new ExOleObjStg();
try {
Ole10Native.createOleMarkerEntry(poiData);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
poiData.writeFilesystem(bos);
exOleObjStg.setData(bos.toByteArray());
} catch (IOException e) {
// Write out the Property Streams
writeProperties(outFS, writtenEntries);
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
// For position dependent records, hold where they were and now are
// As we go along, update, and hand over, to any Position Dependent
}
private static InputStream encryptOnePicture(HSLFSlideShowEncrypted encryptedSS, HSLFPictureData data) {
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
data.write(baos);
byte[] pictBytes = baos.toByteArray();
encryptedSS.encryptPicture(pictBytes, 0);
* If an I/O error occurs.
*/
public void writeProperties(DirectoryEntry directory) throws IOException {
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
List<PropertyValue> values = writeProperties(baos);
// write the header data with the properties declaration
final HwmfEmbedded emb = new HwmfEmbedded();
emb.setEmbeddedType(HwmfEmbeddedType.EMF);
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
WmfEscapeEMF img;
do {
final HwmfEscape esc = (HwmfEscape)current;
private static HWPFDocumentCore writeOutAndReadBack(
HWPFDocumentCore original ) {
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
original.write( baos );
try (InputStream is = baos.toInputStream()) {
return loadDoc(is);
*/
if ( matchSignature( rawContent, COMPRESSED1, 32 )
|| matchSignature( rawContent, COMPRESSED2, 32 ) ) {
- try (UnsynchronizedByteArrayInputStream bis = new UnsynchronizedByteArrayInputStream( rawContent, 33, rawContent.length - 33 );
+ try (UnsynchronizedByteArrayInputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(rawContent).
+ setOffset(33).setLength(rawContent.length - 33).get();
InflaterInputStream in = new InflaterInputStream(bis);
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) {
IOUtils.copy(in, out);
content = out.toByteArray();
@Test
void main() {
PrintStream oldStdOut = System.out;
- System.setOut(new NullPrintStream());
+ System.setOut(NullPrintStream.INSTANCE);
try {
File file = POIDataSamples.getDiagramInstance().getFile("Test_Visio-Some_Random_Text.vsd");
String[] args = { file.getAbsolutePath() };
@Test
void testInfiniteLoopOnByteArray() throws Exception {
try (InputStream is = ss_samples.openResourceAsStream("61294.emf")) {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
IOUtils.copy(is, bos);
HemfPicture pic = new HemfPicture(bos.toInputStream());
@Test
void testNoData() throws Exception {
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
// Header
LittleEndian.putInt(HMEFMessage.HEADER_SIGNATURE, out);
@Test
void testInvalidLevel() throws Exception {
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
// Header
LittleEndian.putInt(HMEFMessage.HEADER_SIGNATURE, out);
private static void doMain(String... args) throws Exception {
PrintStream ps = System.out;
try {
- System.setOut(new NullPrintStream());
+ System.setOut(NullPrintStream.INSTANCE);
HMEFDumper.main(args);
} finally {
System.setOut(ps);
POIDataSamples samples = POIDataSamples.getHMEFInstance();
File winmailTNEFFile = samples.getFile("quick-winmail.dat");
HMEFContentsExtractor extractor = new HMEFContentsExtractor(winmailTNEFFile);
- try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) {
extractor.extractMessageBody(out);
assertTrue(out.size() > 0);
byte[] expectedMagic = new byte[]{'{', '\\', 'r', 't', 'f'};
* Useful for verifying that the serialisation round trip
*/
public static HSLFSlideShowImpl writeOutAndReadBack(HSLFSlideShowImpl original) {
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
original.write(baos);
try (InputStream is = baos.toInputStream()) {
return new HSLFSlideShowImpl(is);
* Useful for verifying that the serialisation round trip
*/
public static HSLFSlideShow writeOutAndReadBack(HSLFSlideShow original) {
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(4096)) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(4096).get()) {
original.write(baos);
return new HSLFSlideShow(baos.toInputStream());
} catch (IOException e) {
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(pfs)) {
// Write out to a byte array, and to a temp file
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
hss.write(baos);
final File file = TempFile.createTempFile("TestHSLF", ".ppt");
assertNotNull(pfsC.getRoot().getEntry("Macros"));
// Write out normally, will loose the macro stream
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
hssC.write(baos);
try (POIFSFileSystem pfsNew = new POIFSFileSystem(baos.toInputStream())) {
assertFalse(pfsNew.getRoot().hasEntry("Macros"));
assertDoesNotThrow(ss::getNotes);
// Now write out to a byte array
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
hss.write(baos);
// Use POIFS to query that lot
package org.apache.poi.hslf;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.poi.POITestCase.assertContains;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Map;
import org.apache.commons.io.output.CountingOutputStream;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hslf.record.CurrentUserAtom;
@Test
void testUserEditAtomsRight() throws Exception {
// Write out to a byte array
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
ss.write(baos);
// Create a new one from that
ue.put(0, 0); // Will show 0 if first
int lastUEPos = -1;
- CountingOutputStream cos = new CountingOutputStream(NULL_OUTPUT_STREAM);
+ CountingOutputStream cos = new CountingOutputStream(NullOutputStream.INSTANCE);
for (final Record rec : r) {
int pos = cos.getCount();
if (rec instanceof PersistPtrHolder) {
IOUtils.setByteArrayMaxOverride(5*1024*1024);
// redirect standard out during the test to avoid spamming the console with output
- System.setOut(new NullPrintStream());
+ System.setOut(NullPrintStream.INSTANCE);
}
@AfterEach
@BeforeAll
public static void muteStdErr() {
oldStdErr = System.err;
- System.setErr(new NullPrintStream());
+ System.setErr(NullPrintStream.INSTANCE);
}
@AfterAll
shape.setAutoPlay(false);
assertFalse(shape.isAutoPlay());
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
ppt.write(out);
ppt = new HSLFSlideShow(out.toInputStream());
slide2.addShape(oleShape2);
oleShape2.setAnchor(new Rectangle2D.Double(100,100,100,100));
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
ppt.write(bos);
ppt = new HSLFSlideShow(bos.toInputStream());
@Test
void testWrite() throws Exception {
AnimationInfoAtom record = new AnimationInfoAtom(data, 0, data.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
record.writeOut(baos);
byte[] b = baos.toByteArray();
record.setFlag(AnimationInfoAtom.Play, true);
record.setFlag(AnimationInfoAtom.Synchronous, true);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
record.writeOut(baos);
byte[] b = baos.toByteArray();
@Test
void testWrite() throws Exception {
CString ca = new CString(data_a, 0, data_a.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
ca.writeOut(baos);
byte[] b = baos.toByteArray();
assertArrayEquals(data_a, b);
CString cb = new CString(data_b, 0, data_a.length);
- UnsynchronizedByteArrayOutputStream baosB = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baosB = UnsynchronizedByteArrayOutputStream.builder().get();
cb.writeOut(baosB);
b = baosB.toByteArray();
assertArrayEquals(data_b, b);
}
assertFalse(equals, "Arrays should not be equals");
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
ca.writeOut(baos);
byte[] b = baos.toByteArray();
assertArrayEquals(data_b, b);
@Test
void testWrite() throws Exception {
ColorSchemeAtom csa = new ColorSchemeAtom(data_a,0,data_a.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
csa.writeOut(baos);
byte[] b = baos.toByteArray();
@Test
void testWrite() throws Exception {
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
ca.writeOut(baos);
byte[] b = baos.toByteArray();
assertArrayEquals(data_a, b);
assertFalse(equals, "Arrays should not be equals");
// Check bytes are now the same
- UnsynchronizedByteArrayOutputStream baosa = new UnsynchronizedByteArrayOutputStream();
- UnsynchronizedByteArrayOutputStream baosn = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baosa = UnsynchronizedByteArrayOutputStream.builder().get();
+ UnsynchronizedByteArrayOutputStream baosn = UnsynchronizedByteArrayOutputStream.builder().get();
ca.writeOut(baosa);
cn.writeOut(baosn);
byte[] ba = baosa.toByteArray();
@Test
void testWrite() throws Exception {
Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
ca.writeOut(baos);
byte[] b = baos.toByteArray();
assertArrayEquals(data_a, b);
a.setDate(date_a);
// Check it's now the same as a
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
a.writeOut(baos);
byte[] b = baos.toByteArray();
assertArrayEquals(data_a, b);
ca.setYOffset(0x0E);
// Check bytes are now the same
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
ca.writeOut(baos);
byte[] b = baos.toByteArray();
assertArrayEquals(data_b, b);
cu.setCurrentEditOffset(0x2942);
// Check it matches
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
cu.writeOut(baos);
byte[] out = baos.toByteArray();
@Test
void testWrite() throws Exception {
DocumentAtom da = new DocumentAtom(data_a, 0, data_a.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
da.writeOut(baos);
assertArrayEquals(data_a, baos.toByteArray());
}
EncryptionInfo ei = documentEncryptionAtom.getEncryptionInfo();
ei.getHeader().setKeySize(0x78);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
hss.write(bos);
try (POIFSFileSystem fs2 = new POIFSFileSystem(bos.toInputStream());
void cryptoAPIEncryption() throws Exception {
/* documents with multiple edits need to be normalized for encryption */
String pptFile = "57272_corrupted_usereditatom.ppt";
- UnsynchronizedByteArrayOutputStream encrypted = new UnsynchronizedByteArrayOutputStream();
- UnsynchronizedByteArrayOutputStream expected = new UnsynchronizedByteArrayOutputStream();
- UnsynchronizedByteArrayOutputStream actual = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream encrypted = UnsynchronizedByteArrayOutputStream.builder().get();
+ UnsynchronizedByteArrayOutputStream expected = UnsynchronizedByteArrayOutputStream.builder().get();
+ UnsynchronizedByteArrayOutputStream actual = UnsynchronizedByteArrayOutputStream.builder().get();
try {
try (POIFSFileSystem fs = new POIFSFileSystem(slTests.getFile(pptFile), true);
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(fs)) {
@Test
void testWrite() throws Exception {
ExControl record = new ExControl(data, 0, data.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
record.writeOut(baos);
assertArrayEquals(data, baos.toByteArray());
}
record.setProgId("ShockwaveFlash.ShockwaveFlash.9");
record.setClipboardName("Shockwave Flash Object");
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
record.writeOut(baos);
assertArrayEquals(data, baos.toByteArray());
}
assertEquals(expURL, exHyperlink._getDetailsA());
assertEquals(expURL, exHyperlink._getDetailsB());
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
exHyperlink.writeOut(baos);
assertArrayEquals(exHyperlinkBytes, baos.toByteArray());
}
@Test
void testWrite() throws Exception {
ExHyperlinkAtom eha = new ExHyperlinkAtom(data_a, 0, data_a.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
eha.writeOut(baos);
assertArrayEquals(data_a, baos.toByteArray());
}
eha.setNumber(1);
// Check it's now the same as a
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
eha.writeOut(baos);
assertArrayEquals(data_a, baos.toByteArray());
}
eha.setNumber(4);
// Check bytes are now the same
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
eha.writeOut(baos);
assertArrayEquals(data_b, baos.toByteArray());
}
@Test
void testWrite() throws Exception {
ExMediaAtom record = new ExMediaAtom(data, 0, data.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
record.writeOut(baos);
byte[] b = baos.toByteArray();
record.setFlag(HeadersFootersAtom.fHasTodayDate, false);
record.setFlag(HeadersFootersAtom.fHasFooter, false);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
record.writeOut(baos);
byte[] b = baos.toByteArray();
@Test
void testWrite() throws Exception {
ExObjListAtom eoa = new ExObjListAtom(data_a, 0, data_a.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
eoa.writeOut(baos);
assertArrayEquals(data_a, baos.toByteArray());
}
eoa.setObjectIDSeed(1);
// Check it's now the same as a
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
eoa.writeOut(baos);
assertArrayEquals(data_a, baos.toByteArray());
}
eoa.setObjectIDSeed(4);
// Check bytes are now the same
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
eoa.writeOut(baos);
assertArrayEquals(data_b, baos.toByteArray());
}
@Test
void testWrite() throws Exception {
ExOleObjAtom record = new ExOleObjAtom(data, 0, data.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
record.writeOut(baos);
assertArrayEquals(data, baos.toByteArray());
}
record.setObjStgDataRef(2);
record.setOptions(1283584);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
record.writeOut(baos);
assertArrayEquals(data, baos.toByteArray());
}
@Test
void testWrite() throws Exception {
ExOleObjStg record = new ExOleObjStg(data, 0, data.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
record.writeOut(baos);
byte[] b = baos.toByteArray();
assertEquals(src.getDataLength(), tgt.getDataLength());
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
tgt.writeOut(out);
byte[] b = out.toByteArray();
@Test
void testWrite() throws Exception {
ExVideoContainer record = new ExVideoContainer(data, 0, data.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
record.writeOut(baos);
assertArrayEquals(data, baos.toByteArray());
}
record.getExMediaAtom().setObjectId(1);
record.getPathAtom().setText("D:\\projects\\SchulerAG\\mcom_v_1_0_4\\view\\data\\tests\\images\\cards.mpg");
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
record.writeOut(baos);
assertArrayEquals(data, baos.toByteArray());
}
@Test
void testWrite() throws Exception {
FontCollection fonts = new FontCollection(data, 0, data.length);
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
fonts.writeOut(out);
byte[] recdata = out.toByteArray();
assertArrayEquals(recdata, data);
@Test
void testWrite() throws Exception {
HeadersFootersAtom record = new HeadersFootersAtom(data, 0, data.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
record.writeOut(baos);
assertArrayEquals(data, baos.toByteArray());
}
record.setFlag(HeadersFootersAtom.fHasTodayDate, true);
record.setFlag(HeadersFootersAtom.fHasFooter, true);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
record.writeOut(baos);
assertArrayEquals(data, baos.toByteArray());
}
@Test
void testWriteSlideHeadersFootersContainer() throws Exception {
HeadersFootersContainer record = new HeadersFootersContainer(slideData, 0, slideData.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
record.writeOut(baos);
assertArrayEquals(slideData, baos.toByteArray());
}
assertEquals(HeadersFootersContainer.FOOTERATOM, csFooter.getOptions() >> 4);
csFooter.setText("My Footer - 1");
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
record.writeOut(baos);
assertArrayEquals(slideData, baos.toByteArray());
}
@Test
void testWriteNotesHeadersFootersContainer() throws Exception {
HeadersFootersContainer record = new HeadersFootersContainer(notesData, 0, notesData.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
record.writeOut(baos);
assertArrayEquals(notesData, baos.toByteArray());
}
assertEquals(HeadersFootersContainer.FOOTERATOM, csFooter.getOptions() >> 4);
csFooter.setText("Note Footer");
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
record.writeOut(baos);
assertArrayEquals(notesData, baos.toByteArray());
}
@Test
void testWrite() throws Exception {
InteractiveInfo ii = new InteractiveInfo(data_a, 0, data_a.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
ii.writeOut(baos);
assertArrayEquals(data_a, baos.toByteArray());
}
ia.setHyperlinkType((byte)8);
// Check it's now the same as a
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
ii.writeOut(baos);
assertArrayEquals(data_a, baos.toByteArray());
}
@Test
void testWrite() throws Exception {
InteractiveInfoAtom ia = new InteractiveInfoAtom(data_a, 0, data_a.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
ia.writeOut(baos);
assertArrayEquals(data_a, baos.toByteArray());
}
ia.setHyperlinkType((byte)8);
// Check it's now the same as a
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
ia.writeOut(baos);
assertArrayEquals(data_a, baos.toByteArray());
}
ia.setHyperlinkID(4);
// Check bytes are now the same
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
ia.writeOut(baos);
assertArrayEquals(data_b, baos.toByteArray());
}
@Test
void testWrite() throws Exception {
NotesAtom na = new NotesAtom(data_a, 0, data_a.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
na.writeOut(baos);
assertArrayEquals(data_a, baos.toByteArray());
}
@Test
void testWrite() throws IOException {
SlideAtom sa = new SlideAtom(data_a, 0, data_a.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
sa.writeOut(baos);
assertArrayEquals(data_a, baos.toByteArray());
}
@Test
void testWrite() throws Exception {
SlidePersistAtom spa = new SlidePersistAtom(data_a, 0, data_a.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
spa.writeOut(baos);
assertArrayEquals(data_a, baos.toByteArray());
}
tpc.setValue(0xFE0033FF);
// Should now be the same as data_a
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
stpa.writeOut(baos);
assertArrayEquals(data_a, baos.toByteArray());
}
assertEquals(tpa.getValue(), tpb.getValue());
}
- UnsynchronizedByteArrayOutputStream ba = new UnsynchronizedByteArrayOutputStream();
- UnsynchronizedByteArrayOutputStream bb = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream ba = UnsynchronizedByteArrayOutputStream.builder().get();
+ UnsynchronizedByteArrayOutputStream bb = UnsynchronizedByteArrayOutputStream.builder().get();
ca.writeOut(ba);
cb.writeOut(bb);
}
// Check byte level with b
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
stpa.writeOut(baos);
assertArrayEquals(data_b, baos.toByteArray());
}
StyleTextPropAtom stpb = new StyleTextPropAtom(data, 0,data.length);
if(textlen != -1) stpb.setParentTextSize(textlen);
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
stpb.writeOut(out);
assertArrayEquals(expected, out.toByteArray());
}
TextBytesAtom tba = new TextBytesAtom(data,0,data.length);
tba.setText(alt_text.getBytes(StandardCharsets.ISO_8859_1));
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
tba.writeOut(baos);
assertArrayEquals(alt_data, baos.toByteArray());
}
@Test
void testWrite() throws Exception {
TextBytesAtom tba = new TextBytesAtom(data,0,data.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
tba.writeOut(baos);
assertArrayEquals(data, baos.toByteArray());
}
TextCharsAtom tca = new TextCharsAtom(data,0,data.length);
tca.setText(alt_text);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
tca.writeOut(baos);
assertArrayEquals(alt_data, baos.toByteArray());
}
@Test
void testWrite() throws Exception {
TextCharsAtom tca = new TextCharsAtom(data,0,data.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
tca.writeOut(baos);
assertArrayEquals(data, baos.toByteArray());
}
assertEquals(data_text, tca.getText());
// Check it's now like data
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
tca.writeOut(baos);
assertArrayEquals(data, baos.toByteArray());
}
@Test
void testWrite() throws Exception {
TextHeaderAtom tha = new TextHeaderAtom(notes_data,0,12);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
tha.writeOut(baos);
assertArrayEquals(notes_data, baos.toByteArray());
}
@Test
void testWriteRuler() throws Exception {
TextRulerAtom ruler = new TextRulerAtom(data_1, 0, data_1.length);
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
ruler.writeOut(out);
byte[] result = out.toByteArray();
void testRead2() throws Exception {
TextRulerAtom ruler = TextRulerAtom.getParagraphInstance();
ruler.setParagraphIndent((short)249, (short)321);
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
ruler.writeOut(out);
byte[] result = out.toByteArray();
@Test
void testWrite() throws Exception {
TextSpecInfoAtom spec = new TextSpecInfoAtom(data_1, 0, data_1.length);
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
spec.writeOut(out);
assertArrayEquals(data_1, out.toByteArray());
}
assertEquals(32, run[0].getLength());
//serialize and read again
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
spec.writeOut(out);
byte[] result = out.toByteArray();
@Test
void testWrite() throws Exception {
TxInteractiveInfoAtom atom = new TxInteractiveInfoAtom(data_a, 0, data_a.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
atom.writeOut(baos);
assertArrayEquals(data_a, baos.toByteArray());
}
ia.setEndIndex(56);
// Check it's now the same as a
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
ia.writeOut(baos);
assertArrayEquals(data_a, baos.toByteArray());
}
ia.setEndIndex(78);
// Check bytes are now the same
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
ia.writeOut(baos);
assertArrayEquals(data_b, baos.toByteArray());
}
@Test
void testWrite() throws Exception {
UserEditAtom uea = new UserEditAtom(data_a, 0, data_a.length);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
uea.writeOut(baos);
assertArrayEquals(data_a, baos.toByteArray());
}
@Override
public HSLFSlideShow reopen(SlideShow<HSLFShape, HSLFTextParagraph> show) throws IOException {
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
show.write(bos);
try (InputStream is = bos.toInputStream()) {
return new HSLFSlideShow(is);
package org.apache.poi.hslf.usermodel;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.poi.hslf.HSLFTestDataSamples.getSlideShow;
import static org.apache.poi.hslf.HSLFTestDataSamples.writeOutAndReadBack;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import javax.imageio.ImageIO;
import org.apache.commons.io.output.CountingOutputStream;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.ddf.EscherContainerRecord;
assertEquals(PictureType.WMF, pdata.getType());
//add a new picture, it should be correctly appended to the Pictures stream
- CountingOutputStream out = new CountingOutputStream(NULL_OUTPUT_STREAM);
+ CountingOutputStream out = new CountingOutputStream(NullOutputStream.INSTANCE);
for (HSLFPictureData p : pictures) p.write(out);
int streamSize = out.getCount();
// Now write out the slideshow
byte[] raw_ss;
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
s.write(baos);
try (POIFSFileSystem fs = new POIFSFileSystem(baos.toInputStream());
InputStream is = fs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT)) {
}
private byte[] writeRecord( org.apache.poi.hslf.record.Record r) throws IOException {
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
r.writeOut(baos);
return baos.toByteArray();
}
testFixedAndVariableLengthPropertiesOfAttachedMSG(attachedMsg);
// rebuild top level message from embedded message
try (POIFSFileSystem extractedAttachedMsg = rebuildFromAttached(attachedMsg)) {
- try (UnsynchronizedByteArrayOutputStream extractedAttachedMsgOut = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream extractedAttachedMsgOut = UnsynchronizedByteArrayOutputStream.builder().get()) {
extractedAttachedMsg.writeFilesystem(extractedAttachedMsgOut);
MAPIMessage extractedMsgTopLevel = new MAPIMessage(extractedAttachedMsgOut.toInputStream());
// test properties of rebuilt embedded message
MAPIType type = Types.getById(iType);
if (type != null && type != Types.UNKNOWN) {
MAPIProperty mprop = MAPIProperty.createCustom(chunk.getChunkId(), type, chunk.getEntryName());
- UnsynchronizedByteArrayOutputStream data = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream data = UnsynchronizedByteArrayOutputStream.builder().get();
chunk.writeValue(data);
PropertyValue pval = new PropertyValue(mprop, MessagePropertiesChunk.PROPERTIES_FLAG_READABLE
| MessagePropertiesChunk.PROPERTIES_FLAG_WRITEABLE, data.toByteArray(), type);
assertEquals("test-unicode.doc", attachment.getAttachLongFileName().getValue());
assertEquals(".doc", attachment.getAttachExtension().getValue());
assertNull(attachment.getAttachMimeTag());
- UnsynchronizedByteArrayOutputStream attachmentstream = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream attachmentstream = UnsynchronizedByteArrayOutputStream.builder().get();
attachment.getAttachData().writeValue(attachmentstream);
assertEquals(24064, attachmentstream.size());
// or compare the hashes of the attachment data
@Test
void testReadMessageDateSucceedsWithHSMFDump() {
HSMFDump dump = new HSMFDump(fsMessageSucceeds);
- assertDoesNotThrow(() -> dump.dump(new NullPrintStream()));
+ assertDoesNotThrow(() -> dump.dump(NullPrintStream.INSTANCE));
}
/**
@Test
void testReadMessageDateFailsWithHSMFDump() {
HSMFDump dump = new HSMFDump(fsMessageFails);
- assertDoesNotThrow(() -> dump.dump(new NullPrintStream()));
+ assertDoesNotThrow(() -> dump.dump(NullPrintStream.INSTANCE));
}
/**
}
public HWPFDocument writeOutAndRead(HWPFDocument doc) {
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
doc.write(baos);
try (InputStream is = baos.toInputStream()) {
return new HWPFDocument(is);
* Useful for verifying that the serialisation round trip
*/
public static HWPFDocument writeOutAndReadBack(HWPFDocument original) {
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(4096)) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(4096).get()) {
original.write(baos);
return new HWPFDocument(baos.toInputStream());
} catch (IOException e) {
String fileArgs = SAMPLES.getFile("SampleDoc.doc").getAbsolutePath() + args;
PrintStream oldStdOut = System.out;
- System.setOut(new NullPrintStream());
+ System.setOut(NullPrintStream.INSTANCE);
try {
assertDoesNotThrow(() -> HWPFLister.main(fileArgs.split(" ")));
*/
@Test
void testWriteStream() throws IOException {
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (HWPFDocument doc = HWPFTestDataSamples.openSampleFile("SampleDoc.doc")) {
Range r = doc.getRange();
assertEquals("I am a test document\r", r.getParagraph(0).text());
* {@link POIFSFileSystem} occurs
*/
private void writePropertySet(String name, PropertySet set, POIFSFileSystem outFS) throws IOException {
- try (UnsynchronizedByteArrayOutputStream bOut = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bOut = UnsynchronizedByteArrayOutputStream.builder().get()) {
PropertySet mSet = new PropertySet(set);
mSet.write(bOut);
* @return the inflated picture data.
*/
private static byte[] inflatePictureData(byte[] data) {
- try (InflaterInputStream in = new InflaterInputStream(new UnsynchronizedByteArrayInputStream(data));
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
+ try (InflaterInputStream in = new InflaterInputStream(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get());
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get()) {
IOUtils.copy(in, out);
return out.toByteArray();
} catch (IOException e) {
// "... LZ compression algorithm in the format used by GNU Zip deflate/inflate with a 32k window ..."
// not sure what to do, when lookup tables exceed 32k ...
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
try (DeflaterOutputStream dos = new DeflaterOutputStream(bos)) {
dos.write(pictureData);
}
/* Variable length: */
if (type == Variant.VT_LPSTR || type == Variant.VT_LPWSTR) {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try {
length = write(bos, property) - 2*LittleEndianConsts.INT_SIZE;
/* Pad to multiples of 4. */
if (value instanceof String) {
b.append((String)value);
b.append("\n");
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try {
write(bos, codepage);
} catch (Exception e) {
}
private byte[] toBytes() throws WritingNotSupportedException, IOException {
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
LittleEndianOutputStream leos = new LittleEndianOutputStream(bos)) {
/* Write the number of sections in this property set stream. */
* @throws IOException if an I/O exception occurs.
*/
public InputStream toInputStream() throws WritingNotSupportedException, IOException {
- return new UnsynchronizedByteArrayInputStream(toBytes());
+ return UnsynchronizedByteArrayInputStream.builder().setByteArray(toBytes()).get();
}
/**
* established when the section's size is calculated and can be reused
* later. If the array is empty, the section was modified and the bytes need to be regenerated.
*/
- private final UnsynchronizedByteArrayOutputStream sectionBytes = new UnsynchronizedByteArrayOutputStream();
+ private final UnsynchronizedByteArrayOutputStream sectionBytes = UnsynchronizedByteArrayOutputStream.builder().get();
/**
* The offset of the section in the stream.
}
final int[][] offsets = new int[properties.size()][2];
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
LittleEndianOutputStream leos = new LittleEndianOutputStream(bos)) {
/* Write the section's length - dummy value, fixed later */
*/
package org.apache.poi.hssf.record;
+import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
}
private static RecordInputStream bytesToRIStream(byte[] data) {
- RecordInputStream ric = new RecordInputStream(new UnsynchronizedByteArrayInputStream(data));
+ RecordInputStream ric = null;
+ try {
+ ric = new RecordInputStream(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get());
+ } catch (IOException e) {
+ // not possible with ByteArray but still declared in the API
+ throw new IllegalStateException(e);
+ }
ric.nextRecord();
return ric;
}
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
+import java.io.IOException;
import java.util.Map;
import java.util.function.Supplier;
private static RecordInputStream convertToInputStream(DrawingRecord r)
{
byte[] data = r.serialize();
- RecordInputStream rinp = new RecordInputStream(
- new UnsynchronizedByteArrayInputStream(data)
- );
+ RecordInputStream rinp = null;
+ try {
+ rinp = new RecordInputStream(
+ UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get()
+ );
+ } catch (IOException e) {
+ // not possible with ByteArray but still declared in the API
+ throw new IllegalStateException(e);
+ }
rinp.nextRecord();
return rinp;
}
private static Ptg readRefPtg(byte[] formulaRawBytes) {
try (LittleEndianInputStream in = new LittleEndianInputStream(
- new UnsynchronizedByteArrayInputStream(formulaRawBytes))) {
+ UnsynchronizedByteArrayInputStream.builder().setByteArray(formulaRawBytes).get())) {
byte ptgSid = in.readByte();
switch(ptgSid) {
case AreaPtg.sid: return new AreaPtg(in);
private static class ShapeCollector extends DefaultEscherRecordFactory {
final List<EscherRecord> objShapes = new ArrayList<>();
- final UnsynchronizedByteArrayOutputStream buffer = new UnsynchronizedByteArrayOutputStream();
+ final UnsynchronizedByteArrayOutputStream buffer = UnsynchronizedByteArrayOutputStream.builder().get();
void addBytes(byte[] data) {
try {
@Override
protected int getDataSize() {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
LittleEndianOutputStream leos = new LittleEndianOutputStream(bos);
serialize(leos);
return bos.size();
package org.apache.poi.hssf.record;
+import java.io.IOException;
+
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
import org.apache.poi.common.Duplicatable;
import org.apache.poi.common.usermodel.GenericRecord;
// Do it via a re-serialization
// It's a cheat, but it works...
byte[] b = serialize();
- RecordInputStream rinp = new RecordInputStream(new UnsynchronizedByteArrayInputStream(b));
+ RecordInputStream rinp = null;
+ try {
+ rinp = new RecordInputStream(UnsynchronizedByteArrayInputStream.builder().setByteArray(b).get());
+ } catch (IOException e) {
+ // not possible with ByteArray but still declared in the API
+ throw new IllegalStateException(e);
+ }
rinp.nextRecord();
Record[] r = RecordFactory.createRecord(rinp);
*/
@Deprecated
public byte[] readAllContinuedRemainder() {
- try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(2 * MAX_RECORD_DATA_SIZE)) {
+ try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(2 * MAX_RECORD_DATA_SIZE).get()) {
while (true) {
byte[] b = readRemainder();
protected abstract int getDataSize();
public byte[] serialize() {
int size = getDataSize() + 4;
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(size);
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(size).get();
serialize(new LittleEndianOutputStream(baos));
if (baos.size() != size) {
throw new IllegalStateException("write size mismatch");
package org.apache.poi.hssf.usermodel;
import java.awt.Dimension;
+import java.io.IOException;
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
import org.apache.poi.ddf.DefaultEscherRecordFactory;
EscherBSERecord bse = iwb.getBSERecord(getPictureIndex());
byte[] data = bse.getBlipRecord().getPicturedata();
int type = bse.getBlipTypeWin32();
- return ImageUtils.getImageDimension(new UnsynchronizedByteArrayInputStream(data), type);
+ try {
+ return ImageUtils.getImageDimension(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get(), type);
+ } catch (IOException e) {
+ // not possible with ByteArray but still declared in the API
+ throw new IllegalStateException(e);
+ }
}
/**
DocumentNode workbookNode = (DocumentNode) dir.getEntry(
getWorkbookDirEntryName(dir));
POIFSDocument workbookDoc = new POIFSDocument(workbookNode);
- workbookDoc.replaceContents(new UnsynchronizedByteArrayInputStream(getBytes()));
+ workbookDoc.replaceContents(UnsynchronizedByteArrayInputStream.builder().setByteArray(getBytes()).get());
// Update the properties streams in the file
writeProperties();
List<String> excepts = new ArrayList<>(1);
// Write out the Workbook stream
- fs.createDocument(new UnsynchronizedByteArrayInputStream(getBytes()), "Workbook");
+ fs.createDocument(UnsynchronizedByteArrayInputStream.builder().setByteArray(getBytes()).get(), "Workbook");
// Write out our HPFS properties, if we have them
writeProperties(fs, excepts);
}
}
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
poiData.writeFilesystem(bos);
return addOlePackage(bos.toByteArray(), label, fileName, command);
}
Ole10Native.createOleMarkerEntry(oleDir);
Ole10Native oleNative = new Ole10Native(label, fileName, command, oleData);
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
oleNative.writeOut(bos);
oleDir.createDocument(Ole10Native.OLE10_NATIVE, bos.toInputStream());
}
/** our buffer, when null we're into normal blocks */
private UnsynchronizedByteArrayOutputStream _buffer =
- new UnsynchronizedByteArrayOutputStream(POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE);
+ UnsynchronizedByteArrayOutputStream.builder().setBufferSize(POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE).get();
/** our main block stream, when we're into normal blocks */
private POIFSStream _stream;
}
// Have an empty one created for now
- return parent.createDocument(name, new UnsynchronizedByteArrayInputStream(new byte[0]));
+ return parent.createDocument(name, UnsynchronizedByteArrayInputStream.builder().setByteArray(new byte[0]).get());
}
private void checkBufferSize() throws IOException {
*/
public static void createOleMarkerEntry(final DirectoryEntry parent) throws IOException {
if (!parent.hasEntry(OLE_MARKER_NAME)) {
- parent.createDocument(OLE_MARKER_NAME, new UnsynchronizedByteArrayInputStream(OLE_MARKER_BYTES));
+ parent.createDocument(OLE_MARKER_NAME, UnsynchronizedByteArrayInputStream.builder().setByteArray(OLE_MARKER_BYTES).get());
}
}
switch (mode) {
case parsed: {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (LittleEndianOutputStream leos = new LittleEndianOutputStream(bos)) {
// total size, will be determined later ..
// _header.setPropertyStart has been updated on write ...
// HeaderBlock
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(
_header.getBigBlockSize().getBigBlockSize()
- );
+ ).get();
_header.writeData(baos);
getBlockAt(-1).put(baos.toByteArray());
} else {
// Decompress a previously found module and store the decompressed result into module.buf
InputStream stream = new RLEDecompressingInputStream(
- new UnsynchronizedByteArrayInputStream(module.buf, moduleOffset, module.buf.length - moduleOffset)
+ UnsynchronizedByteArrayInputStream.builder().
+ setByteArray(module.buf).
+ setOffset(moduleOffset).
+ setLength(module.buf.length - moduleOffset).
+ get()
);
module.read(stream);
stream.close();
}
if (decompressedBytes != null) {
- module.read(new UnsynchronizedByteArrayInputStream(decompressedBytes));
+ module.read(UnsynchronizedByteArrayInputStream.builder().setByteArray(decompressedBytes).get());
}
}
private static String readUnicode(InputStream is) throws IOException {
//reads null-terminated unicode string
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
int b0 = IOUtils.readByte(is);
int b1 = IOUtils.readByte(is);
}
private static String readMBCS(int firstByte, InputStream is, Charset charset) throws IOException {
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
int len = 0;
int b = firstByte;
while (b > 0 && len < MAX_STRING_LENGTH) {
if (w <= 0 || (w & 0x7000) != 0x3000) {
continue;
}
- decompressed = tryToDecompress(new UnsynchronizedByteArrayInputStream(compressed, i, compressed.length - i));
+ decompressed = tryToDecompress(UnsynchronizedByteArrayInputStream.builder().
+ setByteArray(compressed).
+ setOffset(i).
+ setLength(compressed.length - i).
+ get());
if (decompressed != null) {
if (decompressed.length > 9) {
//this is a complete hack. The challenge is that there
public void loadImage(InputStream data, String contentType) throws IOException {
InputStream in = data;
if (doCache) {
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
IOUtils.copy(data, bos);
cachedImage = bos.toByteArray();
cachedContentType = contentType;
cachedImage = data.clone();
cachedContentType = contentType;
}
- img = readImage(new UnsynchronizedByteArrayInputStream(data), contentType);
+ img = readImage(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get(), contentType);
}
/**
public ImageHeaderBitmap(byte[] data, int offset) {
BufferedImage img = null;
try {
- img = ImageIO.read(new UnsynchronizedByteArrayInputStream(data, offset, data.length-offset));
+ img = ImageIO.read(UnsynchronizedByteArrayInputStream.builder().setByteArray(data).setOffset(offset).setLength(data.length-offset).get());
} catch (IOException e) {
LOG.atWarn().withThrowable(e).log("Can't determine image dimensions");
}
final Application app = Application.lookup(progId);
- try (final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ try (final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
final InputStream is = FileMagic.prepareToCheckMagic(readObjectDataRaw())) {
final FileMagic fm = FileMagic.valueOf(is);
protected EmbeddedData extract(DirectoryNode dn) throws IOException {
assert(canExtract(dn));
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(20000);
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(20000).get();
POIFSFileSystem dest = new POIFSFileSystem()) {
copyNodes(dn, dest.getRoot());
// start with a reasonable big size
@Override
public EmbeddedData extract(DirectoryNode dn) throws IOException {
- try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ try(UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
InputStream is = dn.createDocumentInputStream("CONTENTS")) {
IOUtils.copy(is, bos);
return new EmbeddedData(dn.getName() + ".pdf", bos.toByteArray(), CONTENT_TYPE_PDF);
* @param scaleY the amount by which image height is multiplied relative to the original height.
* @return the new Dimensions of the scaled picture in EMUs
* @throws IllegalArgumentException if scale values lead to negative or infinite results
+ * @throws IllegalStateException if the picture data is corrupt
*/
public static Dimension setPreferredSize(Picture picture, double scaleX, double scaleY) {
ClientAnchor anchor = picture.getClientAnchor();
Sheet sheet = picture.getSheet();
// in pixel
- final Dimension imgSize = (scaleX == Double.MAX_VALUE || scaleY == Double.MAX_VALUE)
- ? getImageDimension(new UnsynchronizedByteArrayInputStream(data.getData()), data.getPictureType())
- : new Dimension();
+ final Dimension imgSize;
+ try {
+ imgSize = (scaleX == Double.MAX_VALUE || scaleY == Double.MAX_VALUE)
+ ? getImageDimension(UnsynchronizedByteArrayInputStream.builder().setByteArray(data.getData()).get(), data.getPictureType())
+ : new Dimension();
+ } catch (IOException e) {
+ // is actually impossible with ByteArray, but still declared in the interface
+ throw new IllegalStateException(e);
+ }
// in emus
final Dimension anchorSize = (scaleX != Double.MAX_VALUE || scaleY != Double.MAX_VALUE)
Dimension imgSize = null;
if (anchor.getCol2() < anchor.getCol1() || anchor.getRow2() < anchor.getRow1()) {
PictureData data = picture.getPictureData();
- imgSize = getImageDimension(new UnsynchronizedByteArrayInputStream(data.getData()), data.getPictureType());
+ try {
+ imgSize = getImageDimension(UnsynchronizedByteArrayInputStream.builder().setByteArray(data.getData()).get(), data.getPictureType());
+ } catch (IOException e) {
+ // not possible with ByteArray but still declared in the API
+ throw new IllegalStateException(e);
+ }
}
int w = getDimFromCell(imgSize == null ? 0 : imgSize.getWidth(), anchor.getCol1(), anchor.getDx1(), anchor.getCol2(), anchor.getDx2(),
package org.apache.poi.util;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
-
import java.awt.Color;
import java.awt.geom.AffineTransform;
import java.awt.geom.Dimension2D;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.poi.common.usermodel.GenericRecord;
import org.apache.poi.util.GenericRecordUtil.AnnotatedFlag;
protected int childIndex = 0;
public GenericRecordJsonWriter(File fileName) throws IOException {
- OutputStream os = ("null".equals(fileName.getName())) ? NULL_OUTPUT_STREAM : new FileOutputStream(fileName);
+ OutputStream os = ("null".equals(fileName.getName())) ? NullOutputStream.INSTANCE : new FileOutputStream(fileName);
aw = new AppendableWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));
fw = new PrintWriter(aw);
}
package org.apache.poi.util;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
-
import java.awt.Color;
import java.awt.geom.AffineTransform;
import java.awt.geom.Dimension2D;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.poi.common.usermodel.GenericRecord;
import org.apache.poi.util.GenericRecordJsonWriter.AppendableWriter;
private boolean attributePhase = true;
public GenericRecordXmlWriter(File fileName) throws IOException {
- OutputStream os = ("null".equals(fileName.getName())) ? NULL_OUTPUT_STREAM : new FileOutputStream(fileName);
+ OutputStream os = ("null".equals(fileName.getName())) ? NullOutputStream.INSTANCE : new FileOutputStream(fileName);
fw = new PrintWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));
}
checkByteSizeLimit(limit);
stream.mark(limit);
- try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(limit)) {
+ try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(limit).get()) {
copy(new BoundedInputStream(stream, limit), bos);
int readBytes = bos.size();
final int derivedLen = isLengthKnown ? Math.min(length, derivedMaxLength) : derivedMaxLength;
final int byteArrayInitLen = calculateByteArrayInitLength(isLengthKnown, length, derivedMaxLength);
final int internalBufferLen = DEFAULT_BUFFER_SIZE;
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(byteArrayInitLen)) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(byteArrayInitLen).get()) {
byte[] buffer = new byte[internalBufferLen];
int totalBytes = 0, readBytes;
do {
* of the decompressed input.
*/
public byte[] decompress(InputStream src) throws IOException {
- UnsynchronizedByteArrayOutputStream res = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream res = UnsynchronizedByteArrayOutputStream.builder().get();
decompress(src, res);
return res.toByteArray();
}
}
public static byte[] decompress(byte[] compressed, int offset, int length) throws IOException {
- try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
- InputStream instream = new UnsynchronizedByteArrayInputStream(compressed, offset, length);
+ try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
+ InputStream instream = UnsynchronizedByteArrayInputStream.builder().setByteArray(compressed).setOffset(offset).setLength(length).get();
InputStream stream = new RLEDecompressingInputStream(instream)) {
IOUtils.copy(stream, out);
*/
public byte[] readFile(String fileName) {
try (InputStream fis = openResourceAsStream(fileName);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
IOUtils.copy(fis, bos);
return bos.toByteArray();
} catch (IOException e) {
}
public static POIFSFileSystem writeOutAndReadBack(POIFSFileSystem original) throws IOException {
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
original.writeFilesystem(baos);
return new POIFSFileSystem(baos.toInputStream());
}
@Test
void WriteReadProperties() throws IOException {
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
// Write them out
try (POIDocument xls = openSampleWorkbook("DateFormats.xls");
"eJr+iZEHAAA=";
private final EscherDump dumper = new EscherDump();
- private final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ private final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
private PrintStream stream;
@BeforeEach
// Write out and read back, should still be valid
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (POIDocument doc = new HPSFPropertiesOnlyDocument(fs)) {
doc.write(baos);
}
dsi.write(poifs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
si.write(poifs.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME);
- UnsynchronizedByteArrayOutputStream bout = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bout = UnsynchronizedByteArrayOutputStream.builder().get();
poifs.writeFilesystem(bout);
poifs.close();
/* Create a new POI filesystem containing the origin file's
* property set streams: */
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (POIFSFileSystem poiFs = new POIFSFileSystem()) {
for (POIFile poifile : Util.readPropertySets(file)) {
final InputStream in = new ByteArrayInputStream(poifile.getBytes());
/* Write it to a POIFS and the latter to disk: */
try (OutputStream out = new FileOutputStream(filename);
POIFSFileSystem poiFs = new POIFSFileSystem();
- UnsynchronizedByteArrayOutputStream psStream = new UnsynchronizedByteArrayOutputStream()) {
+ UnsynchronizedByteArrayOutputStream psStream = UnsynchronizedByteArrayOutputStream.builder().get()) {
assertThrows(NoFormatIDException.class, () -> ps.write(psStream));
poiFs.createDocument(psStream.toInputStream(), SummaryInformation.DEFAULT_STREAM_NAME);
poiFs.writeFilesystem(out);
/* Create a mutable property set and write it to a POIFS: */
try (OutputStream out = new FileOutputStream(filename);
POIFSFileSystem poiFs = new POIFSFileSystem();
- UnsynchronizedByteArrayOutputStream psStream = new UnsynchronizedByteArrayOutputStream()) {
+ UnsynchronizedByteArrayOutputStream psStream = UnsynchronizedByteArrayOutputStream.builder().get()) {
final PropertySet ps = new PropertySet();
final Section s = ps.getSections().get(0);
s.setFormatID(SummaryInformation.FORMAT_ID);
p.setValue(TITLE);
ms.setProperty(p);
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
mps.write(out);
byte[] bytes = out.toByteArray();
private void check(final long variantType, final Object value, final int codepage)
throws UnsupportedVariantTypeException, IOException
{
- final UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ final UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
VariantSupport.write(out, variantType, value, codepage);
final byte[] b = out.toByteArray();
final Object objRead =
doufStream.close();
// And also write to some bytes for checking
- UnsynchronizedByteArrayOutputStream sinfBytes = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream sinfBytes = UnsynchronizedByteArrayOutputStream.builder().get();
sinf.write(sinfBytes);
- UnsynchronizedByteArrayOutputStream dinfBytes = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream dinfBytes = UnsynchronizedByteArrayOutputStream.builder().get();
dinf.write(dinfBytes);
* Useful for verifying that the serialisation round trip
*/
public static HSSFWorkbook writeOutAndReadBack(HSSFWorkbook original) {
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
original.write(baos);
try (InputStream is = baos.toInputStream()) {
return new HSSFWorkbook(is);
*/
@Test
void testContinuedUnknownRecord() throws IOException {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
for (byte[] b : CONTINUE_DATA) {
bos.write(b);
}
SecurityManager sm = System.getSecurityManager();
System.setSecurityManager(new NoExitSecurityManager());
try {
- System.setErr(new NullPrintStream());
+ System.setErr(NullPrintStream.INSTANCE);
// calls System.exit()
assertThrows(ExitException.class, () -> OldExcelExtractor.main(new String[]{}));
} finally {
void testMain() throws IOException {
File file = HSSFTestDataSamples.getSampleFile("testEXCEL_3.xls");
PrintStream save = System.out;
- try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ try (UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
PrintStream str = new PrintStream(out, false, StandardCharsets.UTF_8.displayName(LocaleUtil.getUserLocale()))) {
System.setOut(str);
OldExcelExtractor.main(new String[] {file.getAbsolutePath()});
* @return the raw data being aggregated
*/
byte[] getRawBytes(){
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
for (RecordBase rb : aggRecords) {
Record r = (org.apache.poi.hssf.record.Record) rb;
try {
assertEquals(dgBytes.length, pos, "data was not fully read");
// serialize to byte array
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
for(EscherRecord r : records) {
out.write(r.serialize());
}
}
private static byte[] toByteArray(List<RecordBase> records) {
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
for (RecordBase rb : records) {
Record r = (org.apache.poi.hssf.record.Record) rb;
try {
class TestEscherRecordFactory {
private static byte[] toByteArray(List<RecordBase> records) {
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
for (RecordBase rb : records) {
Record r = (org.apache.poi.hssf.record.Record) rb;
try {
private void testReadWrite(byte[] data, String message) throws IOException {
RecordInputStream is = TestcaseRecordInputStream.create(81, data);
DConRefRecord d = new DConRefRecord(is);
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(data.length);
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(data.length).get();
LittleEndianOutputStream o = new LittleEndianOutputStream(bos);
d.serialize(o);
o.flush();
void testReadContinued() throws IOException {
//simulate a continues drawing record
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
//main part
DrawingRecord dg = new DrawingRecord();
byte[] data1 = new byte[8224];
try (LittleEndianInputStream in = new LittleEndianInputStream(new ByteArrayInputStream(data))) {
LbsDataSubRecord.LbsDropData lbs = new LbsDataSubRecord.LbsDropData(in);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (LittleEndianOutputStream out = new LittleEndianOutputStream(baos)) {
lbs.serialize(out);
assertTrue(records.get(4) instanceof ObjRecord);
//serialize and verify that the serialized data is the same as the original
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
for(org.apache.poi.hssf.record.Record rec : records){
out.write(rec.serialize());
}
BOFRecord.createSheetBOF(),
EOFRecord.instance,
};
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
for (org.apache.poi.hssf.record.Record rec : recs) {
try {
baos.write(rec.serialize());
*/
private static byte[] concatHexDumps(String... hexDumpFileNames) throws IOException {
int nFiles = hexDumpFileNames.length;
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(nFiles * 8228);
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(nFiles * 8228).get();
for (String sampleFileName : hexDumpFileNames) {
try (InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName)) {
BufferedReader br = new BufferedReader(new InputStreamReader(is, LocaleUtil.CHARSET_1252));
assertEquals(4, fr.getCharacterPos());
assertEquals(0x15c, fr.getFontIndex());
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
LittleEndianOutputStream out = new LittleEndianOutputStream(baos);
fr.serialize(out);
assertEquals(0, ext.getPhRuns().length);
assertEquals(10, ext.getDataSize()); // Excludes 4 byte header
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
LittleEndianOutputStream out = new LittleEndianOutputStream(baos);
ContinuableRecordOutput cout = new ContinuableRecordOutput(out, 0xffff);
@Test
void bug32191() throws IOException {
try (HSSFWorkbook wb = openSampleWorkbook("27394.xls");
- UnsynchronizedByteArrayOutputStream out1 = new UnsynchronizedByteArrayOutputStream();
- UnsynchronizedByteArrayOutputStream out2 = new UnsynchronizedByteArrayOutputStream();
- UnsynchronizedByteArrayOutputStream out3 = new UnsynchronizedByteArrayOutputStream()) {
+ UnsynchronizedByteArrayOutputStream out1 = UnsynchronizedByteArrayOutputStream.builder().get();
+ UnsynchronizedByteArrayOutputStream out2 = UnsynchronizedByteArrayOutputStream.builder().get();
+ UnsynchronizedByteArrayOutputStream out3 = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(out1);
wb.write(out2);
wb.write(out3);
}
// Convert BufferedImage to byte[]
- UnsynchronizedByteArrayOutputStream imageBAOS = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream imageBAOS = UnsynchronizedByteArrayOutputStream.builder().get();
ImageIO.write(bimage, "jpeg", imageBAOS);
imageBAOS.flush();
byte[] imageBytes = imageBAOS.toByteArray();
void test66319() throws IOException {
try (
HSSFWorkbook workbook = openSampleWorkbook("bug66319.xls");
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
for (Sheet sheet : workbook) {
for (Row row : sheet) {
void test66319WithRemove() throws IOException {
try (
HSSFWorkbook workbook = openSampleWorkbook("bug66319.xls");
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
for (Sheet sheet : workbook) {
for (Row row : sheet) {
void assertDataValidation(Workbook wb) {
byte[] generatedContent;
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(22000)) {
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(22000).get()) {
wb.write(baos);
generatedContent = baos.toByteArray();
} catch (IOException e) {
sheet.addValidationData(dv);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
wb.write(baos);
byte[] wbData = baos.toByteArray();
void setFillForegroundColor() throws IOException {
try (
HSSFWorkbook wb = new HSSFWorkbook();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()
) {
Cell cell = wb.createSheet().createRow(0).createCell(0);
HSSFCellStyle cellStyle = wb.createCellStyle();
HSSFWorkbook wb = new HSSFWorkbook(fs1)) {
ClassID clsid1 = fs1.getRoot().getStorageClsid();
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream(4096);
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(4096).get();
wb.write(out);
try (POIFSFileSystem fs2 = new POIFSFileSystem(out.toInputStream())) {
ClassID clsid2 = fs2.getRoot().getStorageClsid();
assertNotNull(name);
assertEquals("ASheet!A1", name.getRefersToFormula());
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().get();
wb.write(stream);
assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3", "ASheet");
assertSheetOrder(wb, "Sheet1", "Sheet3", "ASheet");
assertEquals("ASheet!A1", name.getRefersToFormula());
- UnsynchronizedByteArrayOutputStream stream2 = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream stream2 = UnsynchronizedByteArrayOutputStream.builder().get();
wb.write(stream2);
assertSheetOrder(wb, "Sheet1", "Sheet3", "ASheet");
private void writeAndCloseWorkbook(Workbook workbook, File file)
throws IOException {
- final UnsynchronizedByteArrayOutputStream bytesOut = new UnsynchronizedByteArrayOutputStream();
+ final UnsynchronizedByteArrayOutputStream bytesOut = UnsynchronizedByteArrayOutputStream.builder().get();
workbook.write(bytesOut);
workbook.close();
@Test
void checkExistingFileForR1C1Refs() throws IOException {
try (
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
HSSFWorkbook wb = openSampleWorkbook("49423.xls")
) {
assertEquals(CellReferenceType.A1, wb.getCellReferenceType());
@Test
void checkNewFileForR1C1Refs() throws IOException {
try (
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
HSSFWorkbook wb = new HSSFWorkbook()
) {
assertEquals(CellReferenceType.UNKNOWN, wb.getCellReferenceType());
circle.setNoFill(true);
try (HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1)) {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
HSSFObjectData od = wb2.getAllEmbeddedObjects().get(0);
Ole10Native ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode) od.getDirectory());
bos.reset();
}
static POIFSFileSystem getSampleXLS() throws IOException {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFSheet sheet = wb.createSheet();
sheet.createRow(5).createCell(2).setCellValue("yo dawg i herd you like embeddet objekts, so we put an ole in your ole so you can save a file while you save a file");
@Test
void testFail() throws IOException, NoPropertySetStreamException, WritingNotSupportedException {
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
// read the workbook, adjust the SummaryInformation and write the data to a byte array
try (POIFSFileSystem fs = openFileSystem();
HSSFWorkbook wb = new HSSFWorkbook(fs)) {
@Test
void testOK() throws Exception {
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
// read the workbook, adjust the SummaryInformation and write the data to a byte array
try (POIFSFileSystem fs = openFileSystem()) {
os.write(testData);
}
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
fsEnc.writeFilesystem(bos);
bos.close();
@BeforeAll
public static void setUp() throws UnsupportedEncodingException {
SYSTEM = System.out;
- System.setOut(new NullPrintStream());
+ System.setOut(NullPrintStream.INSTANCE);
}
@AfterAll
// verify that output is correct
POIFSDocument document = checkDocument(poifs, LARGER_BIG_BLOCK_SIZE + 1);
DocumentProperty property = document.getDocumentProperty();
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().get();
property.writeData(stream);
byte[] output = stream.toByteArray();
assertEquals(blockCountExp, blockCountAct);
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().get();
try (DocumentInputStream dis = document.getFileSystem().createDocumentInputStream(
document.getDocumentProperty().getName())) {
IOUtils.copy(dis, stream);
root.createDocument("foo", expected.length, l);
try (DocumentInputStream is = root.createDocumentInputStream("foo")) {
- final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(expected.length);
+ final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(expected.length).get();
IOUtils.copy(is, bos);
assertArrayEquals(expected, bos.toByteArray());
}
DirectoryEntry dir = fs.getRoot();
emptyDoc.handle(dir);
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
fs.writeFilesystem(out);
assertDoesNotThrow(() -> new POIFSFileSystem(out.toInputStream()));
}
void testEmptyDocumentBug11744() throws Exception {
byte[] testData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
try (POIFSFileSystem fs = new POIFSFileSystem()) {
fs.createDocument(new ByteArrayInputStream(new byte[0]), "Empty");
fs.createDocument(new ByteArrayInputStream(testData), "NotEmpty");
// Can work with POIFS
- try (UnsynchronizedByteArrayOutputStream tmpO = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream tmpO = UnsynchronizedByteArrayOutputStream.builder().get()) {
fs.writeFilesystem(tmpO);
try (InputStream tmpI = tmpO.toInputStream();
EntryUtils.copyNodes(root, dest);
// Re-load
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
root.getFileSystem().writeFilesystem(baos);
POIFSFileSystem read = new POIFSFileSystem(baos.toInputStream());
findOle10(entries, fs.getRoot(), "/");
for (Entry e : entries) {
- UnsynchronizedByteArrayOutputStream bosExp = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bosExp = UnsynchronizedByteArrayOutputStream.builder().get();
try (InputStream is = ((DirectoryNode) e.getParent()).createDocumentInputStream(e)) {
IOUtils.copy(is, bosExp);
}
Ole10Native ole = Ole10Native.createFromEmbeddedOleObject((DirectoryNode) e.getParent());
- UnsynchronizedByteArrayOutputStream bosAct = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bosAct = UnsynchronizedByteArrayOutputStream.builder().get();
ole.writeOut(bosAct);
assertThat(bosExp.toByteArray(), equalTo(bosAct.toByteArray()));
try (POIFSFileSystem fs = new POIFSFileSystem(_samples.openResourceAsStream(file))) {
// Write it into a temp output array
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
fs.writeFilesystem(baos);
// Check sizes
"BIG", new ByteArrayInputStream(hugeStream)
);
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
fs.writeFilesystem(baos);
byte[] fsData = baos.toByteArray();
}
private static HeaderBlock writeOutAndReadHeader(POIFSFileSystem fs) throws IOException {
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
fs.writeFilesystem(baos);
return new HeaderBlock(baos.toInputStream());
}
}
private void verifyProperty() throws IOException {
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(512);
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(512).get();
_property.writeData(stream);
byte[] output = stream.toByteArray();
private static void verifyReadingProperty(int index, byte[] input, int offset, String name) {
DirectoryProperty property = new DirectoryProperty(index, input, offset);
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(128);
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(128).get();
byte[] expected = Arrays.copyOfRange(input, offset, offset+128);
try {
property.writeData(stream);
throws IOException {
DocumentProperty property = new DocumentProperty(index, input,
offset);
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(128);
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(128).get();
byte[] expected = Arrays.copyOfRange(input, offset, offset+128);
property.writeData(stream);
byte[] output = stream.toByteArray();
{
testblock[ index * 2 ] = name_bytes[ index ];
}
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(512);
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(512).get();
property.writeData(stream);
byte[] output = stream.toByteArray();
final class TestPropertyTable {
private static void confirmBlockEncoding(String expectedDataStr, PropertyTable table) throws IOException {
- final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
byte[] expectedData = RawDataUtil.decompress(expectedDataStr);
POIFSStream stream = new POIFSStream(null) {
void testConstructor() throws IOException {
createBasicRootProperty();
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(512);
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(512).get();
_property.writeData(stream);
assertArrayEquals(_testblock, stream.toByteArray());
int offset = 0;
RootProperty property = new RootProperty(index, input, offset);
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream(128);
+ UnsynchronizedByteArrayOutputStream stream = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(128).get();
byte[] expected = Arrays.copyOfRange(input, offset, offset+128);
property.writeData(stream);
byte[] output = stream.toByteArray();
public static byte[] decode(String[] hexDataLines) {
try (UnsynchronizedByteArrayOutputStream baos =
- new UnsynchronizedByteArrayOutputStream(hexDataLines.length * 32 + 32)) {
+ UnsynchronizedByteArrayOutputStream.builder().setBufferSize(hexDataLines.length * 32 + 32).get()) {
for (String hexDataLine : hexDataLines) {
byte[] lineData = HexRead.readFromString(hexDataLine);
baos.write(lineData, 0, lineData.length);
public static byte[] decompress(String data) throws IOException {
byte[] base64Bytes = Base64.getDecoder().decode(data);
try (
- InputStream is = new UnsynchronizedByteArrayInputStream(base64Bytes);
+ InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(base64Bytes).get();
GZIPInputStream gzis = new GZIPInputStream(is);
) {
return IOUtils.toByteArray(gzis);
*/
public static String compress(byte[] data) throws IOException {
try (
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
java.util.zip.GZIPOutputStream gz = new java.util.zip.GZIPOutputStream(bos)
) {
gz.write(data);
}
private static byte[] readExternalFile(String path) {
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (InputStream fis = new FileInputStream(path)) {
byte[] buf = new byte[512];
cell.setCellValue("Ernie & Bert are cool!");
cell.setCellFormula("A1 & \" are cool!\"");
- try (UnsynchronizedByteArrayOutputStream out1 = new UnsynchronizedByteArrayOutputStream();
- UnsynchronizedByteArrayOutputStream out2 = new UnsynchronizedByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream out1 = UnsynchronizedByteArrayOutputStream.builder().get();
+ UnsynchronizedByteArrayOutputStream out2 = UnsynchronizedByteArrayOutputStream.builder().get()) {
wb.write(out1);
wb.write(out2);
g.draw(ell);
g.dispose();
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(2000);
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(2000).get();
ImageIO.write(bi, "PNG", bos);
return bos.toByteArray();
}
package org.apache.poi.ss.usermodel;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Iterator;
import java.util.Spliterator;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
c.setCellStyle(cs);
c.setCellValue("AAA");
}
- assertDoesNotThrow(() -> workbook.write(NULL_OUTPUT_STREAM));
+ assertDoesNotThrow(() -> workbook.write(NullOutputStream.INSTANCE));
}
}
File outputFile = new File("ExcelNumberRendering.xls");
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ try (UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
FileOutputStream os = new FileOutputStream(outputFile)) {
wb.write(baos);
}
private static String interpretLong(byte[] fileContent, int offset) {
- try (InputStream is = new UnsynchronizedByteArrayInputStream(fileContent, offset, 8)) {
+ try (InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(fileContent).setOffset(offset).setLength(8).get()) {
long l = new DataInputStream(is).readLong();
return "0x" + Long.toHexString(l).toUpperCase(Locale.ROOT);
} catch (IOException e) {
CellRangeAddress ref = new CellRangeAddress(0, 0, 0, 0);
byte[] recordBytes;
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (LittleEndianOutputStream out = new LittleEndianOutputStream(baos)) {
// With nothing set
ref.serialize(out);
import static java.text.DateFormat.getDateInstance;
import static java.text.DateFormat.getDateTimeInstance;
import static java.text.DateFormat.getTimeInstance;
-import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static org.apache.poi.ss.util.DateFormatConverter.getPrefixForLocale;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.stream.IntStream;
import java.util.stream.Stream;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
cell[6].setCellValue(excelFormatPattern);
}
- assertDoesNotThrow(() -> workbook.write(NULL_OUTPUT_STREAM));
+ assertDoesNotThrow(() -> workbook.write(NullOutputStream.INSTANCE));
}
}
@BeforeAll
public static void setUp() throws UnsupportedEncodingException {
SYSTEM_OUT = System.out;
- System.setOut(new NullPrintStream());
+ System.setOut(NullPrintStream.INSTANCE);
}
@AfterAll
@Test
void testDump() throws IOException {
byte[] testArray = testArray();
- UnsynchronizedByteArrayOutputStream streamAct = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream streamAct = UnsynchronizedByteArrayOutputStream.builder().get();
HexDump.dump(testArray, 0, streamAct, 0);
byte[] bytesAct = streamAct.toByteArray();
byte[] bytesExp = toHexDump(0, 0);
@Test
void testSkipFullyByteArray() throws IOException {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (InputStream is = new FileInputStream(TMP)) {
assertEquals(LENGTH, IOUtils.copy(is, bos));
long skipped = IOUtils.skipFully(bos.toInputStream(), 20000L);
@Test
void testSkipFullyByteArrayGtIntMax() throws IOException {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (InputStream is = new FileInputStream(TMP)) {
assertEquals(LENGTH, IOUtils.copy(is, bos));
long skipped = IOUtils.skipFully(bos.toInputStream(), Integer.MAX_VALUE + 20000L);
assertEquals(4, fr.getCharacterPos());
assertEquals(0x15c, fr.getFontIndex());
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
LittleEndianOutputStream out = new LittleEndianOutputStream(baos);
fr.serialize(out);
@Test
void testRead() throws IOException {
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
try (LittleEndianOutputStream leo = new LittleEndianOutputStream(baos)) {
leo.writeInt(12345678);
leo.writeShort(12345);
private static void checkRLEDecompression(String expected, byte[] runLengthEncodedData) throws IOException {
InputStream compressedStream = new ByteArrayInputStream(runLengthEncodedData);
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
try (InputStream stream = new RLEDecompressingInputStream(compressedStream)) {
IOUtils.copy(stream, out);
}