27
27
import java .io .InputStream ;
28
28
import java .io .OutputStreamWriter ;
29
29
import java .io .PrintWriter ;
30
+ import java .nio .charset .StandardCharsets ;
30
31
import java .util .ArrayList ;
31
32
import java .util .Collections ;
32
33
import java .util .Comparator ;
37
38
import java .util .SortedMap ;
38
39
import java .util .StringTokenizer ;
39
40
import java .util .TreeMap ;
40
- import java .util .Vector ;
41
41
42
42
import org .apache .commons .compress .archivers .zip .ZipArchiveEntry ;
43
43
import org .apache .commons .compress .archivers .zip .ZipArchiveOutputStream ;
@@ -139,12 +139,12 @@ public class JarArchiver
139
139
* <p/>
140
140
* Will not be filled unless the user has asked for an index.
141
141
*/
142
- private Vector <String > rootEntries ;
142
+ private List <String > rootEntries ;
143
143
144
144
/**
145
145
* Path containing jars that shall be indexed in addition to this archive.
146
146
*/
147
- private ArrayList <String > indexJars ;
147
+ private List <String > indexJars ;
148
148
149
149
/**
150
150
* Creates a minimal default manifest with {@code Manifest-Version: 1.0} only.
@@ -159,7 +159,7 @@ public JarArchiver()
159
159
super ();
160
160
archiveType = "jar" ;
161
161
setEncoding ( "UTF8" );
162
- rootEntries = new Vector < String >();
162
+ rootEntries = new ArrayList < >();
163
163
}
164
164
165
165
/**
@@ -299,7 +299,7 @@ public void addConfiguredIndexJars( File indexJar )
299
299
{
300
300
if ( indexJars == null )
301
301
{
302
- indexJars = new ArrayList <String >();
302
+ indexJars = new ArrayList <>();
303
303
}
304
304
indexJars .add ( indexJar .getAbsolutePath () );
305
305
}
@@ -373,13 +373,14 @@ private void writeManifest( ConcurrentJarCreator zOut, Manifest manifest )
373
373
}
374
374
375
375
zipDir ( null , zOut , "META-INF/" , DEFAULT_DIR_MODE , getEncoding () );
376
+
376
377
// time to write the manifest
377
- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
378
+ ByteArrayOutputStream baos = new ByteArrayOutputStream ( 128 );
378
379
manifest .write ( baos );
380
+ InputStreamSupplier in = () -> new ByteArrayInputStream ( baos .toByteArray () );
379
381
380
- ByteArrayInputStream bais = new ByteArrayInputStream ( baos .toByteArray () );
381
- super .zipFile ( createInputStreamSupplier ( bais ), zOut , MANIFEST_NAME , System .currentTimeMillis (), null ,
382
- DEFAULT_FILE_MODE , null , false );
382
+ super .zipFile ( in , zOut , MANIFEST_NAME , System .currentTimeMillis (), null , DEFAULT_FILE_MODE , null ,
383
+ false );
383
384
super .initZipOutputStream ( zOut );
384
385
}
385
386
@@ -408,9 +409,9 @@ protected void finalizeZipOutputStream( ConcurrentJarCreator zOut )
408
409
private void createIndexList ( ConcurrentJarCreator zOut )
409
410
throws IOException , ArchiverException
410
411
{
411
- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
412
+ ByteArrayOutputStream baos = new ByteArrayOutputStream ( 128 );
412
413
// encoding must be UTF8 as specified in the specs.
413
- PrintWriter writer = new PrintWriter ( new OutputStreamWriter ( baos , "UTF8" ) );
414
+ PrintWriter writer = new PrintWriter ( new OutputStreamWriter ( baos , StandardCharsets . UTF_8 ) );
414
415
415
416
// version-info blankline
416
417
writer .println ( "JarIndex-Version: 1.0" );
@@ -440,7 +441,7 @@ private void createIndexList( ConcurrentJarCreator zOut )
440
441
filteredDirs .remove ( META_INF_NAME + '/' );
441
442
}
442
443
}
443
- writeIndexLikeList ( new ArrayList <String >( filteredDirs ), rootEntries , writer );
444
+ writeIndexLikeList ( new ArrayList <>( filteredDirs ), rootEntries , writer );
444
445
writer .println ();
445
446
446
447
if ( indexJars != null )
@@ -464,8 +465,8 @@ private void createIndexList( ConcurrentJarCreator zOut )
464
465
String name = findJarName ( indexJar , cpEntries );
465
466
if ( name != null )
466
467
{
467
- ArrayList <String > dirs = new ArrayList <String >();
468
- ArrayList <String > files = new ArrayList <String >();
468
+ List <String > dirs = new ArrayList <>();
469
+ List <String > files = new ArrayList <>();
469
470
grabFilesAndDirs ( indexJar , dirs , files );
470
471
if ( dirs .size () + files .size () > 0 )
471
472
{
@@ -479,9 +480,9 @@ private void createIndexList( ConcurrentJarCreator zOut )
479
480
480
481
writer .flush ();
481
482
482
- ByteArrayInputStream bais = new ByteArrayInputStream ( baos .toByteArray () );
483
+ InputStreamSupplier in = () -> new ByteArrayInputStream ( baos .toByteArray () );
483
484
484
- super .zipFile ( createInputStreamSupplier ( bais ) , zOut , INDEX_NAME , System .currentTimeMillis (), null ,
485
+ super .zipFile ( in , zOut , INDEX_NAME , System .currentTimeMillis (), null ,
485
486
DEFAULT_FILE_MODE , null , true );
486
487
}
487
488
@@ -511,9 +512,9 @@ else if ( INDEX_NAME.equalsIgnoreCase( vPath ) && index )
511
512
}
512
513
else
513
514
{
514
- if ( index && ( !vPath .contains ( "/" ) ) )
515
+ if ( index && !vPath .contains ( "/" ) )
515
516
{
516
- rootEntries .addElement ( vPath );
517
+ rootEntries .add ( vPath );
517
518
}
518
519
super .zipFile ( is , zOut , vPath , lastModified , fromArchive , mode , symlinkDestination , addInParallel );
519
520
}
@@ -624,7 +625,7 @@ protected void cleanUp()
624
625
filesetManifest = null ;
625
626
originalManifest = null ;
626
627
}
627
- rootEntries .removeAllElements ();
628
+ rootEntries .clear ();
628
629
}
629
630
630
631
/**
@@ -722,21 +723,9 @@ protected static String findJarName( String fileName, String[] classpath )
722
723
return new File ( fileName ).getName ();
723
724
}
724
725
fileName = fileName .replace ( File .separatorChar , '/' );
725
- SortedMap <String , String > matches = new TreeMap <String , String >( new Comparator <String >()
726
- {
727
-
728
- // longest match comes first
729
- @ Override
730
- public int compare ( String o1 , String o2 )
731
- {
732
- if ( ( o1 != null ) && ( o2 != null ) )
733
- {
734
- return o2 .length () - o1 .length ();
735
- }
736
- return 0 ;
737
- }
738
726
739
- } );
727
+ // longest match comes first
728
+ SortedMap <String , String > matches = new TreeMap <>( Comparator .comparingInt ( String ::length ).reversed () );
740
729
741
730
for ( String aClasspath : classpath )
742
731
{
0 commit comments