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