aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/java_tools/singlejar
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2015-04-02 17:19:29 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-04-03 20:36:33 +0000
commit4544389bcf149b63579c9ebb59bd0dabe1e0b381 (patch)
tree5d99202cbed590b8cf5cbfd605bc1e997b189c1c /src/java_tools/singlejar
parentfe5754f00dab5c10437dcdf4cb50cc2ac224a42a (diff)
Adds ZipCombiner#addZip(InputStream).
-- MOS_MIGRATED_REVID=90172709
Diffstat (limited to 'src/java_tools/singlejar')
-rw-r--r--src/java_tools/singlejar/java/com/google/devtools/build/singlejar/ZipCombiner.java18
-rw-r--r--src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ZipCombinerTest.java15
2 files changed, 33 insertions, 0 deletions
diff --git a/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/ZipCombiner.java b/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/ZipCombiner.java
index 75dacb92ef..e64d4b82c5 100644
--- a/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/ZipCombiner.java
+++ b/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/ZipCombiner.java
@@ -32,6 +32,8 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -416,6 +418,22 @@ public class ZipCombiner implements AutoCloseable {
* Adds the contents of a ZIP file to the combined ZIP file using the specified
* {@link ZipEntryFilter} to determine the appropriate action for each file.
*
+ * @param in the InputStream of the ZIP file to add to the combined ZIP file
+ * @throws IOException if there is an error reading the ZIP file or writing entries to the
+ * combined ZIP file
+ */
+ @Deprecated
+ public void addZip(InputStream in) throws IOException {
+ File file = Files.createTempFile(null, null).toFile();
+ Files.copy(in, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
+ addZip(file);
+ file.deleteOnExit();
+ }
+
+ /**
+ * Adds the contents of a ZIP file to the combined ZIP file using the specified
+ * {@link ZipEntryFilter} to determine the appropriate action for each file.
+ *
* @param zipFile the ZIP file to add to the combined ZIP file
* @throws IOException if there is an error reading the ZIP file or writing entries to the
* combined ZIP file
diff --git a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ZipCombinerTest.java b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ZipCombinerTest.java
index aba561bfd3..e5e89f0ac1 100644
--- a/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ZipCombinerTest.java
+++ b/src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ZipCombinerTest.java
@@ -72,6 +72,12 @@ public class ZipCombinerTest {
@Rule public TemporaryFolder tmp = new TemporaryFolder();
@Rule public ExpectedException thrown = ExpectedException.none();
+ private InputStream sampleZipStream() {
+ ZipFactory factory = new ZipFactory();
+ factory.addFile("hello.txt", "Hello World!");
+ return factory.toInputStream();
+ }
+
private File sampleZip() throws IOException {
ZipFactory factory = new ZipFactory();
factory.addFile("hello.txt", "Hello World!");
@@ -140,6 +146,15 @@ public class ZipCombinerTest {
assertEntry(zipInput, filename, date.getTime(), content.getBytes(ISO_8859_1));
}
+ @Test public void testInputStreamZip() throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try (ZipCombiner zipCombiner = new ZipCombiner(out)) {
+ zipCombiner.addZip(sampleZipStream());
+ }
+ FakeZipFile expectedResult = new FakeZipFile().addEntry("hello.txt", "Hello World!", true);
+ expectedResult.assertSame(out.toByteArray());
+ }
+
@Test public void testCompressedDontCare() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (ZipCombiner zipCombiner = new ZipCombiner(out)) {