FELIX-3336 Finalized the patch after finally understanding exactly what was going on.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1240500 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStream.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStream.java
index 0051562..7615941 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStream.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStream.java
@@ -73,7 +73,7 @@
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 @@
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 @@
}
}
-
public static void replace(File target, File source) {
delete(target, true);
source.renameTo(target);
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/OutputtingInputStream.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/OutputtingInputStream.java
index e44b92c..ac8fa36 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/OutputtingInputStream.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/OutputtingInputStream.java
@@ -77,9 +77,8 @@
m_outputStream.close();
}
catch (Exception e) {
- // not much we can do
+ // TODO: review the implications of this
}
}
}
-
}
diff --git a/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStreamTest.java b/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStreamTest.java
index 651822c..bbc9ee7 100644
--- a/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStreamTest.java
+++ b/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStreamTest.java
@@ -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 @@
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();
+ }
}