Author: nick
Date: Wed Oct 28 23:21:41 2015
New Revision: 1711162

URL: http://svn.apache.org/viewvc?rev=1711162&view=rev
Log:
Add Tika Facade parse methods for Path and File which take a Metadata object, 
to mirror the existing InputStream one. This closes #60 from GitHub

Modified:
    tika/trunk/CHANGES.txt
    tika/trunk/tika-core/src/main/java/org/apache/tika/Tika.java

Modified: tika/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/tika/trunk/CHANGES.txt?rev=1711162&r1=1711161&r2=1711162&view=diff
==============================================================================
--- tika/trunk/CHANGES.txt (original)
+++ tika/trunk/CHANGES.txt Wed Oct 28 23:21:41 2015
@@ -5,6 +5,9 @@ Release 1.12 - Current Development
 
   * Fix regression with spacing in PPT via Andreas Beeker (TIKA-1777).
 
+  * Tika Facade parse methods for Path and File added which take a
+    Metadata object, to mirror the existing InputStream one (GitHub-60)
+
 
 Release 1.11 - 10/18/2015
 

Modified: tika/trunk/tika-core/src/main/java/org/apache/tika/Tika.java
URL: 
http://svn.apache.org/viewvc/tika/trunk/tika-core/src/main/java/org/apache/tika/Tika.java?rev=1711162&r1=1711161&r2=1711162&view=diff
==============================================================================
--- tika/trunk/tika-core/src/main/java/org/apache/tika/Tika.java (original)
+++ tika/trunk/tika-core/src/main/java/org/apache/tika/Tika.java Wed Oct 28 
23:21:41 2015
@@ -283,7 +283,8 @@ public class Tika {
      */
     public String detect(File file) throws IOException {
         Metadata metadata = new Metadata();
-        try (InputStream stream = TikaInputStream.get(file, metadata)) {
+        try (@SuppressWarnings("deprecation")
+        InputStream stream = TikaInputStream.get(file, metadata)) {
             return detect(stream, metadata);
         }
     }
@@ -399,7 +400,7 @@ public class Tika {
      * the time when the {@link Reader#close()} method is called.
      *
      * @param stream the document to be parsed
-     * @param metadata document metadata
+     * @param metadata where document's metadata will be populated
      * @return extracted text content
      * @throws IOException if the document can not be read or parsed
      */
@@ -427,32 +428,62 @@ public class Tika {
 
     /**
      * Parses the file at the given path and returns the extracted text 
content.
+     * <p>
+     * Metadata information extracted from the document is returned in 
+     *  the supplied metadata instance.
      *
      * @param path the path of the file to be parsed
+     * @param metadata where document's metadata will be populated
      * @return extracted text content
      * @throws IOException if the file can not be read or parsed
      */
-    public Reader parse(Path path) throws IOException {
-        Metadata metadata = new Metadata();
+    public Reader parse(Path path, Metadata metadata) throws IOException {
         InputStream stream = TikaInputStream.get(path, metadata);
         return parse(stream, metadata);
     }
+    
+    /**
+     * Parses the file at the given path and returns the extracted text 
content.
+     *
+     * @param path the path of the file to be parsed
+     * @return extracted text content
+     * @throws IOException if the file can not be read or parsed
+     */
+    public Reader parse(Path path) throws IOException {
+        return parse(path, new Metadata());
+    }
 
     /**
      * Parses the given file and returns the extracted text content.
+     * <p>
+     * Metadata information extracted from the document is returned in 
+     *  the supplied metadata instance.
      *
      * @param file the file to be parsed
+     * @param metadata where document's metadata will be populated
      * @return extracted text content
      * @throws IOException if the file can not be read or parsed
      * @see #parse(Path)
      */
-    public Reader parse(File file) throws IOException {
-        Metadata metadata = new Metadata();
+    public Reader parse(File file, Metadata metadata) throws IOException {
+        @SuppressWarnings("deprecation")
         InputStream stream = TikaInputStream.get(file, metadata);
         return parse(stream, metadata);
     }
 
     /**
+     * Parses the given file and returns the extracted text content.
+     *
+     * @param file the file to be parsed
+     * @return extracted text content
+     * @throws IOException if the file can not be read or parsed
+     * @see #parse(Path)
+     */
+    public Reader parse(File file) throws IOException {
+        return parse(file, new Metadata());
+    }
+    
+    /**
      * Parses the resource at the given URL and returns the extracted
      * text content.
      *
@@ -606,6 +637,7 @@ public class Tika {
      */
     public String parseToString(File file) throws IOException, TikaException {
         Metadata metadata = new Metadata();
+        @SuppressWarnings("deprecation")
         InputStream stream = TikaInputStream.get(file, metadata);
         return parseToString(stream, metadata);
     }


Reply via email to