]> source.dussan.org Git - poi.git/commitdiff
Detect if a file is actually PDF instead of .doc similar to how it is already done...
authorDominik Stadler <centic@apache.org>
Mon, 20 Apr 2015 18:08:24 +0000 (18:08 +0000)
committerDominik Stadler <centic@apache.org>
Mon, 20 Apr 2015 18:08:24 +0000 (18:08 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1674951 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java

index d8e4109448d267e4b5f79be4adea861d355514cb..04fe38ca3829000e5f590df8bf3faef46fbfdd9d 100644 (file)
@@ -85,7 +85,7 @@ public abstract class HWPFDocumentCore extends POIDocument
   }
 
   /**
-   * 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 extends POIDocument
        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);