From: Dominik Stadler Date: Mon, 20 Apr 2015 18:08:24 +0000 (+0000) Subject: Detect if a file is actually PDF instead of .doc similar to how it is already done... X-Git-Tag: REL_3_12_FINAL~53 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=208955bc8cc0b0bba02758d907201d98865d3b25;p=poi.git Detect if a file is actually PDF instead of .doc similar to how it is already done for RTF git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1674951 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java index d8e4109448..04fe38ca38 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java @@ -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);