2674N/A/*
2674N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2674N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2674N/A *
2674N/A * This code is free software; you can redistribute it and/or modify it
2674N/A * under the terms of the GNU General Public License version 2 only, as
2674N/A * published by the Free Software Foundation.
2674N/A *
2674N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2674N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2674N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2674N/A * version 2 for more details (a copy is included in the LICENSE file that
2674N/A * accompanied this code).
2674N/A *
2674N/A * You should have received a copy of the GNU General Public License version
2674N/A * 2 along with this work; if not, write to the Free Software Foundation,
2674N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2674N/A *
2674N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2674N/A * or visit www.oracle.com if you need additional information or have any
2674N/A * questions.
2674N/A */
2674N/A
2674N/A/*
2674N/A * @test
2674N/A * @bug 6531345
2674N/A * @summary check for unpacker memory leaks
2674N/A * @compile -XDignore.symbol.file Utils.java UnpackerMemoryTest.java
2674N/A * @run main/othervm/timeout=1200 -Xmx32m UnpackerMemoryTest
2674N/A * @author ksrini
2674N/A */
2674N/A
2674N/Aimport java.io.File;
2674N/Aimport java.io.FileOutputStream;
2674N/Aimport java.io.PrintStream;
2674N/Aimport java.io.IOException;
2674N/Aimport java.util.jar.JarFile;
2674N/Aimport java.util.jar.JarOutputStream;
2674N/A
2674N/Apublic class UnpackerMemoryTest {
2674N/A
2674N/A private static void createPackFile(File packFile) throws IOException {
2674N/A File tFile = new File("test.dat");
2674N/A FileOutputStream fos = null;
2674N/A PrintStream ps = null;
2674N/A String jarFileName = Utils.baseName(packFile, Utils.PACK_FILE_EXT)
2674N/A + Utils.JAR_FILE_EXT;
2674N/A JarFile jarFile = null;
2674N/A try {
2674N/A fos = new FileOutputStream(tFile);
2674N/A ps = new PrintStream(fos);
2674N/A ps.println("A quick brown fox");
2674N/A Utils.jar("cvf", jarFileName, tFile.getName());
2674N/A jarFile = new JarFile(jarFileName);
2674N/A Utils.pack(jarFile, packFile);
2674N/A } finally {
2674N/A Utils.close(ps);
2674N/A tFile.delete();
2674N/A Utils.close(jarFile);
2674N/A }
2674N/A }
2674N/A
2674N/A public static void main(String[] args) throws Exception {
2674N/A String name = "foo";
2674N/A File packFile = new File(name + Utils.PACK_FILE_EXT);
2674N/A createPackFile(packFile);
2674N/A if (!packFile.exists()) {
2674N/A throw new RuntimeException(packFile + " not found");
2674N/A }
2674N/A File jarOut = new File(name + ".out");
2674N/A for (int i = 0; i < 2000; i++) {
2674N/A JarOutputStream jarOS = null;
2674N/A FileOutputStream fos = null;
2674N/A try {
2674N/A fos = new FileOutputStream(jarOut);
2674N/A jarOS = new JarOutputStream(fos);
2674N/A System.out.println("Unpacking[" + i + "]" + packFile);
2674N/A Utils.unpackn(packFile, jarOS);
2674N/A } finally {
2674N/A Utils.close(jarOS);
2674N/A Utils.close(fos);
2674N/A }
2674N/A }
2674N/A }
2674N/A}
2674N/A