6320
|
1 |
/*
|
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 6531345
|
|
27 |
* @summary check for unpacker memory leaks
|
|
28 |
* @compile -XDignore.symbol.file Utils.java UnpackerMemoryTest.java
|
|
29 |
* @run main/othervm/timeout=1200 -Xmx32m UnpackerMemoryTest
|
|
30 |
* @author ksrini
|
|
31 |
*/
|
|
32 |
|
|
33 |
import java.io.File;
|
|
34 |
import java.io.FileOutputStream;
|
|
35 |
import java.io.PrintStream;
|
|
36 |
import java.io.IOException;
|
|
37 |
import java.util.jar.JarFile;
|
|
38 |
import java.util.jar.JarOutputStream;
|
|
39 |
|
|
40 |
public class UnpackerMemoryTest {
|
|
41 |
|
|
42 |
private static void createPackFile(File packFile) throws IOException {
|
|
43 |
File tFile = new File("test.dat");
|
|
44 |
FileOutputStream fos = null;
|
|
45 |
PrintStream ps = null;
|
|
46 |
String jarFileName = Utils.baseName(packFile, Utils.PACK_FILE_EXT)
|
|
47 |
+ Utils.JAR_FILE_EXT;
|
|
48 |
JarFile jarFile = null;
|
|
49 |
try {
|
|
50 |
fos = new FileOutputStream(tFile);
|
|
51 |
ps = new PrintStream(fos);
|
|
52 |
ps.println("A quick brown fox");
|
|
53 |
Utils.jar("cvf", jarFileName, tFile.getName());
|
|
54 |
jarFile = new JarFile(jarFileName);
|
|
55 |
Utils.pack(jarFile, packFile);
|
|
56 |
} finally {
|
|
57 |
Utils.close(ps);
|
|
58 |
tFile.delete();
|
|
59 |
Utils.close(jarFile);
|
|
60 |
}
|
|
61 |
}
|
|
62 |
|
|
63 |
public static void main(String[] args) throws Exception {
|
|
64 |
String name = "foo";
|
|
65 |
File packFile = new File(name + Utils.PACK_FILE_EXT);
|
|
66 |
createPackFile(packFile);
|
|
67 |
if (!packFile.exists()) {
|
|
68 |
throw new RuntimeException(packFile + " not found");
|
|
69 |
}
|
|
70 |
File jarOut = new File(name + ".out");
|
|
71 |
for (int i = 0; i < 2000; i++) {
|
|
72 |
JarOutputStream jarOS = null;
|
|
73 |
FileOutputStream fos = null;
|
|
74 |
try {
|
|
75 |
fos = new FileOutputStream(jarOut);
|
|
76 |
jarOS = new JarOutputStream(fos);
|
|
77 |
System.out.println("Unpacking[" + i + "]" + packFile);
|
|
78 |
Utils.unpackn(packFile, jarOS);
|
|
79 |
} finally {
|
|
80 |
Utils.close(jarOS);
|
|
81 |
Utils.close(fos);
|
|
82 |
}
|
|
83 |
}
|
|
84 |
}
|
|
85 |
}
|
|
86 |
|