You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ma...@apache.org on 2012/02/04 14:22:03 UTC

svn commit: r1240500 - in /felix/trunk/deploymentadmin/deploymentadmin/src: main/java/org/apache/felix/deploymentadmin/ test/java/org/apache/felix/deploymentadmin/

Author: marrs
Date: Sat Feb  4 13:22:02 2012
New Revision: 1240500

URL: http://svn.apache.org/viewvc?rev=1240500&view=rev
Log:
FELIX-3336 Finalized the patch after finally understanding exactly what was going on.

Modified:
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStream.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/OutputtingInputStream.java
    felix/trunk/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStreamTest.java

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStream.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStream.java?rev=1240500&r1=1240499&r2=1240500&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStream.java (original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStream.java Sat Feb  4 13:22:02 2012
@@ -73,7 +73,7 @@ class ExplodingOutputtingInputStream ext
         super(inputStream, output);
         m_contentDir = root;
         m_indexFile = index;
-        m_input = new PipedInputStream(output /*, 8 FELIX-3336: if you provide such a small buffer, the error is reproducible (see below) */);
+        m_input = new PipedInputStream(output);
         m_task = new Thread(this, "Apache Felix DeploymentAdmin - ExplodingOutputtingInputStream");
         m_task.start();
     }
@@ -119,21 +119,21 @@ class ExplodingOutputtingInputStream ext
                 input.closeEntry();
                 writer.flush();
             }
-        } catch (IOException ex) {
-            // TODO: log this
+        }
+        catch (IOException ex) {
+            // TODO: review the impact of this happening and how to react
         }
         finally {
-            // FELIX 3336: removed closing of the input stream here, I'm quite sure that was plain wrong
             if (writer != null) {
                 writer.close();
             }
         }
-        // FELIX-3336: if you include this code, the issue is gone
+        
         try {
-            byte[] bb = new byte[512];
-            int c = m_input.read(bb);
+            byte[] buffer = new byte[1024];
+            int c = m_input.read(buffer);
             while (c != -1) {
-                c = m_input.read(bb);
+                c = m_input.read(buffer);
             }
         }
         catch (IOException e) {
@@ -141,7 +141,6 @@ class ExplodingOutputtingInputStream ext
         }
     }
 
-
     public static void replace(File target, File source) {
         delete(target, true);
         source.renameTo(target);

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/OutputtingInputStream.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/OutputtingInputStream.java?rev=1240500&r1=1240499&r2=1240500&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/OutputtingInputStream.java (original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/OutputtingInputStream.java Sat Feb  4 13:22:02 2012
@@ -77,9 +77,8 @@ public class OutputtingInputStream exten
                 m_outputStream.close();
             }
             catch (Exception e) {
-                // not much we can do
+                // TODO: review the implications of this
             }
         }
     }
-
 }

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStreamTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStreamTest.java?rev=1240500&r1=1240499&r2=1240500&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStreamTest.java (original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStreamTest.java Sat Feb  4 13:22:02 2012
@@ -1,8 +1,29 @@
+/*
+ * 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.felix.deploymentadmin;
 
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
@@ -60,4 +81,63 @@ public class ExplodingOutputtingInputStr
         dir.delete();
         tempDir.delete();
     }
+    
+    public void testStreamReadWithJARStream() throws Exception {
+        // fill up a stringbuffer with some test data
+        StringBuffer sb = new StringBuffer();
+        for (int i = 0; i < 1000; i++) {
+            sb.append("DATAdataDATAdata");
+        }
+        String data = sb.toString();
+        
+        // create a temporary folder
+        File tempDir = File.createTempFile("temp", "dir");
+        tempDir.delete();
+        tempDir.mkdirs();
+        System.out.println("Dir: " + tempDir);
+        
+        // create a zip file with two entries in it
+        File jarfile = new File(tempDir, "jarfile");
+        JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarfile));
+        String dummy1 = "dummy";
+        jos.putNextEntry(new JarEntry(dummy1));
+        jos.write(data.getBytes());
+        jos.closeEntry();
+        String dummy2 = "dummy2";
+        jos.putNextEntry(new JarEntry(dummy2));
+        jos.write(data.getBytes());
+        jos.closeEntry();
+        jos.close();
+        
+        // create another temporary folder
+        File dir = new File(tempDir, "dir");
+        dir.mkdirs();
+        File index = new File(tempDir, "list");
+        ExplodingOutputtingInputStream stream = new ExplodingOutputtingInputStream(new FileInputStream(jarfile), index, dir);
+        JarInputStream jarInputStream = new JarInputStream(stream);
+
+        JarEntry entry;
+        while ((entry = jarInputStream.getNextJarEntry()) != null) {
+            int size = 0;
+            byte[] buffer = new byte[4096];
+            for (int i = jarInputStream.read(buffer); i > -1; i = jarInputStream.read(buffer)) {
+                size += i;
+            }
+            System.out.println("read JAR entry: " + entry + " of " + size + " bytes.");
+            jarInputStream.closeEntry();
+        }
+        stream.close();
+        
+        // create references to the unpacked dummy files
+        File d1 = new File(dir, dummy1);
+        File d2 = new File(dir, dummy2);
+        
+        // cleanup
+        jarfile.delete();
+        index.delete();
+        d1.delete();
+        d2.delete();
+        dir.delete();
+        tempDir.delete();
+    }
 }