commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1401553 - in /commons/proper/imaging/trunk/src: changes/changes.xml main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java
Date Wed, 24 Oct 2012 05:21:55 GMT
Author: damjan
Date: Wed Oct 24 05:21:55 2012
New Revision: 1401553

URL: http://svn.apache.org/viewvc?rev=1401553&view=rev
Log:
Speed up ByteSourceInputStream.CacheReadingInputStream.skip(), which
speeds up reading TIFF files from InputStreams.

Submitted by: Amit Gupta <amitgupt at adobe dot com>
Jira issue key: IMAGING-95


Modified:
    commons/proper/imaging/trunk/src/changes/changes.xml
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java

Modified: commons/proper/imaging/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/changes/changes.xml?rev=1401553&r1=1401552&r2=1401553&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/changes/changes.xml (original)
+++ commons/proper/imaging/trunk/src/changes/changes.xml Wed Oct 24 05:21:55 2012
@@ -236,6 +236,9 @@ The <action> type attribute can be add,u
       <action issue="IMAGING-91" dev="damjan" type="update">
          ByteSourceInputStream.streamLength could be a long.
       </action>
+      <action issue="IMAGING-95" dev="damjan" type="update" due-to="amitgupt">
+         Some tiff processing takes very long.
+      </action>
     </release>
     
   </body>

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java?rev=1401553&r1=1401552&r2=1401553&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java
Wed Oct 24 05:21:55 2012
@@ -88,7 +88,7 @@ public class ByteSourceInputStream exten
         private CacheBlock block = null;
         private boolean readFirst = false;
         private int blockIndex = 0;
-
+        
         @Override
         public int read() throws IOException {
             if (null == block) {
@@ -155,6 +155,48 @@ public class ByteSourceInputStream exten
             blockIndex += readSize;
             return readSize;
         }
+        
+        @Override
+        public long skip(long n) throws IOException {
+
+            long remaining = n;
+
+            if (n <= 0) {
+                return 0;
+            }
+
+            while (remaining > 0) {
+                // read the first block
+                if (null == block) {
+                    if (readFirst) {
+                        return -1;
+                    }
+                    block = getFirstBlock();
+                    readFirst = true;
+                }
+
+                // get next block
+                if (block != null && blockIndex >= block.bytes.length) {
+                    block = block.getNext();
+                    blockIndex = 0;
+                }
+
+                if (null == block) {
+                    break;
+                }
+
+                if (blockIndex >= block.bytes.length) {
+                    break;
+                }
+
+                int readSize = Math.min((int) Math.min(BLOCK_SIZE, remaining), block.bytes.length
- blockIndex);
+
+                blockIndex += readSize;
+                remaining -= readSize;
+            }
+
+            return n - remaining;
+        }
 
     }
 



Mime
View raw message