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 2011/09/01 14:34:55 UTC
svn commit: r1164049 - in
/tika/trunk/tika-core/src/main/java/org/apache/tika: Tika.java
parser/ParsingReader.java
Author: jukka
Date: Thu Sep 1 12:34:54 2011
New Revision: 1164049
URL: http://svn.apache.org/viewvc?rev=1164049&view=rev
Log:
TIKA-701: Fix problems with TemporaryFiles
Better documentation (and use) of streams in the Tika facade
Modified:
tika/trunk/tika-core/src/main/java/org/apache/tika/Tika.java
tika/trunk/tika-core/src/main/java/org/apache/tika/parser/ParsingReader.java
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=1164049&r1=1164048&r2=1164049&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 Thu Sep 1 12:34:54 2011
@@ -197,7 +197,12 @@ public class Tika {
*/
public String detect(byte[] prefix, String name) {
try {
- return detect(TikaInputStream.get(prefix), name);
+ InputStream stream = TikaInputStream.get(prefix);
+ try {
+ return detect(stream, name);
+ } finally {
+ stream.close();
+ }
} catch (IOException e) {
throw new IllegalStateException("Unexpected IOException", e);
}
@@ -218,7 +223,12 @@ public class Tika {
*/
public String detect(byte[] prefix) {
try {
- return detect(TikaInputStream.get(prefix));
+ InputStream stream = TikaInputStream.get(prefix);
+ try {
+ return detect(stream);
+ } finally {
+ stream.close();
+ }
} catch (IOException e) {
throw new IllegalStateException("Unexpected IOException", e);
}
@@ -284,8 +294,13 @@ public class Tika {
* Input metadata like a file name or a content type hint can be passed
* in the given metadata instance. Metadata information extracted from
* the document is returned in that same metadata instance.
+ * <p>
+ * The returned reader will be responsible for closing the given stream.
+ * The stream and any associated resources will be closed at or before
+ * the time when the {@link Reader#close()} method is called.
*
* @param stream the document to be parsed
+ * @param metadata document metadata
* @return extracted text content
* @throws IOException if the document can not be read or parsed
*/
@@ -298,6 +313,10 @@ public class Tika {
/**
* Parses the given document and returns the extracted text content.
+ * <p>
+ * The returned reader will be responsible for closing the given stream.
+ * The stream and any associated resources will be closed at or before
+ * the time when the {@link Reader#close()} method is called.
*
* @param stream the document to be parsed
* @return extracted text content
@@ -340,6 +359,11 @@ public class Tika {
* only up to {@link #getMaxStringLength()} first characters extracted
* from the input document. Use the {@link #setMaxStringLength(int)}
* method to adjust this limitation.
+ * <p>
+ * <strong>NOTE:</strong> Unlike most other Tika methods that taken an
+ * {@link InputStream}, this method will close the given stream for
+ * you as a convenience. With other methods you are still responsible
+ * for closing the stream or a wrapper instance returned by Tika.
*
* @param stream the document to be parsed
* @param metadata document metadata
@@ -375,6 +399,11 @@ public class Tika {
* only up to {@link #getMaxStringLength()} first characters extracted
* from the input document. Use the {@link #setMaxStringLength(int)}
* method to adjust this limitation.
+ * <p>
+ * <strong>NOTE:</strong> Unlike most other Tika methods that taken an
+ * {@link InputStream}, this method will close the given stream for
+ * you as a convenience. With other methods you are still responsible
+ * for closing the stream or a wrapper instance returned by Tika.
*
* @param stream the document to be parsed
* @return extracted text content
Modified: tika/trunk/tika-core/src/main/java/org/apache/tika/parser/ParsingReader.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-core/src/main/java/org/apache/tika/parser/ParsingReader.java?rev=1164049&r1=1164048&r2=1164049&view=diff
==============================================================================
--- tika/trunk/tika-core/src/main/java/org/apache/tika/parser/ParsingReader.java (original)
+++ tika/trunk/tika-core/src/main/java/org/apache/tika/parser/ParsingReader.java Thu Sep 1 12:34:54 2011
@@ -131,6 +131,10 @@ public class ParsingReader extends Reade
* Creates a reader for the text content of the given binary stream
* with the given document metadata. The given parser is used for
* parsing. A new background thread is started for the parsing task.
+ * <p>
+ * The created reader will be responsible for closing the given stream.
+ * The stream and any associated resources will be closed at or before
+ * the time when the {@link #close()} method is called on this reader.
*
* @param parser parser instance
* @param stream binary stream
@@ -162,6 +166,10 @@ public class ParsingReader extends Reade
* <em>must</em> run the parsing task asynchronously in a separate thread,
* since the current thread must return to the caller that can then
* consume the parsed text through the {@link Reader} interface.
+ * <p>
+ * The created reader will be responsible for closing the given stream.
+ * The stream and any associated resources will be closed at or before
+ * the time when the {@link #close()} method is called on this reader.
*
* @param parser parser instance
* @param stream binary stream