Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/URLConnection/6212146/Test.java
41153 views
1
/*
2
* Copyright (c) 2006, 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
import java.net.URL;
25
import java.net.URLConnection;
26
import java.nio.file.Paths;
27
28
public class Test {
29
30
public static void main(String[] args)
31
throws Exception {
32
String baseDir = args[0];
33
String archiveName = args[1];
34
String lProperty = System.getProperty("do.iterations", "5000");
35
int lRepetitions = Integer.valueOf(lProperty);
36
System.out.println("Start creating copys of the archive, "
37
+ lRepetitions + " times");
38
for (int i = 0; i < lRepetitions; i++) {
39
// Copy the given jar file and add a prefix
40
copyFile(baseDir, archiveName, i);
41
}
42
System.out.println("Start opening the archives archive, "
43
+ lRepetitions + " times");
44
System.out.println("First URL is jar:" + Paths.get(baseDir,
45
0 + archiveName).toUri() + "!/foo/Test.class");
46
for (int i = 0; i < lRepetitions; i++) {
47
// Create URL
48
String lURLPath = "jar:" + Paths.get(baseDir, i
49
+ archiveName).toUri() + "!/foo/Test.class";
50
URL lURL = new URL(lURLPath);
51
// Open URL Connection
52
try {
53
URLConnection lConnection = lURL.openConnection();
54
lConnection.getInputStream();
55
} catch (java.io.FileNotFoundException fnfe) {
56
// Ignore this one because we expect this one
57
} catch (java.util.zip.ZipException ze) {
58
throw new RuntimeException("Test failed: " + ze.getMessage());
59
}
60
}
61
}
62
63
private static void copyFile( String pBaseDir, String pArchiveName, int pIndex) {
64
try {
65
java.io.File lSource = new java.io.File( pBaseDir, pArchiveName );
66
java.io.File lDestination = new java.io.File( pBaseDir, pIndex + pArchiveName );
67
if( !lDestination.exists() ) {
68
lDestination.createNewFile();
69
java.io.InputStream lInput = new java.io.FileInputStream( lSource );
70
java.io.OutputStream lOutput = new java.io.FileOutputStream( lDestination );
71
byte[] lBuffer = new byte[ 1024 ];
72
int lLength = -1;
73
while( ( lLength = lInput.read( lBuffer ) ) > 0 ) {
74
lOutput.write( lBuffer, 0, lLength );
75
}
76
lInput.close();
77
lOutput.close();
78
}
79
} catch( Exception e ) {
80
e.printStackTrace();
81
}
82
}
83
}
84
85