aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/ijar/test/GenZipWithEntries.java
diff options
context:
space:
mode:
authorGravatar Liam Miller-Cushon <cushon@google.com>2015-12-03 18:23:09 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-12-03 18:39:00 +0000
commit220be7a7362bb27f3a23b2328b36d1a55f6f9197 (patch)
tree559e6c9a458305c84b28c191265413cf2c5c2662 /third_party/ijar/test/GenZipWithEntries.java
parent188d8eb7838ecc8aeaa9ba146908e2ad2db7de03 (diff)
Add zip64 support to ijar
This allows ijar to process jars with >65535 entries. -- MOS_MIGRATED_REVID=109321374
Diffstat (limited to 'third_party/ijar/test/GenZipWithEntries.java')
-rw-r--r--third_party/ijar/test/GenZipWithEntries.java64
1 files changed, 64 insertions, 0 deletions
diff --git a/third_party/ijar/test/GenZipWithEntries.java b/third_party/ijar/test/GenZipWithEntries.java
new file mode 100644
index 0000000000..1654e7abc3
--- /dev/null
+++ b/third_party/ijar/test/GenZipWithEntries.java
@@ -0,0 +1,64 @@
+// Copyright 2015 The Bazel Authors. All rights reserved.
+//
+// Licensed 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 test;
+
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.jar.JarOutputStream;
+import java.util.zip.ZipEntry;
+
+/**
+ * Generates a jar file with the specified number of .class entries.
+ *
+ * usage: GenZipWithEntries <number of zip entries> <output file>
+ */
+public class GenZipWithEntries {
+
+ public static void main(String[] args) throws IOException {
+ int entries = Integer.parseInt(args[0]);
+ Path out = Paths.get(args[1]);
+ try (OutputStream os = Files.newOutputStream(out);
+ JarOutputStream jos = new JarOutputStream(os)) {
+ for (int i = 1; i <= entries; i++) {
+ String name = String.format("Test%d", i);
+ jos.putNextEntry(new ZipEntry(String.format("%s.class", name)));
+ jos.write(dump(name));
+ }
+ }
+ }
+
+ public static byte[] dump(String name) {
+ ClassWriter cw = new ClassWriter(0);
+ cw.visit(52, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, name, null, "java/lang/Object", null);
+ {
+ MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
+ mv.visitCode();
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
+ mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
+ mv.visitInsn(Opcodes.RETURN);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+ }
+ cw.visitEnd();
+ return cw.toByteArray();
+ }
+}