pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1552521 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
Date Fri, 20 Dec 2013 08:02:40 GMT
Author: lehmi
Date: Fri Dec 20 08:02:39 2013
New Revision: 1552521

URL: http://svn.apache.org/r1552521
Log:
PDFBOX-1769: loop to read all needed bytes

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java?rev=1552521&r1=1552520&r2=1552521&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
Fri Dec 20 08:02:39 2013
@@ -1743,16 +1743,26 @@ public class NonSequentialPDFParser exte
      */
     private boolean checkBytesAtOffset(byte[] string) throws IOException
     {
-    	byte[] bytesRead = new byte[string.length];
     	boolean bytesMatching = false;
 		if (pdfSource.peek() == string[0])
 		{
-			pdfSource.read(bytesRead, 0, string.length);
+	    	int length = string.length;
+	    	byte[] bytesRead = new byte[length];
+			int numberOfBytes = pdfSource.read(bytesRead, 0, length);
+			while (numberOfBytes < length)
+			{
+				int readMore =  pdfSource.read(bytesRead, numberOfBytes, length-numberOfBytes);
+				if (readMore < 0)
+				{
+					break;
+				}
+				numberOfBytes += readMore;
+			}
 			if (Arrays.equals(string, bytesRead))
 			{
 				bytesMatching = true;
 			}
-			pdfSource.unread(bytesRead);
+			pdfSource.unread(bytesRead, 0, numberOfBytes);
 		}
 		return bytesMatching;
     }



Mime
View raw message