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
This commit is contained in:
Dominik Stadler 2015-04-20 18:08:24 +00:00
parent 37a7733b45
commit a75cf0b57c

View 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);