You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2009/01/06 22:57:24 UTC
svn commit: r732135 -
/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/filter/ASCIIHexFilter.java
Author: lehmi
Date: Tue Jan 6 13:57:24 2009
New Revision: 732135
URL: http://svn.apache.org/viewvc?rev=732135&view=rev
Log:
PDFBOX-390: applying patch from Mathias Bosch for skipping whitespaces within the ASCIIHexDecodeFilter
Modified:
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/filter/ASCIIHexFilter.java
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/filter/ASCIIHexFilter.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/filter/ASCIIHexFilter.java?rev=732135&r1=732134&r2=732135&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/filter/ASCIIHexFilter.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/filter/ASCIIHexFilter.java Tue Jan 6 13:57:24 2009
@@ -34,20 +34,56 @@
{
/**
- * {@inheritDoc}
+ * Whitespace
+ * 0 0x00 Null (NUL)
+ * 9 0x09 Tab (HT)
+ * 10 0x0A Line feed (LF)
+ * 12 0x0C Form feed (FF)
+ * 13 0x0D Carriage return (CR)
+ * 32 0x20 Space (SP)
*/
- public void decode( InputStream compressedData, OutputStream result, COSDictionary options, int filterIndex ) throws IOException
+
+ protected boolean isWhitespace(int c)
+ {
+ return c == 0 || c == 9 || c == 10 || c == 12 || c == 13 || c == 32;
+ }
+
+ protected boolean isEOD(int c)
{
- int value =0;
+ return (c == 62); // '>' - EOD
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void decode( InputStream compressedData, OutputStream result, COSDictionary options, int filterIndex ) throws IOException
+ {
+ int value = 0;
int firstByte = 0;
int secondByte = 0;
- while( (firstByte = compressedData.read()) != -1 )
+ while ((firstByte = compressedData.read()) != -1)
{
+ // always after first char
+ while(isWhitespace(firstByte))
+ firstByte = compressedData.read();
+ if(isEOD(firstByte))
+ break;
+
+ if(REVERSE_HEX[firstByte] == -1)
+ System.out.println("Invalid Hex Code; int: " + firstByte + " char: " + (char) firstByte);
value = REVERSE_HEX[firstByte] * 16;
secondByte = compressedData.read();
- if( secondByte >= 0 )
+
+ if(isEOD(secondByte)) {
+ // second value behaves like 0 in case of EOD
+ result.write( value );
+ break;
+ }
+ if(secondByte >= 0)
{
- value += REVERSE_HEX[ secondByte ];
+ if(REVERSE_HEX[secondByte] == -1)
+ System.out.println("Invalid Hex Code; int: " + secondByte + " char: " + (char) secondByte);
+ value += REVERSE_HEX[secondByte];
}
result.write( value );
}