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 2010/04/27 17:46:48 UTC
svn commit: r938529 -
/lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/io/TikaInputStream.java
Author: jukka
Date: Tue Apr 27 15:46:48 2010
New Revision: 938529
URL: http://svn.apache.org/viewvc?rev=938529&view=rev
Log:
TIKA-153: Allow passing of files or memory buffers to parsers
Add support for memory buffers and URL resources and included a getLength() method for retrieving the stream length.
Modified:
lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/io/TikaInputStream.java
Modified: lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/io/TikaInputStream.java
URL: http://svn.apache.org/viewvc/lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/io/TikaInputStream.java?rev=938529&r1=938528&r2=938529&view=diff
==============================================================================
--- lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/io/TikaInputStream.java (original)
+++ lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/io/TikaInputStream.java Tue Apr 27 15:46:48 2010
@@ -16,12 +16,14 @@
*/
package org.apache.tika.io;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.URL;
/**
*
@@ -60,21 +62,34 @@ public class TikaInputStream extends Pro
*/
private boolean temporary;
+ private long length;
+
/**
* Current read position within this stream.
*/
private long position = 0;
- public TikaInputStream(InputStream stream) {
+ private TikaInputStream(InputStream stream, File file, long length) {
super(stream);
- this.file = null;
- this.temporary = true;
+ this.file = file;
+ this.temporary = (file == null);
+ this.length = length;
}
- public TikaInputStream(File file) {
- super(null);
- this.file = file;
- this.temporary = false;
+ public TikaInputStream(InputStream stream) {
+ this(stream, null, -1);
+ }
+
+ public TikaInputStream(byte[] data) {
+ this(new ByteArrayInputStream(data), null, data.length);
+ }
+
+ public TikaInputStream(File file) throws IOException {
+ this(new FileInputStream(file), file, file.length());
+ }
+
+ public TikaInputStream(URL url) throws IOException {
+ this(url.openStream(), null, -1);
}
public File getFile() throws IOException {
@@ -98,6 +113,13 @@ public class TikaInputStream extends Pro
return file;
}
+ public long getLength() throws IOException {
+ if (length == -1) {
+ length = getFile().length();
+ }
+ return length;
+ }
+
@Override
public void close() throws IOException {
if (in != null) {