You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2021/05/14 00:37:53 UTC
svn commit: r1889871 [12/17] - in /poi: site/src/documentation/content/xdocs/
site/src/documentation/content/xdocs/components/ trunk/ trunk/maven/
trunk/osgi/ trunk/osgi/src/test/java/org/apache/poi/osgi/
trunk/poi-examples/src/main/java/org/apache/poi...
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTextShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTextShape.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTextShape.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTextShape.java Fri May 14 00:37:50 2021
@@ -17,27 +17,26 @@
package org.apache.poi.hslf.usermodel;
+import static org.apache.poi.hslf.HSLFTestDataSamples.getSlideShow;
+import static org.apache.poi.hslf.HSLFTestDataSamples.writeOutAndReadBack;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.poi.hslf.HSLFTestDataSamples;
import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.sl.usermodel.TextShape.TextPlaceholder;
import org.junit.jupiter.api.Test;
/**
- * Verify behavior of <code>TextShape</code> and its sub-classes
+ * Verify behavior of {@code TextShape} and its sub-classes
*/
public final class TestTextShape {
@Test
@@ -72,153 +71,146 @@ public final class TestTextShape {
*/
@Test
void read() throws IOException {
- HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("text_shapes.ppt");
+ try (HSLFSlideShow ppt = getSlideShow("text_shapes.ppt")) {
- List<String> lst1 = new ArrayList<>();
- HSLFSlide slide = ppt.getSlides().get(0);
- for (HSLFShape shape : slide.getShapes()) {
- assertTrue(shape instanceof HSLFTextShape, "Expected TextShape but found " + shape.getClass().getName());
- HSLFTextShape tx = (HSLFTextShape)shape;
- List<HSLFTextParagraph> paras = tx.getTextParagraphs();
- assertNotNull(paras);
- int runType = paras.get(0).getRunType();
-
- ShapeType type = shape.getShapeType();
- String rawText = HSLFTextParagraph.getRawText(paras);
- switch (type){
- case TEXT_BOX:
- assertEquals("Text in a TextBox", rawText);
- break;
- case RECT:
- if(runType == TextPlaceholder.OTHER.nativeId) {
- assertEquals("Rectangle", rawText);
- } else if(runType == TextPlaceholder.TITLE.nativeId) {
- assertEquals("Title Placeholder", rawText);
- }
- break;
- case OCTAGON:
- assertEquals("Octagon", rawText);
- break;
- case ELLIPSE:
- assertEquals("Ellipse", rawText);
- break;
- case ROUND_RECT:
- assertEquals("RoundRectangle", rawText);
- break;
- default:
- fail("Unexpected shape: " + shape.getShapeName());
+ List<String> lst1 = new ArrayList<>();
+ HSLFSlide slide = ppt.getSlides().get(0);
+ for (HSLFShape shape : slide.getShapes()) {
+ assertTrue(shape instanceof HSLFTextShape, "Expected TextShape but found " + shape.getClass().getName());
+ HSLFTextShape tx = (HSLFTextShape) shape;
+ List<HSLFTextParagraph> paras = tx.getTextParagraphs();
+ assertNotNull(paras);
+ int runType = paras.get(0).getRunType();
+
+ ShapeType type = shape.getShapeType();
+ String rawText = HSLFTextParagraph.getRawText(paras);
+ switch (type) {
+ case TEXT_BOX:
+ assertEquals("Text in a TextBox", rawText);
+ break;
+ case RECT:
+ if (runType == TextPlaceholder.OTHER.nativeId) {
+ assertEquals("Rectangle", rawText);
+ } else if (runType == TextPlaceholder.TITLE.nativeId) {
+ assertEquals("Title Placeholder", rawText);
+ }
+ break;
+ case OCTAGON:
+ assertEquals("Octagon", rawText);
+ break;
+ case ELLIPSE:
+ assertEquals("Ellipse", rawText);
+ break;
+ case ROUND_RECT:
+ assertEquals("RoundRectangle", rawText);
+ break;
+ default:
+ fail("Unexpected shape: " + shape.getShapeName());
+ }
+ lst1.add(rawText);
}
- lst1.add(rawText);
- }
- List<String> lst2 = new ArrayList<>();
- for (List<HSLFTextParagraph> paras : slide.getTextParagraphs()) {
- lst2.add(HSLFTextParagraph.getRawText(paras));
- }
+ List<String> lst2 = new ArrayList<>();
+ for (List<HSLFTextParagraph> paras : slide.getTextParagraphs()) {
+ lst2.add(HSLFTextParagraph.getRawText(paras));
+ }
- assertTrue(lst1.containsAll(lst2));
- ppt.close();
+ assertTrue(lst1.containsAll(lst2));
+ }
}
@Test
void readWrite() throws IOException {
- HSLFSlideShow ppt = new HSLFSlideShow();
- HSLFSlide slide = ppt.createSlide();
+ try (HSLFSlideShow ppt1 = new HSLFSlideShow()) {
+ HSLFSlide slide = ppt1.createSlide();
- HSLFTextShape shape1 = new HSLFTextBox();
- shape1.setText("Hello, World!");
- slide.addShape(shape1);
-
- shape1.moveTo(100, 100);
-
- HSLFTextShape shape2 = new HSLFAutoShape(ShapeType.RIGHT_ARROW);
- shape2.setText("Testing TextShape");
- slide.addShape(shape2);
- shape2.moveTo(300, 300);
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ppt.write(out);
- out.close();
-
- ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
- slide = ppt.getSlides().get(0);
- List<HSLFShape> shape = slide.getShapes();
-
- assertTrue(shape.get(0) instanceof HSLFTextShape);
- shape1 = (HSLFTextShape)shape.get(0);
- assertEquals(ShapeType.TEXT_BOX, shape1.getShapeType());
- assertEquals("Hello, World!", shape1.getText());
-
- assertTrue(shape.get(1) instanceof HSLFTextShape);
- shape1 = (HSLFTextShape)shape.get(1);
- assertEquals(ShapeType.RIGHT_ARROW, shape1.getShapeType());
- assertEquals("Testing TextShape", shape1.getText());
- ppt.close();
+ HSLFTextShape shape1 = new HSLFTextBox();
+ shape1.setText("Hello, World!");
+ slide.addShape(shape1);
+
+ shape1.moveTo(100, 100);
+
+ HSLFTextShape shape2 = new HSLFAutoShape(ShapeType.RIGHT_ARROW);
+ shape2.setText("Testing TextShape");
+ slide.addShape(shape2);
+ shape2.moveTo(300, 300);
+
+ try (HSLFSlideShow ppt2 = writeOutAndReadBack(ppt1)) {
+ slide = ppt2.getSlides().get(0);
+ List<HSLFShape> shape = slide.getShapes();
+
+ assertTrue(shape.get(0) instanceof HSLFTextShape);
+ shape1 = (HSLFTextShape) shape.get(0);
+ assertEquals(ShapeType.TEXT_BOX, shape1.getShapeType());
+ assertEquals("Hello, World!", shape1.getText());
+
+ assertTrue(shape.get(1) instanceof HSLFTextShape);
+ shape1 = (HSLFTextShape) shape.get(1);
+ assertEquals(ShapeType.RIGHT_ARROW, shape1.getShapeType());
+ assertEquals("Testing TextShape", shape1.getText());
+ }
+ }
}
@Test
void margins() throws IOException {
- HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("text-margins.ppt");
+ try (HSLFSlideShow ppt = getSlideShow("text-margins.ppt")) {
- HSLFSlide slide = ppt.getSlides().get(0);
+ HSLFSlide slide = ppt.getSlides().get(0);
- Map<String,HSLFTextShape> map = new HashMap<>();
- for (HSLFShape shape : slide.getShapes()) {
- if(shape instanceof HSLFTextShape){
- HSLFTextShape tx = (HSLFTextShape)shape;
- map.put(tx.getText(), tx);
+ Map<String, HSLFTextShape> map = new HashMap<>();
+ for (HSLFShape shape : slide.getShapes()) {
+ if (shape instanceof HSLFTextShape) {
+ HSLFTextShape tx = (HSLFTextShape) shape;
+ map.put(tx.getText(), tx);
+ }
}
- }
-
- HSLFTextShape tx;
-
- tx = map.get("TEST1");
- assertEquals(7.2, tx.getLeftInset(), 0);
- assertEquals(7.2, tx.getRightInset(), 0);
- assertEquals(28.34, tx.getTopInset(), 0.01);
- assertEquals(3.6, tx.getBottomInset(), 0);
-
- tx = map.get("TEST2");
- assertEquals(7.2, tx.getLeftInset(), 0);
- assertEquals(7.2, tx.getRightInset(), 0);
- assertEquals(3.6, tx.getTopInset(), 0);
- assertEquals(28.34, tx.getBottomInset(), 0.01);
-
- tx = map.get("TEST3");
- assertEquals(28.34, tx.getLeftInset(), 0.01);
- assertEquals(7.2, tx.getRightInset(), 0);
- assertEquals(3.6, tx.getTopInset(), 0);
- assertEquals(3.6, tx.getBottomInset(), 0);
-
- tx = map.get("TEST4");
- assertEquals(7.2, tx.getLeftInset(), 0);
- assertEquals(28.34, tx.getRightInset(), 0.01);
- assertEquals(3.6, tx.getTopInset(), 0);
- assertEquals(3.6, tx.getBottomInset(), 0);
- ppt.close();
+ HSLFTextShape tx = map.get("TEST1");
+ assertEquals(7.2, tx.getLeftInset(), 0);
+ assertEquals(7.2, tx.getRightInset(), 0);
+ assertEquals(28.34, tx.getTopInset(), 0.01);
+ assertEquals(3.6, tx.getBottomInset(), 0);
+
+ tx = map.get("TEST2");
+ assertEquals(7.2, tx.getLeftInset(), 0);
+ assertEquals(7.2, tx.getRightInset(), 0);
+ assertEquals(3.6, tx.getTopInset(), 0);
+ assertEquals(28.34, tx.getBottomInset(), 0.01);
+
+ tx = map.get("TEST3");
+ assertEquals(28.34, tx.getLeftInset(), 0.01);
+ assertEquals(7.2, tx.getRightInset(), 0);
+ assertEquals(3.6, tx.getTopInset(), 0);
+ assertEquals(3.6, tx.getBottomInset(), 0);
+
+ tx = map.get("TEST4");
+ assertEquals(7.2, tx.getLeftInset(), 0);
+ assertEquals(28.34, tx.getRightInset(), 0.01);
+ assertEquals(3.6, tx.getTopInset(), 0);
+ assertEquals(3.6, tx.getBottomInset(), 0);
+ }
}
@Test
void bug52599() throws IOException {
- HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("52599.ppt");
-
- HSLFSlide slide = ppt.getSlides().get(0);
- List<HSLFShape> sh = slide.getShapes();
- assertEquals(3, sh.size());
-
- HSLFTextShape sh0 = (HSLFTextShape)sh.get(0);
- assertNotNull(sh0.getTextParagraphs());
- assertEquals("", sh0.getText());
-
- HSLFTextShape sh1 = (HSLFTextShape)sh.get(1);
- assertNotNull(sh1.getTextParagraphs());
- assertEquals("", sh1.getText());
-
- HSLFTextShape sh2 = (HSLFTextShape)sh.get(2);
- assertEquals("this box should be shown just once", sh2.getText());
- assertEquals(-1, sh2.getTextParagraphs().get(0).getIndex());
- ppt.close();
+ try (HSLFSlideShow ppt = getSlideShow("52599.ppt")) {
+ HSLFSlide slide = ppt.getSlides().get(0);
+ List<HSLFShape> sh = slide.getShapes();
+ assertEquals(3, sh.size());
+
+ HSLFTextShape sh0 = (HSLFTextShape) sh.get(0);
+ assertNotNull(sh0.getTextParagraphs());
+ assertEquals("", sh0.getText());
+
+ HSLFTextShape sh1 = (HSLFTextShape) sh.get(1);
+ assertNotNull(sh1.getTextParagraphs());
+ assertEquals("", sh1.getText());
+
+ HSLFTextShape sh2 = (HSLFTextShape) sh.get(2);
+ assertEquals("this box should be shown just once", sh2.getText());
+ assertEquals(-1, sh2.getTextParagraphs().get(0).getIndex());
+ }
}
}
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestExtractEmbeddedMSG.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestExtractEmbeddedMSG.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestExtractEmbeddedMSG.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestExtractEmbeddedMSG.java Fri May 14 00:37:50 2021
@@ -21,12 +21,12 @@ import static org.junit.jupiter.api.Asse
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Calendar;
import java.util.Map;
import java.util.TimeZone;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
import org.apache.poi.hsmf.datatypes.Chunk;
@@ -54,8 +54,6 @@ public class TestExtractEmbeddedMSG {
/**
* Initialize this test, load up the attachment_msg_pdf.msg mapi message.
- *
- * @throws Exception
*/
@BeforeAll
public static void setUp() throws IOException {
@@ -71,9 +69,6 @@ public class TestExtractEmbeddedMSG {
/**
* Test to see if embedded message properties can be read, extracted, and
* re-parsed
- *
- * @throws ChunkNotFoundException
- *
*/
@Test
void testEmbeddedMSGProperties() throws IOException, ChunkNotFoundException {
@@ -86,11 +81,9 @@ public class TestExtractEmbeddedMSG {
testFixedAndVariableLengthPropertiesOfAttachedMSG(attachedMsg);
// rebuild top level message from embedded message
try (POIFSFileSystem extractedAttachedMsg = rebuildFromAttached(attachedMsg)) {
- try (ByteArrayOutputStream extractedAttachedMsgOut = new ByteArrayOutputStream()) {
+ try (UnsynchronizedByteArrayOutputStream extractedAttachedMsgOut = new UnsynchronizedByteArrayOutputStream()) {
extractedAttachedMsg.writeFilesystem(extractedAttachedMsgOut);
- byte[] extratedAttachedMsgRaw = extractedAttachedMsgOut.toByteArray();
- MAPIMessage extractedMsgTopLevel = new MAPIMessage(
- new ByteArrayInputStream(extratedAttachedMsgRaw));
+ MAPIMessage extractedMsgTopLevel = new MAPIMessage(extractedAttachedMsgOut.toInputStream());
// test properties of rebuilt embedded message
testFixedAndVariableLengthPropertiesOfAttachedMSG(extractedMsgTopLevel);
}
@@ -104,7 +97,7 @@ public class TestExtractEmbeddedMSG {
Calendar messageDate = msg.getMessageDate();
assertNotNull(messageDate);
Calendar expectedMessageDate = LocaleUtil.getLocaleCalendar();
- expectedMessageDate.set(2010, 05, 17, 23, 52, 19); // 2010/06/17 23:52:19 GMT
+ expectedMessageDate.set(2010, Calendar.JUNE, 17, 23, 52, 19); // 2010/06/17 23:52:19 GMT
expectedMessageDate.setTimeZone(TimeZone.getTimeZone("GMT"));
expectedMessageDate.set(Calendar.MILLISECOND, 0);
assertEquals(expectedMessageDate.getTimeInMillis(), messageDate.getTimeInMillis());
@@ -178,7 +171,7 @@ public class TestExtractEmbeddedMSG {
MAPIType type = Types.getById(iType);
if (type != null && type != Types.UNKNOWN) {
MAPIProperty mprop = MAPIProperty.createCustom(chunk.getChunkId(), type, chunk.getEntryName());
- ByteArrayOutputStream data = new ByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream data = new UnsynchronizedByteArrayOutputStream();
chunk.writeValue(data);
PropertyValue pval = new PropertyValue(mprop, MessagePropertiesChunk.PROPERTIES_FLAG_READABLE
| MessagePropertiesChunk.PROPERTIES_FLAG_WRITEABLE, data.toByteArray(), type);
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java Fri May 14 00:37:50 2021
@@ -22,14 +22,16 @@ import static org.junit.jupiter.api.Asse
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
/**
* Tests to verify that we can read attachments from msg file
@@ -74,32 +76,21 @@ public class TestFileWithAttachmentsRead
/**
* Bug 60550: Test to see if we get the correct Content-IDs of inline images`.
*/
- @Test
- void testReadContentIDField() throws IOException {
- AttachmentChunks[] attachments = inlineImgMsgAttachments.getAttachmentFiles();
-
- AttachmentChunks attachment;
-
- // Check in Content-ID field
- attachment = inlineImgMsgAttachments.getAttachmentFiles()[0];
- assertEquals("image001.png", attachment.getAttachFileName().getValue());
- assertEquals(".png", attachment.getAttachExtension().getValue());
- assertEquals("image001.png@01D0A524.96D40F30", attachment.getAttachContentId().getValue());
-
- attachment = inlineImgMsgAttachments.getAttachmentFiles()[1];
- assertEquals("image002.png", attachment.getAttachFileName().getValue());
- assertEquals(".png", attachment.getAttachExtension().getValue());
- assertEquals("image002.png@01D0A524.96D40F30", attachment.getAttachContentId().getValue());
-
- attachment = inlineImgMsgAttachments.getAttachmentFiles()[2];
- assertEquals("image003.png", attachment.getAttachFileName().getValue());
- assertEquals(".png", attachment.getAttachExtension().getValue());
- assertEquals("image003.png@01D0A526.B4C739C0", attachment.getAttachContentId().getValue());
-
- attachment = inlineImgMsgAttachments.getAttachmentFiles()[3];
- assertEquals("image006.jpg", attachment.getAttachFileName().getValue());
- assertEquals(".jpg", attachment.getAttachExtension().getValue());
- assertEquals("image006.jpg@01D0A526.B649E220", attachment.getAttachContentId().getValue());
+ @ParameterizedTest
+ @CsvSource({
+ "0, image001.png@01D0A524.96D40F30",
+ "1, image002.png@01D0A524.96D40F30",
+ "2, image003.png@01D0A526.B4C739C0",
+ "3, image006.jpg@01D0A526.B649E220"
+ })
+ void testReadContentIDField(int index, String contentId) {
+ AttachmentChunks attachment = inlineImgMsgAttachments.getAttachmentFiles()[index];
+ String fileName = contentId.substring(0, contentId.indexOf("@"));
+ String extension = fileName.substring(fileName.lastIndexOf("."));
+
+ assertEquals(fileName, attachment.getAttachFileName().getValue());
+ assertEquals(extension, attachment.getAttachExtension().getValue());
+ assertEquals(contentId, attachment.getAttachContentId().getValue());
}
@@ -128,7 +119,7 @@ public class TestFileWithAttachmentsRead
assertEquals("test-unicode.doc", attachment.getAttachLongFileName().getValue());
assertEquals(".doc", attachment.getAttachExtension().getValue());
assertNull(attachment.getAttachMimeTag());
- ByteArrayOutputStream attachmentstream = new ByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream attachmentstream = new UnsynchronizedByteArrayOutputStream();
attachment.getAttachData().writeValue(attachmentstream);
assertEquals(24064, attachmentstream.size());
// or compare the hashes of the attachment data
@@ -141,7 +132,7 @@ public class TestFileWithAttachmentsRead
assertNull(attachment.getAttachMimeTag());
// or compare the hashes of the attachment data
assertEquals(89, attachment.getAttachData().getValue().length);
- attachmentstream = new ByteArrayOutputStream();
+ attachmentstream.reset();
attachment.getAttachData().writeValue(attachmentstream);
assertEquals(89, attachmentstream.size());
}
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFixedSizedProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFixedSizedProperties.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFixedSizedProperties.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestFixedSizedProperties.java Fri May 14 00:37:50 2021
@@ -24,7 +24,6 @@ import static org.junit.jupiter.api.Asse
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashSet;
@@ -33,6 +32,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
+import org.apache.commons.io.output.NullPrintStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hsmf.datatypes.ChunkBasedPropertyValue;
import org.apache.poi.hsmf.datatypes.Chunks;
@@ -44,7 +44,6 @@ import org.apache.poi.hsmf.dev.HSMFDump;
import org.apache.poi.hsmf.extractor.OutlookTextExtractor;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.LocaleUtil;
-import org.apache.poi.util.NullPrintStream;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -167,7 +166,7 @@ public final class TestFixedSizedPropert
* Test to see if we can read the Date Chunk with HSMFDump.
*/
@Test
- void testReadMessageDateSucceedsWithHSMFDump() throws IOException {
+ void testReadMessageDateSucceedsWithHSMFDump() {
HSMFDump dump = new HSMFDump(fsMessageSucceeds);
assertDoesNotThrow(() -> dump.dump(new NullPrintStream()));
}
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestCase.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestCase.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestCase.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestCase.java Fri May 14 00:37:50 2021
@@ -17,10 +17,10 @@
package org.apache.poi.hwpf;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -29,7 +29,7 @@ public abstract class HWPFTestCase {
@BeforeEach
void setUp() throws Exception {
- /** @todo verify the constructors */
+ // @TODO verify the constructors
_hWPFDocFixture = new HWPFDocFixture(this, getTestFile());
_hWPFDocFixture.setUp();
@@ -40,7 +40,7 @@ public abstract class HWPFTestCase {
}
@AfterEach
- void tearDown() throws Exception {
+ void tearDown() {
if (_hWPFDocFixture != null) {
_hWPFDocFixture.tearDown();
}
@@ -49,15 +49,13 @@ public abstract class HWPFTestCase {
}
public HWPFDocument writeOutAndRead(HWPFDocument doc) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- HWPFDocument newDoc;
- try {
+ try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
doc.write(baos);
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- newDoc = new HWPFDocument(bais);
+ try (InputStream is = baos.toInputStream()) {
+ return new HWPFDocument(is);
+ }
} catch (IOException e) {
throw new RuntimeException(e);
}
- return newDoc;
}
}
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestDataSamples.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestDataSamples.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFTestDataSamples.java Fri May 14 00:37:50 2021
@@ -16,74 +16,24 @@
==================================================================== */
package org.apache.poi.hwpf;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.zip.ZipInputStream;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.util.IOUtils;
-
-import static org.apache.logging.log4j.util.Unbox.box;
public class HWPFTestDataSamples {
-
- private static final Logger LOG = LogManager.getLogger(HWPFTestDataSamples.class);
+ private static final POIDataSamples SAMPLES = POIDataSamples.getDocumentInstance();
public static HWPFDocument openSampleFile(String sampleFileName) {
- try {
- InputStream is = POIDataSamples.getDocumentInstance().openResourceAsStream(sampleFileName);
- try {
- return new HWPFDocument(is);
- } catch (Throwable e) {
- is.close();
- throw e;
- }
+ try (InputStream is = SAMPLES.openResourceAsStream(sampleFileName)) {
+ return new HWPFDocument(is);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
- public static HWPFDocument openSampleFileFromArchive( String sampleFileName )
- {
- final long start = System.currentTimeMillis();
- try
- {
- try (ZipInputStream is = new ZipInputStream(POIDataSamples
- .getDocumentInstance()
- .openResourceAsStream(sampleFileName))) {
- is.getNextEntry();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try {
- IOUtils.copy(is, baos);
- } finally {
- baos.close();
- }
-
- final long endUnzip = System.currentTimeMillis();
- byte[] byteArray = baos.toByteArray();
-
- LOG.atDebug().log("Unzipped in {} ms -- {} byte(s)", box(endUnzip - start),box(byteArray.length));
-
- ByteArrayInputStream bais = new ByteArrayInputStream(byteArray);
- HWPFDocument doc = new HWPFDocument(bais);
- final long endParse = System.currentTimeMillis();
-
- LOG.atDebug().log("Parsed in {} ms", box(endParse - start));
-
- return doc;
- }
- }
- catch ( IOException e )
- {
- throw new RuntimeException( e );
- }
- }
-
public static HWPFOldDocument openOldSampleFile(String sampleFileName) {
try {
InputStream is = POIDataSamples.getDocumentInstance().openResourceAsStream(sampleFileName);
@@ -98,11 +48,9 @@ public class HWPFTestDataSamples {
* Useful for verifying that the serialisation round trip
*/
public static HWPFDocument writeOutAndReadBack(HWPFDocument original) {
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+ try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(4096)) {
original.write(baos);
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- return new HWPFDocument(bais);
+ return new HWPFDocument(baos.toInputStream());
} catch (IOException e) {
throw new RuntimeException(e);
}
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/dev/TestHWPFLister.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/dev/TestHWPFLister.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/dev/TestHWPFLister.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/dev/TestHWPFLister.java Fri May 14 00:37:50 2021
@@ -22,7 +22,7 @@ import java.io.PrintStream;
import java.util.Arrays;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.util.NullPrintStream;
+import org.apache.commons.io.output.NullPrintStream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
@@ -38,7 +38,7 @@ public class TestHWPFLister {
"",
" --dop --textPieces --textPiecesText --chpx --chpxProperties --chpxSprms --papx --papxProperties --papxSprms --paragraphs --paragraphsText --bookmarks --escher --fields --pictures --officeDrawings --styles --writereadback"
})
- void main(String args) throws Exception {
+ void main(String args) {
String fileArgs = SAMPLES.getFile("SampleDoc.doc").getAbsolutePath() + args;
PrintStream oldStdOut = System.out;
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/model/TestSavedByTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/model/TestSavedByTable.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/model/TestSavedByTable.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/model/TestSavedByTable.java Fri May 14 00:37:50 2021
@@ -17,17 +17,15 @@
package org.apache.poi.hwpf.model;
+import static org.apache.poi.hwpf.HWPFTestDataSamples.openSampleFile;
+import static org.apache.poi.hwpf.HWPFTestDataSamples.writeOutAndReadBack;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import org.apache.poi.hwpf.HWPFDocument;
-import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.junit.jupiter.api.Test;
/**
@@ -53,29 +51,21 @@ public final class TestSavedByTable {
* Tests reading in the entries, comparing them against the expected
* entries. Then tests writing the document out and reading the entries yet
* again.
- *
- * @throws Exception if an unexpected error occurs.
*/
@Test
void testReadWrite() throws IOException {
// This document is widely available on the internet as "blair.doc".
// I tried stripping the content and saving the document but my version
// of Word (from Office XP) strips this table out.
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("saved-by-table.doc");
-
- // Check what we just read.
- assertEquals( expected, doc.getSavedByTable().getEntries(), "List of saved-by entries was not as expected" );
-
- // Now write the entire document out, and read it back in...
- ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
- doc.write(byteStream);
- InputStream copyStream = new ByteArrayInputStream(byteStream.toByteArray());
- doc.close();
- HWPFDocument copy = new HWPFDocument(copyStream);
-
- // And check again.
- assertEquals( expected, copy.getSavedByTable().getEntries(), "List of saved-by entries was incorrect after writing" );
-
- copy.close();
+ try (HWPFDocument doc = openSampleFile("saved-by-table.doc")) {
+ // Check what we just read.
+ assertEquals(expected, doc.getSavedByTable().getEntries(), "List of saved-by entries was not as expected");
+
+ // Now write the entire document out, and read it back in...
+ try (HWPFDocument copy = writeOutAndReadBack(doc)) {
+ // And check again.
+ assertEquals(expected, copy.getSavedByTable().getEntries(), "List of saved-by entries was incorrect after writing");
+ }
+ }
}
}
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/sprm/TestSprms.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/sprm/TestSprms.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/sprm/TestSprms.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/sprm/TestSprms.java Fri May 14 00:37:50 2021
@@ -19,43 +19,29 @@
package org.apache.poi.hwpf.sprm;
+import static org.apache.poi.hwpf.HWPFTestDataSamples.openSampleFile;
+import static org.apache.poi.hwpf.HWPFTestDataSamples.writeOutAndReadBack;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.util.Locale;
-import org.apache.poi.POIDataSamples;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range;
import org.junit.jupiter.api.Test;
public class TestSprms {
- private static HWPFDocument reload( HWPFDocument hwpfDocument )
- throws IOException
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- hwpfDocument.write( baos );
- return new HWPFDocument( new ByteArrayInputStream( baos.toByteArray() ) );
- }
-
/**
* Test correct processing of "sprmPItap" (0x6649) and "sprmPFInTable"
* (0x2416)
*/
@Test
void testInnerTable() throws Exception {
- InputStream resourceAsStream = POIDataSamples.getDocumentInstance()
- .openResourceAsStream( "innertable.doc" );
- try (HWPFDocument hwpfDocument = new HWPFDocument( resourceAsStream )) {
- resourceAsStream.close();
-
+ try (HWPFDocument hwpfDocument = openSampleFile("innertable.doc")) {
testInnerTable(hwpfDocument);
- try (HWPFDocument hwpfDocument2 = reload(hwpfDocument)) {
+ try (HWPFDocument hwpfDocument2 = writeOutAndReadBack(hwpfDocument)) {
testInnerTable(hwpfDocument2);
}
}
@@ -87,20 +73,12 @@ public class TestSprms {
*/
@Test
void testSprmPJc() throws IOException {
- try (InputStream resourceAsStream = POIDataSamples.getDocumentInstance()
- .openResourceAsStream( "Bug49820.doc" );
- HWPFDocument hwpfDocument = new HWPFDocument( resourceAsStream )) {
- resourceAsStream.close();
+ try (HWPFDocument hwpfDocument = openSampleFile( "Bug49820.doc" )) {
+ assertEquals(1, hwpfDocument.getStyleSheet().getParagraphStyle(8).getJustification());
- assertEquals(1, hwpfDocument.getStyleSheet().getParagraphStyle(8)
- .getJustification());
-
- try (HWPFDocument hwpfDocument2 = reload(hwpfDocument)) {
-
- assertEquals(1, hwpfDocument2.getStyleSheet().getParagraphStyle(8)
- .getJustification());
+ try (HWPFDocument hwpfDocument2 = writeOutAndReadBack(hwpfDocument)) {
+ assertEquals(1, hwpfDocument2.getStyleSheet().getParagraphStyle(8).getJustification());
}
}
-
}
}
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestHWPFWrite.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestHWPFWrite.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestHWPFWrite.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestHWPFWrite.java Fri May 14 00:37:50 2021
@@ -20,14 +20,13 @@ package org.apache.poi.hwpf.usermodel;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestCase;
@@ -48,20 +47,17 @@ public final class TestHWPFWrite extends
*/
@Test
void testWriteStream() throws IOException {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("SampleDoc.doc");
-
- Range r = doc.getRange();
- assertEquals("I am a test document\r", r.getParagraph(0).text());
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- doc.write(baos);
- doc.close();
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
- doc = new HWPFDocument(bais);
- r = doc.getRange();
- assertEquals("I am a test document\r", r.getParagraph(0).text());
- doc.close();
+ UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ try (HWPFDocument doc = HWPFTestDataSamples.openSampleFile("SampleDoc.doc")) {
+ Range r = doc.getRange();
+ assertEquals("I am a test document\r", r.getParagraph(0).text());
+ doc.write(baos);
+ }
+
+ try (HWPFDocument doc = new HWPFDocument(baos.toInputStream())) {
+ Range r = doc.getRange();
+ assertEquals("I am a test document\r", r.getParagraph(0).text());
+ }
}
/**
Modified: poi/trunk/poi/build.gradle
URL: http://svn.apache.org/viewvc/poi/trunk/poi/build.gradle?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/build.gradle (original)
+++ poi/trunk/poi/build.gradle Fri May 14 00:37:50 2021
@@ -39,6 +39,7 @@ dependencies {
api "commons-codec:commons-codec:${commonsCodecVersion}"
api 'org.apache.commons:commons-collections4:4.4'
api "org.apache.commons:commons-math3:${commonsMathVersion}"
+ api "commons-io:commons-io:${commonsIoVersion}"
api 'com.zaxxer:SparseBitSet:1.2'
implementation "org.apache.logging.log4j:log4j-api:${log4jVersion}"
implementation 'javax.activation:activation:1.1.1'
Modified: poi/trunk/poi/src/main/java/org/apache/poi/POIDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/POIDocument.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/POIDocument.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/POIDocument.java Fri May 14 00:37:50 2021
@@ -21,8 +21,6 @@ import static org.apache.logging.log4j.u
import static org.apache.poi.hpsf.PropertySetFactory.newDocumentSummaryInformation;
import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
@@ -32,6 +30,7 @@ import java.io.OutputStream;
import java.security.GeneralSecurityException;
import java.util.List;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.hpsf.DocumentSummaryInformation;
@@ -323,18 +322,16 @@ public abstract class POIDocument implem
* {@link POIFSFileSystem} occurs
*/
private void writePropertySet(String name, PropertySet set, POIFSFileSystem outFS) throws IOException {
- try {
+ try (UnsynchronizedByteArrayOutputStream bOut = new UnsynchronizedByteArrayOutputStream()) {
PropertySet mSet = new PropertySet(set);
- ByteArrayOutputStream bOut = new ByteArrayOutputStream();
-
mSet.write(bOut);
- byte[] data = bOut.toByteArray();
- ByteArrayInputStream bIn = new ByteArrayInputStream(data);
- // Create or Update the Property Set stream in the POIFS
- outFS.createOrUpdateDocument(bIn, name);
+ try (InputStream bIn = bOut.toInputStream()) {
+ // Create or Update the Property Set stream in the POIFS
+ outFS.createOrUpdateDocument(bIn, name);
+ }
- LOG.atInfo().log("Wrote property set {} of size {}", name, box(data.length));
+ LOG.atInfo().log("Wrote property set {} of size {}", name, box(bOut.size()));
} catch(WritingNotSupportedException ignored) {
LOG.atError().log("Couldn't write property set with name {} as not supported by HPSF yet", name);
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java Fri May 14 00:37:50 2021
@@ -22,7 +22,6 @@ import java.util.function.Supplier;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.Removal;
/**
* Generates escher records when provided the byte array containing those records.
@@ -73,23 +72,4 @@ public class DefaultEscherRecordFactory
// catch all
return UnknownEscherRecord::new;
}
-
-
- /**
- * @deprecated this method is not used anymore to identify container records
- */
- @Deprecated
- @Removal(version = "5.0.0")
- public static boolean isContainer(short options, short recordId){
- if(recordId >= EscherContainerRecord.DGG_CONTAINER && recordId
- <= EscherContainerRecord.SOLVER_CONTAINER){
- return true;
- } else {
- if (recordId == EscherTextboxRecord.RECORD_ID) {
- return false;
- } else {
- return ( options & (short) 0x000F ) == (short) 0x000F;
- }
- }
- }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java Fri May 14 00:37:50 2021
@@ -17,10 +17,11 @@
package org.apache.poi.ddf;
+import static org.apache.logging.log4j.util.Unbox.box;
+
import java.awt.Dimension;
import java.awt.Rectangle;
import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashMap;
@@ -29,21 +30,30 @@ import java.util.function.Supplier;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFPictureData;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndian;
-
-import static org.apache.logging.log4j.util.Unbox.box;
+import org.apache.poi.util.Removal;
public final class EscherMetafileBlip extends EscherBlipRecord {
private static final Logger LOGGER = LogManager.getLogger(EscherMetafileBlip.class);
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000_000;
+ /** @deprecated use EscherRecordTypes.BLIP_EMF.typeID */
+ @Deprecated
+ @Removal(version = "5.3")
public static final short RECORD_ID_EMF = EscherRecordTypes.BLIP_EMF.typeID;
+ /** @deprecated use EscherRecordTypes.BLIP_WMF.typeID */
+ @Deprecated
+ @Removal(version = "5.3")
public static final short RECORD_ID_WMF = EscherRecordTypes.BLIP_WMF.typeID;
+ /** @deprecated use EscherRecordTypes.BLIP_PICT.typeID */
+ @Deprecated
+ @Removal(version = "5.3")
public static final short RECORD_ID_PICT = EscherRecordTypes.BLIP_PICT.typeID;
private static final int HEADER_SIZE = 8;
@@ -150,9 +160,10 @@ public final class EscherMetafileBlip ex
data[pos] = field_6_fCompression; pos++;
data[pos] = field_7_fFilter; pos++;
- System.arraycopy( raw_pictureData, 0, data, pos, raw_pictureData.length ); pos += raw_pictureData.length;
+ System.arraycopy( raw_pictureData, 0, data, pos, raw_pictureData.length );
+ pos += raw_pictureData.length;
if(remainingData != null) {
- System.arraycopy( remainingData, 0, data, pos, remainingData.length ); pos += remainingData.length;
+ System.arraycopy( remainingData, 0, data, pos, remainingData.length );
}
listener.afterRecordSerialize(offset + getRecordSize(), getRecordId(), getRecordSize(), this);
@@ -166,15 +177,9 @@ public final class EscherMetafileBlip ex
* @return the inflated picture data.
*/
private static byte[] inflatePictureData(byte[] data) {
- try {
- InflaterInputStream in = new InflaterInputStream(
- new ByteArrayInputStream( data ) );
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- byte[] buf = new byte[4096];
- int readBytes;
- while ((readBytes = in.read(buf)) > 0) {
- out.write(buf, 0, readBytes);
- }
+ try (InflaterInputStream in = new InflaterInputStream(new ByteArrayInputStream(data));
+ UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
+ IOUtils.copy(in, out);
return out.toByteArray();
} catch (IOException e) {
LOGGER.atWarn().withThrowable(e).log("Possibly corrupt compression or non-compressed data");
@@ -390,11 +395,10 @@ public final class EscherMetafileBlip ex
// "... 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 {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- DeflaterOutputStream dos = new DeflaterOutputStream(bos);
- dos.write(pictureData);
- dos.close();
+ try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ try (DeflaterOutputStream dos = new DeflaterOutputStream(bos)) {
+ dos.write(pictureData);
+ }
raw_pictureData = bos.toByteArray();
} catch (IOException e) {
throw new RuntimeException("Can't compress metafile picture data", e);
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java Fri May 14 00:37:50 2021
@@ -41,16 +41,18 @@ public class HPSFPropertiesOnlyDocument
/**
* Write out to the currently open file the properties changes, but nothing else
*/
+ @Override
public void write() throws IOException {
POIFSFileSystem fs = getDirectory().getFileSystem();
-
- validateInPlaceWritePossible();
+
+ validateInPlaceWritePossible();
writeProperties(fs, null);
fs.writeFilesystem();
}
/**
* Write out, with any properties changes, but nothing else
*/
+ @Override
public void write(File newFile) throws IOException {
try (POIFSFileSystem fs = POIFSFileSystem.create(newFile)) {
write(fs);
@@ -60,25 +62,26 @@ public class HPSFPropertiesOnlyDocument
/**
* Write out, with any properties changes, but nothing else
*/
+ @Override
public void write(OutputStream out) throws IOException {
try (POIFSFileSystem fs = new POIFSFileSystem()) {
write(fs);
fs.writeFilesystem(out);
}
}
-
+
private void write(POIFSFileSystem fs) throws IOException {
// For tracking what we've written out, so far
List<String> excepts = new ArrayList<>(2);
// Write out our HPFS properties, with any changes
writeProperties(fs, excepts);
-
+
// Copy over everything else unchanged
FilteringDirectoryNode src = new FilteringDirectoryNode(getDirectory(), excepts);
FilteringDirectoryNode dest = new FilteringDirectoryNode(fs.getRoot(), excepts);
EntryUtils.copyNodes(src, dest);
-
+
// Caller will save the resultant POIFSFileSystem to the stream/file
}
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hpsf/Property.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hpsf/Property.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hpsf/Property.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hpsf/Property.java Fri May 14 00:37:50 2021
@@ -17,7 +17,8 @@
package org.apache.poi.hpsf;
-import java.io.ByteArrayOutputStream;
+import static org.apache.logging.log4j.util.Unbox.box;
+
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
@@ -29,6 +30,7 @@ import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
@@ -39,8 +41,6 @@ import org.apache.poi.util.LittleEndianB
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LocaleUtil;
-import static org.apache.logging.log4j.util.Unbox.box;
-
/**
* A property in a {@link Section} of a {@link PropertySet}.<p>
*
@@ -115,7 +115,7 @@ public class Property {
}
/**
- * Creates a {@link Property} instance by reading its bytes
+ * Creates a Property instance by reading its bytes
* from the property set stream.
*
* @param id The property's ID.
@@ -153,7 +153,7 @@ public class Property {
}
/**
- * Creates a {@link Property} instance by reading its bytes
+ * Creates a Property instance by reading its bytes
* from the property set stream.
*
* @param id The property's ID.
@@ -272,7 +272,7 @@ public class Property {
/* Variable length: */
if (type == Variant.VT_LPSTR || type == Variant.VT_LPWSTR) {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
try {
length = write(bos, property) - 2*LittleEndianConsts.INT_SIZE;
/* Pad to multiples of 4. */
@@ -295,8 +295,6 @@ public class Property {
* ID == 0 is a special case: It does not have a type, and its value is the
* section's dictionary. Another special case are strings: Two properties
* may have the different types Variant.VT_LPSTR and Variant.VT_LPWSTR;
- *
- * @see Object#equals(Object)
*/
@Override
public boolean equals(final Object o) {
@@ -366,22 +364,12 @@ public class Property {
(t2 == Variant.VT_LPSTR && t1 == Variant.VT_LPWSTR));
}
-
-
- /**
- * @see Object#hashCode()
- */
@Override
public int hashCode() {
return Objects.hash(id,type,value);
}
-
-
- /**
- * @see Object#toString()
- */
@Override
public String toString() {
return toString(Property.DEFAULT_CODEPAGE, null);
@@ -411,7 +399,7 @@ public class Property {
if (value instanceof String) {
b.append((String)value);
b.append("\n");
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
try {
write(bos, codepage);
} catch (Exception e) {
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hpsf/PropertySet.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hpsf/PropertySet.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hpsf/PropertySet.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hpsf/PropertySet.java Fri May 14 00:37:50 2021
@@ -18,7 +18,6 @@
package org.apache.poi.hpsf;
import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -27,6 +26,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.EmptyFileException;
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
@@ -38,7 +38,6 @@ import org.apache.poi.util.LittleEndianB
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianOutputStream;
import org.apache.poi.util.NotImplemented;
-import org.apache.poi.util.Removal;
/**
* Represents a property set in the Horrible Property Set Format
@@ -166,7 +165,7 @@ public class PropertySet {
/**
- * Creates a {@link PropertySet} instance from an {@link
+ * Creates a PropertySet instance from an {@link
* InputStream} in the Horrible Property Set Format.<p>
*
* The constructor reads the first few bytes from the stream
@@ -198,7 +197,7 @@ public class PropertySet {
/**
- * Creates a {@link PropertySet} instance from a byte array that
+ * Creates a PropertySet instance from a byte array that
* represents a stream in the Horrible Property Set Format.
*
* @param stream The byte array holding the stream data.
@@ -220,7 +219,7 @@ public class PropertySet {
}
/**
- * Creates a {@link PropertySet} instance from a byte array
+ * Creates a PropertySet instance from a byte array
* that represents a stream in the Horrible Property Set Format.
*
* @param stream The byte array holding the stream data. The
@@ -439,7 +438,7 @@ public class PropertySet {
/**
- * Initializes this {@link PropertySet} instance from a byte
+ * Initializes this PropertySet instance from a byte
* array. The method assumes that it has been checked already that
* the byte array indeed represents a property set stream. It does
* no more checks on its own.
@@ -515,7 +514,7 @@ public class PropertySet {
}
private byte[] toBytes() throws WritingNotSupportedException, IOException {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
LittleEndianOutputStream leos = new LittleEndianOutputStream(bos);
/* Write the number of sections in this property set stream. */
@@ -590,7 +589,7 @@ public class PropertySet {
* document. The input stream represents a snapshot of the property set.
* If the latter is modified while the input stream is still being
* read, the modifications will not be reflected in the input stream but in
- * the {@link PropertySet} only.
+ * the PropertySet only.
*
* @return the contents of this property set stream
*
@@ -657,9 +656,9 @@ public class PropertySet {
}
/**
- * Checks whether this {@link PropertySet} represents a Summary Information.
+ * Checks whether this PropertySet represents a Summary Information.
*
- * @return {@code true} if this {@link PropertySet}
+ * @return {@code true} if this PropertySet
* represents a Summary Information, else {@code false}.
*/
public boolean isSummaryInformation() {
@@ -667,9 +666,9 @@ public class PropertySet {
}
/**
- * Checks whether this {@link PropertySet} is a Document Summary Information.
+ * Checks whether this PropertySet is a Document Summary Information.
*
- * @return {@code true} if this {@link PropertySet}
+ * @return {@code true} if this PropertySet
* represents a Document Summary Information, else {@code false}.
*/
public boolean isDocumentSummaryInformation() {
@@ -687,13 +686,13 @@ public class PropertySet {
/**
* Convenience method returning the {@link Property} array contained in this
- * property set. It is a shortcut for getting he {@link PropertySet}'s
+ * property set. It is a shortcut for getting he PropertySets
* {@link Section}s list and then getting the {@link Property} array from the
* first {@link Section}.
*
* @return The properties of the only {@link Section} of this
- * {@link PropertySet}.
- * @throws NoSingleSectionException if the {@link PropertySet} has
+ * PropertySet.
+ * @throws NoSingleSectionException if the PropertySet has
* more or less than one {@link Section}.
*/
public Property[] getProperties() throws NoSingleSectionException {
@@ -709,7 +708,7 @@ public class PropertySet {
*
* @param id The property ID
* @return The property value
- * @throws NoSingleSectionException if the {@link PropertySet} has
+ * @throws NoSingleSectionException if the PropertySet has
* more or less than one {@link Section}.
*/
protected Object getProperty(final int id) throws NoSingleSectionException {
@@ -726,7 +725,7 @@ public class PropertySet {
*
* @param id The property ID
* @return The property value
- * @throws NoSingleSectionException if the {@link PropertySet} has
+ * @throws NoSingleSectionException if the PropertySet has
* more or less than one {@link Section}.
*/
boolean getPropertyBooleanValue(final int id) throws NoSingleSectionException {
@@ -744,7 +743,7 @@ public class PropertySet {
*
* @param id The property ID
* @return The propertyIntValue value
- * @throws NoSingleSectionException if the {@link PropertySet} has
+ * @throws NoSingleSectionException if the PropertySet has
* more or less than one {@link Section}.
*/
int getPropertyIntValue(final int id) throws NoSingleSectionException {
@@ -765,7 +764,7 @@ public class PropertySet {
* @return {@code true} if the last call to {@link
* #getPropertyIntValue} or {@link #getProperty} tried to access a
* property that was not available, else {@code false}.
- * @throws NoSingleSectionException if the {@link PropertySet} has
+ * @throws NoSingleSectionException if the PropertySet has
* more than one {@link Section}.
*/
public boolean wasNull() throws NoSingleSectionException {
@@ -775,9 +774,9 @@ public class PropertySet {
/**
- * Gets the {@link PropertySet}'s first section.
+ * Gets the PropertySets first section.
*
- * @return The {@link PropertySet}'s first section.
+ * @return The PropertySets first section.
*/
@SuppressWarnings("WeakerAccess")
public Section getFirstSection() {
@@ -825,22 +824,12 @@ public class PropertySet {
return getSections().containsAll(ps.getSections());
}
-
-
- /**
- * @see Object#hashCode()
- */
@NotImplemented
@Override
public int hashCode() {
throw new UnsupportedOperationException("FIXME: Not yet implemented.");
}
-
-
- /**
- * @see Object#toString()
- */
@Override
public String toString() {
final StringBuilder b = new StringBuilder();
@@ -888,7 +877,7 @@ public class PropertySet {
getFirstSection().setProperty((int)id, value);
}
- private static void putClassId(final ByteArrayOutputStream out, final ClassID n) {
+ private static void putClassId(final UnsynchronizedByteArrayOutputStream out, final ClassID n) {
byte[] b = new byte[16];
n.write(b, 0);
out.write(b, 0, b.length);
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hpsf/PropertySetFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hpsf/PropertySetFactory.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hpsf/PropertySetFactory.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hpsf/PropertySetFactory.java Fri May 14 00:37:50 2021
@@ -54,8 +54,6 @@ public class PropertySetFactory {
throws FileNotFoundException, NoPropertySetStreamException, IOException, UnsupportedEncodingException {
try (DocumentInputStream inp = ((DirectoryNode)dir).createDocumentInputStream(name)) {
return create(inp);
- } catch (MarkUnsupportedException e) {
- return null;
}
}
@@ -71,14 +69,12 @@ public class PropertySetFactory {
* @return The created {@link PropertySet}.
* @throws NoPropertySetStreamException if the stream does not
* contain a property set.
- * @throws MarkUnsupportedException if the stream does not support
- * the {@code mark} operation.
* @throws IOException if some I/O problem occurs.
* @exception UnsupportedEncodingException if the specified codepage is not
* supported.
*/
public static PropertySet create(final InputStream stream)
- throws NoPropertySetStreamException, MarkUnsupportedException, UnsupportedEncodingException, IOException {
+ throws NoPropertySetStreamException, IOException {
stream.mark(PropertySet.OFFSET_HEADER+ClassID.LENGTH+1);
LittleEndianInputStream leis = new LittleEndianInputStream(stream);
int byteOrder = leis.readUShort();
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hpsf/Section.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hpsf/Section.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hpsf/Section.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hpsf/Section.java Fri May 14 00:37:50 2021
@@ -17,7 +17,6 @@
package org.apache.poi.hpsf;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
@@ -31,6 +30,7 @@ import java.util.Set;
import java.util.TreeMap;
import org.apache.commons.collections4.bidimap.TreeBidiMap;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
@@ -66,7 +66,7 @@ public class Section {
* established when the section's size is calculated and can be reused
* later. If the array is empty, the section was modified and the bytes need to be regenerated.
*/
- private final ByteArrayOutputStream sectionBytes = new ByteArrayOutputStream();
+ private final UnsynchronizedByteArrayOutputStream sectionBytes = new UnsynchronizedByteArrayOutputStream();
/**
* The offset of the section in the stream.
@@ -86,7 +86,7 @@ public class Section {
private transient boolean wasNull;
/**
- * Creates an empty {@link Section}.
+ * Creates an empty Section.
*/
public Section() {
this._offset = -1;
@@ -112,7 +112,7 @@ public class Section {
/**
- * Creates a {@link Section} instance from a byte array.
+ * Creates a Section instance from a byte array.
*
* @param src Contains the complete property set stream.
* @param offset The position in the stream that points to the
@@ -428,7 +428,6 @@ public class Section {
* @see #getProperty
* @see Variant
*/
- @SuppressWarnings("deprecation")
public void setProperty(final int id, final long variantType, final Object value) {
setProperty(new Property(id, variantType, value));
}
@@ -601,7 +600,7 @@ public class Section {
/**
* Returns the PID string associated with a property ID. The ID
- * is first looked up in the {@link Section Sections} private dictionary.
+ * is first looked up in the Sections private dictionary.
* If it is not found there, the property PID string is taken
* from sections format IDs namespace.
* If the PID is also undefined there, i.e. it is not well-known,
@@ -641,14 +640,14 @@ public class Section {
*
* <ul>
*
- * <li>The other object is not a {@link Section}.
+ * <li>The other object is not a Section.
*
* <li>The format IDs of the two sections are not equal.
*
* <li>The sections have a different number of properties. However,
* properties with ID 1 (codepage) are not counted.
*
- * <li>The other object is not a {@link Section}.
+ * <li>The other object is not a Section.
*
* <li>The properties have different values. The order of the properties
* is irrelevant.
@@ -736,7 +735,7 @@ public class Section {
}
final int[][] offsets = new int[properties.size()][2];
- final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
final LittleEndianOutputStream leos = new LittleEndianOutputStream(bos);
/* Write the section's length - dummy value, fixed later */
@@ -932,19 +931,11 @@ public class Section {
}
}
-
-
- /**
- * @see Object#hashCode()
- */
@Override
public int hashCode() {
return Arrays.deepHashCode(new Object[]{getFormatID(),getProperties()});
}
- /**
- * @see Object#toString()
- */
@Override
public String toString() {
return toString(null);
@@ -1008,7 +999,7 @@ public class Section {
*/
public int getCodepage() {
final Integer codepage = (Integer) getProperty(PropertyIDMap.PID_CODEPAGE);
- return (codepage == null) ? -1 : codepage.intValue();
+ return (codepage == null) ? -1 : codepage;
}
/**
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hpsf/SummaryInformation.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hpsf/SummaryInformation.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hpsf/SummaryInformation.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hpsf/SummaryInformation.java Fri May 14 00:37:50 2021
@@ -50,14 +50,14 @@ public final class SummaryInformation ex
}
/**
- * Creates an empty {@link SummaryInformation}.
+ * Creates an empty SummaryInformation.
*/
public SummaryInformation() {
getFirstSection().setFormatID(FORMAT_ID);
}
/**
- * Creates a {@link SummaryInformation} from a given {@link
+ * Creates a SummaryInformation from a given {@link
* PropertySet}.
*
* @param ps A property set which should be created from a summary
@@ -73,7 +73,7 @@ public final class SummaryInformation ex
}
/**
- * Creates a {@link SummaryInformation} instance from an {@link
+ * Creates a SummaryInformation instance from an {@link
* InputStream} in the Horrible Property Set Format.<p>
*
* The constructor reads the first few bytes from the stream
@@ -85,8 +85,6 @@ public final class SummaryInformation ex
*
* @param stream Holds the data making out the property set
* stream.
- * @throws MarkUnsupportedException
- * if the stream does not support the {@link InputStream#markSupported} method.
* @throws IOException
* if the {@link InputStream} cannot be accessed as needed.
* @exception NoPropertySetStreamException
@@ -95,7 +93,7 @@ public final class SummaryInformation ex
* if a character encoding is not supported.
*/
public SummaryInformation(final InputStream stream)
- throws NoPropertySetStreamException, MarkUnsupportedException, IOException, UnsupportedEncodingException {
+ throws NoPropertySetStreamException, IOException {
super(stream);
}
@@ -481,10 +479,10 @@ public final class SummaryInformation ex
/**
- * Returns the page count or 0 if the {@link SummaryInformation} does
+ * Returns the page count or 0 if the SummaryInformation does
* not contain a page count.
*
- * @return The page count or 0 if the {@link SummaryInformation} does not
+ * @return The page count or 0 if the SummaryInformation does not
* contain a page count.
*/
public int getPageCount() {
@@ -514,7 +512,7 @@ public final class SummaryInformation ex
/**
- * Returns the word count or 0 if the {@link SummaryInformation} does
+ * Returns the word count or 0 if the SummaryInformation does
* not contain a word count.
*
* @return The word count or {@code null}
@@ -546,7 +544,7 @@ public final class SummaryInformation ex
/**
- * Returns the character count or 0 if the {@link SummaryInformation}
+ * Returns the character count or 0 if the SummaryInformation
* does not contain a char count.
*
* @return The character count or {@code null}
@@ -665,7 +663,7 @@ public final class SummaryInformation ex
*
* <ul>
*
- * <li>0 if the {@link SummaryInformation} does not contain a
+ * <li>0 if the SummaryInformation does not contain a
* security field or if there is no security on the document. Use
* {@link PropertySet#wasNull()} to distinguish between the two
* cases!
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/dev/ReSave.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/dev/ReSave.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/dev/ReSave.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/dev/ReSave.java Fri May 14 00:37:50 2021
@@ -17,11 +17,11 @@
package org.apache.poi.hssf.dev;
-import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -60,7 +60,7 @@ public class ReSave {
System.out.print("saving to " + outputFile + "...");
}
- try (OutputStream os = saveToMemory ? new ByteArrayOutputStream() : new FileOutputStream(outputFile)) {
+ try (OutputStream os = saveToMemory ? new UnsynchronizedByteArrayOutputStream() : new FileOutputStream(outputFile)) {
wb.write(os);
}
System.out.println("done");
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org