pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1552522 - in /pdfbox/branches/1.8: ./ pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
Date Fri, 20 Dec 2013 08:06:12 GMT
Author: lehmi
Date: Fri Dec 20 08:06:12 2013
New Revision: 1552522

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

Modified:
    pdfbox/branches/1.8/   (props changed)
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java

Propchange: pdfbox/branches/1.8/
------------------------------------------------------------------------------
  Merged /pdfbox/trunk:r1552521

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java?rev=1552522&r1=1552521&r2=1552522&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
Fri Dec 20 08:06:12 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