You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2014/12/21 00:41:39 UTC
svn commit: r1647063 - in
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser:
PDFParser.java VisualSignatureParser.java
Author: tilman
Date: Sat Dec 20 23:41:39 2014
New Revision: 1647063
URL: http://svn.apache.org/r1647063
Log:
PDFBOX-2576: partial reformat for code analysis tool
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/VisualSignatureParser.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java?rev=1647063&r1=1647062&r2=1647063&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java Sat Dec 20 23:41:39 2014
@@ -553,12 +553,11 @@ public class PDFParser extends BaseParse
//we are going to parse a normal object
long number = -1;
int genNum;
- String objectKey;
boolean missingObjectNumber = false;
try
{
- char peeked = (char)pdfSource.peek();
- if( peeked == '<' )
+ char peeked = (char) pdfSource.peek();
+ if (peeked == '<')
{
missingObjectNumber = true;
}
@@ -567,7 +566,7 @@ public class PDFParser extends BaseParse
number = readObjectNumber();
}
}
- catch( IOException e )
+ catch (IOException e)
{
//ok for some reason "GNU Ghostscript 5.10" puts two endobj
//statements after an object, of course this is nonsense
@@ -575,17 +574,15 @@ public class PDFParser extends BaseParse
//we will simply try again
number = readObjectNumber();
}
- if( !missingObjectNumber )
+ if (!missingObjectNumber)
{
skipSpaces();
genNum = readGenerationNumber();
- objectKey = readString( 3 );
- //System.out.println( "parseObject() num=" + number +
- //" genNumber=" + genNum + " key='" + objectKey + "'" );
- if( !objectKey.equals( "obj" ) )
+ String objectKey = readString(3);
+ if (!objectKey.equals("obj"))
{
- if (!isContinueOnError(null) || !objectKey.equals("o"))
+ if (!isContinueOnError(null) || !objectKey.equals("o"))
{
throw new IOException("expected='obj' actual='" + objectKey + "' " + pdfSource);
}
@@ -603,17 +600,17 @@ public class PDFParser extends BaseParse
COSBase pb = parseDirObject();
String endObjectKey = readString();
- if( endObjectKey.equals( "stream" ) )
+ if (endObjectKey.equals("stream"))
{
- pdfSource.unread( endObjectKey.getBytes("ISO-8859-1") );
- pdfSource.unread( ' ' );
- if( pb instanceof COSDictionary )
+ pdfSource.unread(endObjectKey.getBytes("ISO-8859-1"));
+ pdfSource.unread(' ');
+ if (pb instanceof COSDictionary)
{
- pb = parseCOSStream( (COSDictionary)pb );
+ pb = parseCOSStream((COSDictionary) pb);
// test for XRef type
final COSStream strmObj = (COSStream) pb;
-
+
// remember streams without length to check them later
COSBase streamLength = strmObj.getItem(COSName.LENGTH);
int length = -1;
@@ -625,12 +622,12 @@ public class PDFParser extends BaseParse
{
streamLengthCheckSet.add(strmObj);
}
-
- final COSName objectType = (COSName)strmObj.getItem( COSName.TYPE );
- if( objectType != null && objectType.equals( COSName.XREF ) )
+
+ final COSName objectType = (COSName) strmObj.getItem(COSName.TYPE);
+ if (objectType != null && objectType.equals(COSName.XREF))
{
// XRef stream
- parseXrefStream( strmObj, currentObjByteOffset );
+ parseXrefStream(strmObj, currentObjByteOffset);
}
}
else
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/VisualSignatureParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/VisualSignatureParser.java?rev=1647063&r1=1647062&r2=1647063&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/VisualSignatureParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/VisualSignatureParser.java Sat Dec 20 23:41:39 2014
@@ -190,19 +190,19 @@ public class VisualSignatureParser exten
long number = -1;
int genNum;
boolean missingObjectNumber = false;
- try
+ try
{
char peeked = (char) pdfSource.peek();
- if(peeked == '<')
+ if (peeked == '<')
{
missingObjectNumber = true;
- }
- else
+ }
+ else
{
number = readObjectNumber();
}
- }
- catch(IOException e)
+ }
+ catch (IOException e)
{
//ok for some reason "GNU Ghostscript 5.10" puts two endobj
//statements after an object, of course this is nonsense
@@ -210,18 +210,18 @@ public class VisualSignatureParser exten
//we will simply try again
number = readObjectNumber();
}
- if(!missingObjectNumber)
+ if (!missingObjectNumber)
{
skipSpaces();
genNum = readGenerationNumber();
String objectKey = readString(3);
- if(!objectKey.equals("obj"))
+ if (!objectKey.equals("obj"))
{
throw new IOException("expected='obj' actual='" + objectKey + "' " + pdfSource);
}
- }
- else
+ }
+ else
{
number = -1;
genNum = -1;
@@ -231,16 +231,16 @@ public class VisualSignatureParser exten
COSBase pb = parseDirObject();
String endObjectKey = readString();
- if(endObjectKey.equals("stream"))
+ if (endObjectKey.equals("stream"))
{
pdfSource.unread(endObjectKey.getBytes());
pdfSource.unread(' ');
- if(pb instanceof COSDictionary)
+ if (pb instanceof COSDictionary)
{
pb = parseCOSStream((COSDictionary) pb);
- }
- else
+ }
+ else
{
// this is not legal
// the combination of a dict and the stream/endstream forms a complete stream object
@@ -254,9 +254,9 @@ public class VisualSignatureParser exten
pb.setNeedToBeUpdate(true);
pdfObject.setObject(pb);
- if(!endObjectKey.equals("endobj"))
+ if (!endObjectKey.equals("endobj"))
{
- if(endObjectKey.startsWith("endobj"))
+ if (endObjectKey.startsWith("endobj"))
{
/*
* Some PDF files don't contain a new line after endobj so we
@@ -265,25 +265,25 @@ public class VisualSignatureParser exten
* instead of "endobj"
*/
pdfSource.unread(endObjectKey.substring(6).getBytes());
- }
- else if(!pdfSource.isEOF())
+ }
+ else if (!pdfSource.isEOF())
{
- try
+ try
{
//It is possible that the endobj is missing, there
//are several PDFs out there that do that so skip it and move on.
Float.parseFloat(endObjectKey);
pdfSource.unread(COSWriter.SPACE);
pdfSource.unread(endObjectKey.getBytes());
- }
- catch(NumberFormatException e)
+ }
+ catch (NumberFormatException e)
{
//we will try again incase there was some garbage which
//some writers will leave behind.
String secondEndObjectKey = readString();
- if(!secondEndObjectKey.equals("endobj"))
+ if (!secondEndObjectKey.equals("endobj"))
{
- if(isClosing())
+ if (isClosing())
{
//found a case with 17506.pdf object 41 that was like this
//41 0 obj [/Pattern /DeviceGray] ] endobj
@@ -293,7 +293,7 @@ public class VisualSignatureParser exten
}
skipSpaces();
String thirdPossibleEndObj = readString();
- if(!thirdPossibleEndObj.equals("endobj"))
+ if (!thirdPossibleEndObj.equals("endobj"))
{
throw new IOException("expected='endobj' firstReadAttempt='" + endObjectKey + "' "
+ "secondReadAttempt='" + secondEndObjectKey + "' " + pdfSource, e);