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 2015/08/01 22:09:38 UTC
svn commit: r1693754 - in /poi: site/src/documentation/content/xdocs/
trunk/src/java/org/apache/poi/util/
trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/
Author: kiwiwings
Date: Sat Aug 1 20:09:37 2015
New Revision: 1693754
URL: http://svn.apache.org/r1693754
Log:
#58193 - Use input stream rather than byte array for checksum etc.
Modified:
poi/site/src/documentation/content/xdocs/status.xml
poi/trunk/src/java/org/apache/poi/util/IOUtils.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
Modified: poi/site/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1693754&r1=1693753&r2=1693754&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Sat Aug 1 20:09:37 2015
@@ -39,6 +39,7 @@
</devs>
<release version="3.13-beta2" date="2015-10-??">
+ <action dev="PD" type="add" fixes-bug="58193">Use input stream rather than byte array for checksum etc.</action>
<action dev="PD" type="add" fixes-bug="58200">SXSSF support for evaluating formula cells, provided the cell and all its references are within the current window</action>
<action dev="PD" type="fix" fixes-bug="58098">Avoid NPE in cleanup if NPOIFSFileSystem is opened on a locked File under Windows</action>
<action dev="PD" type="add">Merged common_sl branch to trunk</action>
Modified: poi/trunk/src/java/org/apache/poi/util/IOUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/IOUtils.java?rev=1693754&r1=1693753&r2=1693754&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/IOUtils.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/IOUtils.java Sat Aug 1 20:09:37 2015
@@ -166,6 +166,9 @@ public final class IOUtils {
}
}
+ /**
+ * Calculate checksum on input data
+ */
public static long calculateChecksum(byte[] data) {
Checksum sum = new CRC32();
sum.update(data, 0, data.length);
@@ -173,6 +176,26 @@ public final class IOUtils {
}
/**
+ * Calculate checksum on all the data read from input stream.
+ *
+ * This should be more efficient than the equivalent code
+ * {@code IOUtils.calculateChecksum(IOUtils.toByteArray(stream))}
+ */
+ public static long calculateChecksum(InputStream stream) throws IOException {
+ Checksum sum = new CRC32();
+
+ byte[] buf = new byte[4096];
+ int count;
+ while ((count = stream.read(buf)) != -1) {
+ if (count > 0) {
+ sum.update(buf, 0, count);
+ }
+ }
+ return sum.getValue();
+ }
+
+
+ /**
* Quietly (no exceptions) close Closable resource. In case of error it will
* be printed to {@link IOUtils} class logger.
*
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java?rev=1693754&r1=1693753&r2=1693754&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java Sat Aug 1 20:09:37 2015
@@ -20,6 +20,7 @@
package org.apache.poi.xslf.usermodel;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import org.apache.poi.POIXMLDocumentPart;
@@ -141,21 +142,25 @@ public final class XSLFPictureData exten
}
/**
+ * An InputStream to read the picture data directly
+ * from the underlying package part
+ *
+ * @return InputStream
+ */
+ public InputStream getInputStream() throws IOException {
+ return getPackagePart().getInputStream();
+ }
+
+ /**
* Gets the picture data as a byte array.
- * <p>
- * Note, that this call might be expensive since all the picture data is copied into a temporary byte array.
- * You can grab the picture data directly from the underlying package part as follows:
- * <br/>
- * <code>
- * InputStream is = getPackagePart().getInputStream();
- * </code>
- * </p>
*
+ * You can grab the picture data directly from the underlying package part with the {@link #getInputStream()} method
+ *
* @return the Picture data.
*/
public byte[] getData() {
try {
- return IOUtils.toByteArray(getPackagePart().getInputStream());
+ return IOUtils.toByteArray(getInputStream());
} catch (IOException e) {
throw new POIXMLException(e);
}
@@ -203,8 +208,11 @@ public final class XSLFPictureData exten
long getChecksum(){
if(checksum == null){
- byte[] pictureData = getData();
- checksum = IOUtils.calculateChecksum(pictureData);
+ try {
+ checksum = IOUtils.calculateChecksum(getInputStream());
+ } catch (IOException e) {
+ throw new POIXMLException("Unable to calulate checksum", e);
+ }
}
return checksum;
}
@@ -227,6 +235,8 @@ public final class XSLFPictureData exten
OutputStream os = getPackagePart().getOutputStream();
os.write(data);
os.close();
+ // recalculate now since we already have the data bytes available anyhow
+ checksum = IOUtils.calculateChecksum(data);
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java?rev=1693754&r1=1693753&r2=1693754&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java Sat Aug 1 20:09:37 2015
@@ -22,7 +22,6 @@ package org.apache.poi.xslf.usermodel;
import java.awt.Insets;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
import java.net.URI;
import javax.imageio.ImageIO;
@@ -91,10 +90,8 @@ public class XSLFPictureShape extends XS
* for other types sets the default size of 200x200 pixels.
*/
public void resize() {
- XSLFPictureData pict = getPictureData();
-
try {
- BufferedImage img = ImageIO.read(new ByteArrayInputStream(pict.getData()));
+ BufferedImage img = ImageIO.read(getPictureData().getInputStream());
setAnchor(new Rectangle2D.Double(0, 0, img.getWidth(), img.getHeight()));
}
catch (Exception e) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org