You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ju...@apache.org on 2009/02/01 02:19:51 UTC

svn commit: r739673 - /lucene/tika/trunk/src/main/java/org/apache/tika/mime/MimeTypes.java

Author: jukka
Date: Sun Feb  1 01:19:51 2009
New Revision: 739673

URL: http://svn.apache.org/viewvc?rev=739673&view=rev
Log:
TIKA-95: Pluggable magic header detectors

Allow the input stream to be null also in the MimeTypes detector.

Modified:
    lucene/tika/trunk/src/main/java/org/apache/tika/mime/MimeTypes.java

Modified: lucene/tika/trunk/src/main/java/org/apache/tika/mime/MimeTypes.java
URL: http://svn.apache.org/viewvc/lucene/tika/trunk/src/main/java/org/apache/tika/mime/MimeTypes.java?rev=739673&r1=739672&r2=739673&view=diff
==============================================================================
--- lucene/tika/trunk/src/main/java/org/apache/tika/mime/MimeTypes.java (original)
+++ lucene/tika/trunk/src/main/java/org/apache/tika/mime/MimeTypes.java Sun Feb  1 01:19:51 2009
@@ -436,22 +436,24 @@
      * can reset the stream to the position it was in before this method
      * was called.
      *
-     * @param stream document stream
+     * @param stream document stream, or <code>null</code>
      * @param metadata metadata hints
      * @return MIME type of the document
      * @throws IOException if the document stream could not be read
      */
     public MediaType detect(InputStream input, Metadata metadata)
             throws IOException {
-        MimeType type;
+        MimeType type = root;
 
         // Get type based on magic prefix
-        input.mark(getMinLength());
-        try {
-            byte[] prefix = readMagicHeader(input);
-            type = getMimeType(prefix);
-        } finally {
-            input.reset();
+        if (input != null) {
+            input.mark(getMinLength());
+            try {
+                byte[] prefix = readMagicHeader(input);
+                type = getMimeType(prefix);
+            } finally {
+                input.reset();
+            }
         }
 
         // Get type based on resourceName hint (if available)