0N/A/*
2362N/A * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Aimport java.net.*;
0N/Aimport java.io.*;
0N/A
0N/Apublic class Test {
0N/A
0N/A public static void main(String[] args)
0N/A throws Exception {
0N/A String BASE_DIR = args[0];
0N/A String ARCHIVE_NAME = args[1];
0N/A String lProperty = System.getProperty( "do.iterations", "5000" );
0N/A int lRepetitions = new Integer( lProperty ).intValue();
0N/A System.out.println ( "Start creating copys of the archive, " + lRepetitions + " times" );
0N/A for( int i = 0; i < lRepetitions; i++ ) {
0N/A // Copy the given jar file and add a prefix
0N/A copyFile( BASE_DIR, ARCHIVE_NAME, i);
0N/A }
0N/A System.out.println ( "Start opening the archives archive, " + lRepetitions + " times" );
0N/A System.out.println ( "First URL is jar:file://" + BASE_DIR + "1" + ARCHIVE_NAME + "!/foo/Test.class");
0N/A for( int i = 0; i < lRepetitions; i++ ) {
0N/A // Create ULR
0N/A String lURLPath = "jar:file://" + BASE_DIR + i + ARCHIVE_NAME + "!/foo/Test.class";
0N/A URL lURL = new URL( lURLPath );
0N/A // Open URL Connection
0N/A try {
0N/A URLConnection lConnection = lURL.openConnection();
0N/A lConnection.getInputStream();
0N/A } catch( java.io.FileNotFoundException fnfe ) {
0N/A // Ignore this one because we expect this one
0N/A } catch( java.util.zip.ZipException ze ) {
0N/A throw new RuntimeException ("Test failed: " + ze.getMessage());
0N/A }
0N/A }
0N/A //System.out.println ( "Done testing, waiting 20 seconds for checking" );
0N/A //System.out.println ( "Cleaning up");
0N/A //for( int i = 0; i < lRepetitions; i++ ) {
0N/A // Copy the given jar file and add a prefix
0N/A //deleteFile( BASE_DIR, i, ARCHIVE_NAME);
0N/A ////}
0N/A }
0N/A
0N/A private static void deleteFile (String BASE_DIR, int pIndex, String pArchiveName) {
0N/A java.io.File file = new java.io.File (BASE_DIR, pIndex + pArchiveName );
0N/A file.delete ();
0N/A }
0N/A
0N/A private static void copyFile( String pBaseDir, String pArchiveName, int pIndex) {
0N/A try {
0N/A java.io.File lSource = new java.io.File( pBaseDir, pArchiveName );
0N/A java.io.File lDestination = new java.io.File( pBaseDir, pIndex + pArchiveName );
0N/A if( !lDestination.exists() ) {
0N/A lDestination.createNewFile();
0N/A java.io.InputStream lInput = new java.io.FileInputStream( lSource );
0N/A java.io.OutputStream lOutput = new java.io.FileOutputStream( lDestination );
0N/A byte[] lBuffer = new byte[ 1024 ];
0N/A int lLength = -1;
0N/A while( ( lLength = lInput.read( lBuffer ) ) > 0 ) {
0N/A lOutput.write( lBuffer, 0, lLength );
0N/A }
0N/A lInput.close();
0N/A lOutput.close();
0N/A }
0N/A } catch( Exception e ) {
0N/A e.printStackTrace();
0N/A }
0N/A }
0N/A}