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