You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2015/04/20 20:08:24 UTC

svn commit: r1674951 - /poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java

Author: centic
Date: Mon Apr 20 18:08:24 2015
New Revision: 1674951

URL: http://svn.apache.org/r1674951
Log:
Detect if a file is actually PDF instead of .doc similar to how it is already done for RTF

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java?rev=1674951&r1=1674950&r2=1674951&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java Mon Apr 20 18:08:24 2015
@@ -85,7 +85,7 @@ public abstract class HWPFDocumentCore e
   }
 
   /**
-   * Takens an InputStream, verifies that it's not RTF, builds a
+   * Takens an InputStream, verifies that it's not RTF or PDF, builds a
    *  POIFSFileSystem from it, and returns that.
    */
   public static POIFSFileSystem verifyAndBuildPOIFS(InputStream istream) throws IOException {
@@ -98,9 +98,11 @@ public abstract class HWPFDocumentCore e
 	if(first6[0] == '{' && first6[1] == '\\' && first6[2] == 'r'
 		&& first6[3] == 't' && first6[4] == 'f') {
 		throw new IllegalArgumentException("The document is really a RTF file");
+	} else if(first6[0] == '%' && first6[1] == 'P' && first6[2] == 'D' && first6[3] == 'F' ) {
+		throw new IllegalArgumentException("The document is really a PDF file");
 	}
 
-	// OK, so it's not RTF
+	// OK, so it's neither RTF nor PDF
 	// Open a POIFSFileSystem on the (pushed back) stream
 	pis.unread(first6);
 	return new POIFSFileSystem(pis);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org