You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2011/02/23 20:01:25 UTC

svn commit: r1073883 - /poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java

Author: nick
Date: Wed Feb 23 19:01:24 2011
New Revision: 1073883

URL: http://svn.apache.org/viewvc?rev=1073883&view=rev
Log:
Switch Picture processing in HSLFSlideShow to be lazy-loading, to speed things up if you're only interested in text stuff

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java?rev=1073883&r1=1073882&r2=1073883&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java Wed Feb 23 19:01:24 2011
@@ -174,9 +174,6 @@ public final class HSLFSlideShow extends
 
 		// Look for any other streams
 		readOtherStreams();
-
-		// Look for Picture Streams:
-		readPictures();
 	}
 	/**
 	 * Constructs a new, empty, Powerpoint document.
@@ -309,7 +306,8 @@ public final class HSLFSlideShow extends
 	}
 
 	/**
-	 * Find and read in pictures contained in this presentation
+	 * Find and read in pictures contained in this presentation.
+	 * This is lazily called as and when we want to touch pictures.
 	 */
 	private void readPictures() throws IOException {
         _pictures = new ArrayList<PictureData>();
@@ -472,6 +470,9 @@ public final class HSLFSlideShow extends
 
 
         // Write any pictures, into another stream
+        if(_pictures == null) {
+           readPictures();
+        }
         if (_pictures.size() > 0) {
             ByteArrayOutputStream pict = new ByteArrayOutputStream();
             for (PictureData p : _pictures) {
@@ -526,15 +527,24 @@ public final class HSLFSlideShow extends
      * @return offset of this picture in the Pictures stream
 	 */
 	public int addPicture(PictureData img) {
-		int offset = 0;
-
-        if(_pictures.size() > 0){
-            PictureData prev = _pictures.get(_pictures.size() - 1);
-            offset = prev.getOffset() + prev.getRawData().length + 8;
-        }
-        img.setOffset(offset);
-        _pictures.add(img);
-        return offset;
+	   // Process any existing pictures if we haven't yet
+	   if(_pictures == null) {
+         try {
+            readPictures();
+         } catch(IOException e) {
+            throw new CorruptPowerPointFileException(e.getMessage());
+         }
+	   }
+	   
+	   // Add the new picture in
+      int offset = 0;
+	   if(_pictures.size() > 0) {
+	      PictureData prev = _pictures.get(_pictures.size() - 1);
+	      offset = prev.getOffset() + prev.getRawData().length + 8;
+	   }
+	   img.setOffset(offset);
+	   _pictures.add(img);
+	   return offset;
    }
 
 	/* ******************* fetching methods follow ********************* */
@@ -563,6 +573,14 @@ public final class HSLFSlideShow extends
 	 *  presentation doesn't contain pictures.
 	 */
 	public PictureData[] getPictures() {
+	   if(_pictures == null) {
+	      try {
+	         readPictures();
+	      } catch(IOException e) {
+	         throw new CorruptPowerPointFileException(e.getMessage());
+	      }
+	   }
+	   
 		return _pictures.toArray(new PictureData[_pictures.size()]);
 	}
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org