tika-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1222880 - in /tika/trunk/tika-core/src: main/java/org/apache/tika/io/TaggedInputStream.java test/java/org/apache/tika/io/TaggedInputStreamTest.java
Date Fri, 23 Dec 2011 22:50:28 GMT
Author: jukka
Date: Fri Dec 23 22:50:28 2011
New Revision: 1222880

URL: http://svn.apache.org/viewvc?rev=1222880&view=rev
Log:
TIKA-828: TaggedIOException can be passed non Serializable objects

Use a serializable tag in TaggedInputStream/-IOException. See also IO-192.

Test case by Jerome Lacoste.

Added:
    tika/trunk/tika-core/src/test/java/org/apache/tika/io/TaggedInputStreamTest.java   (with
props)
Modified:
    tika/trunk/tika-core/src/main/java/org/apache/tika/io/TaggedInputStream.java

Modified: tika/trunk/tika-core/src/main/java/org/apache/tika/io/TaggedInputStream.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-core/src/main/java/org/apache/tika/io/TaggedInputStream.java?rev=1222880&r1=1222879&r2=1222880&view=diff
==============================================================================
--- tika/trunk/tika-core/src/main/java/org/apache/tika/io/TaggedInputStream.java (original)
+++ tika/trunk/tika-core/src/main/java/org/apache/tika/io/TaggedInputStream.java Fri Dec 23
22:50:28 2011
@@ -18,6 +18,8 @@ package org.apache.tika.io;
 
  import java.io.IOException;
 import java.io.InputStream;
+import java.io.Serializable;
+import java.util.UUID;
 
 /**
  * An input stream decorator that tags potential exceptions so that the
@@ -59,6 +61,11 @@ import java.io.InputStream;
 public class TaggedInputStream extends ProxyInputStream {
 
     /**
+     * The unique (serializable) tag of this stream.
+     */
+    private final Serializable tag = UUID.randomUUID();
+
+    /**
      * Creates a tagging decorator for the given input stream.
      *
      * @param proxy input stream to be decorated
@@ -90,7 +97,7 @@ public class TaggedInputStream extends P
     public boolean isCauseOf(IOException exception) {
         if (exception instanceof TaggedIOException) {
             TaggedIOException tagged = (TaggedIOException) exception;
-            return this == tagged.getTag();
+            return tag.equals(tagged.getTag());
         } else {
             return false;
         }
@@ -109,7 +116,7 @@ public class TaggedInputStream extends P
     public void throwIfCauseOf(Exception exception) throws IOException {
         if (exception instanceof TaggedIOException) {
             TaggedIOException tagged = (TaggedIOException) exception;
-            if (this == tagged.getTag()) {
+            if (tag.equals(tagged.getTag())) {
                 throw tagged.getCause();
             }
         }
@@ -123,10 +130,10 @@ public class TaggedInputStream extends P
      */
     @Override
     protected void handleIOException(IOException e) throws IOException {
-        throw new TaggedIOException(e, this);
+        throw new TaggedIOException(e, tag);
     }
 
     public String toString() {
-        return "Tika Tagged InputStream wrapping " + in.toString(); 
+        return "Tika Tagged InputStream wrapping " + in;
     }
 }

Added: tika/trunk/tika-core/src/test/java/org/apache/tika/io/TaggedInputStreamTest.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-core/src/test/java/org/apache/tika/io/TaggedInputStreamTest.java?rev=1222880&view=auto
==============================================================================
--- tika/trunk/tika-core/src/test/java/org/apache/tika/io/TaggedInputStreamTest.java (added)
+++ tika/trunk/tika-core/src/test/java/org/apache/tika/io/TaggedInputStreamTest.java Fri Dec
23 22:50:28 2011
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.io;
+
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+
+import static org.junit.Assert.fail;
+
+public class TaggedInputStreamTest {
+
+    @Test
+    public void createdIOExceptionIsSerializable() {
+        try {
+            new TaggedInputStream(null).handleIOException(new IOException("Dummy"));
+        } catch (IOException e) {
+            assertCanSerialize(e);
+        }
+    }
+
+    private static void assertCanSerialize(Object e) {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        ObjectOutputStream oos = null;
+        try {
+            oos = new ObjectOutputStream(out);
+            oos.writeObject(e);
+        } catch (IOException e1) {
+            fail(e1.getMessage());
+        } finally {
+            if (oos != null)
+                try {
+                    oos.close();
+                } catch (IOException ignore) {
+                }
+        }
+    }
+
+}
\ No newline at end of file

Propchange: tika/trunk/tika-core/src/test/java/org/apache/tika/io/TaggedInputStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message