17
17
* limitations under the License.
18
18
*/
19
19
20
- import java . io .* ;
21
- import java . util .* ;
22
- import java . util . concurrent . ExecutionException ;
23
- import java . util . zip .CRC32 ;
24
-
25
- import org .apache .commons .compress .archivers .zip .* ;
20
+ import org . apache . commons . compress . archivers . zip . InputStreamSupplier ;
21
+ import org . apache . commons . compress . archivers . zip . ParallelScatterZipCreator ;
22
+ import org . apache . commons . compress . archivers . zip . ZipArchiveEntry ;
23
+ import org . apache . commons . compress . archivers . zip .ZipArchiveOutputStream ;
24
+ import org . apache . commons . compress . archivers . zip . ZipEncoding ;
25
+ import org .apache .commons .compress .archivers .zip .ZipEncodingHelper ;
26
26
import org .codehaus .plexus .archiver .AbstractArchiver ;
27
27
import org .codehaus .plexus .archiver .ArchiveEntry ;
28
28
import org .codehaus .plexus .archiver .Archiver ;
36
36
import org .codehaus .plexus .util .IOUtil ;
37
37
38
38
import javax .annotation .WillClose ;
39
+ import java .io .ByteArrayInputStream ;
40
+ import java .io .File ;
41
+ import java .io .FileOutputStream ;
42
+ import java .io .IOException ;
43
+ import java .io .InputStream ;
44
+ import java .io .OutputStream ;
45
+ import java .io .SequenceInputStream ;
46
+ import java .util .Hashtable ;
47
+ import java .util .Stack ;
48
+ import java .util .concurrent .ExecutionException ;
49
+ import java .util .zip .CRC32 ;
39
50
40
51
import static org .codehaus .plexus .archiver .util .Streams .bufferedOutputStream ;
41
52
import static org .codehaus .plexus .archiver .util .Streams .fileOutputStream ;
@@ -325,36 +336,6 @@ private void createArchiveMain()
325
336
success = true ;
326
337
}
327
338
328
- protected Map <String , Long > getZipEntryNames ( File file )
329
- throws IOException
330
- {
331
- if ( !file .exists () || !doUpdate )
332
- {
333
- //noinspection unchecked
334
- return Collections .EMPTY_MAP ;
335
- }
336
- final Map <String , Long > entries = new HashMap <String , Long >();
337
- final org .apache .commons .compress .archivers .zip .ZipFile zipFile =
338
- new org .apache .commons .compress .archivers .zip .ZipFile ( file );
339
- for ( Enumeration en = zipFile .getEntries (); en .hasMoreElements (); )
340
- {
341
- ZipArchiveEntry ze = (ZipArchiveEntry ) en .nextElement ();
342
- entries .put ( ze .getName (), ze .getLastModifiedDate ().getTime () );
343
- }
344
- return entries ;
345
- }
346
-
347
- protected static boolean isFileAdded ( ArchiveEntry entry , Map entries )
348
- {
349
- return !entries .containsKey ( entry .getName () );
350
- }
351
-
352
- protected static boolean isFileUpdated ( ArchiveEntry entry , Map entries )
353
- {
354
- Long l = (Long ) entries .get ( entry .getName () );
355
- return l != null && ( l == -1 || !ResourceUtils .isUptodate ( entry .getResource (), l ) );
356
- }
357
-
358
339
/**
359
340
* Add the given resources.
360
341
*
@@ -365,8 +346,6 @@ protected static boolean isFileUpdated( ArchiveEntry entry, Map entries )
365
346
protected final void addResources ( ResourceIterator resources , ParallelScatterZipCreator zOut )
366
347
throws IOException , ArchiverException
367
348
{
368
- File base = null ;
369
-
370
349
while ( resources .hasNext () )
371
350
{
372
351
ArchiveEntry entry = resources .next ();
@@ -383,7 +362,7 @@ protected final void addResources( ResourceIterator resources, ParallelScatterZi
383
362
name = name + "/" ;
384
363
}
385
364
386
- addParentDirs ( entry , base , name , zOut , "" );
365
+ addParentDirs ( entry , null , name , zOut , "" );
387
366
388
367
if ( entry .getResource ().isFile () )
389
368
{
@@ -448,52 +427,6 @@ private void addParentDirs( ArchiveEntry archiveEntry, File baseDir, String entr
448
427
}
449
428
}
450
429
451
- private void readWithZipStats ( InputStream in , byte [] header , int headerRead , ZipArchiveEntry ze ,
452
- ByteArrayOutputStream bos )
453
- throws IOException
454
- {
455
- byte [] buffer = new byte [8 * 1024 ];
456
-
457
- CRC32 cal2 = new CRC32 ();
458
-
459
- long size = 0 ;
460
-
461
- for ( int i = 0 ; i < headerRead ; i ++ )
462
- {
463
- cal2 .update ( header [i ] );
464
- size ++;
465
- }
466
-
467
- int count = 0 ;
468
- do
469
- {
470
- size += count ;
471
- cal2 .update ( buffer , 0 , count );
472
- if ( bos != null )
473
- {
474
- bos .write ( buffer , 0 , count );
475
- }
476
- count = in .read ( buffer , 0 , buffer .length );
477
- }
478
- while ( count != -1 );
479
- ze .setSize ( size );
480
- ze .setCrc ( cal2 .getValue () );
481
- }
482
-
483
- public static long copy ( final InputStream input , final OutputStream output , final int bufferSize )
484
- throws IOException
485
- {
486
- final byte [] buffer = new byte [bufferSize ];
487
- long size = 0 ;
488
- int n ;
489
- while ( -1 != ( n = input .read ( buffer ) ) )
490
- {
491
- size += n ;
492
- output .write ( buffer , 0 , n );
493
- }
494
- return size ;
495
- }
496
-
497
430
/**
498
431
* Adds a new entry to the archive, takes care of duplicates as well.
499
432
*
@@ -529,13 +462,6 @@ protected void zipFile( @WillClose InputStream in, ParallelScatterZipCreator zOu
529
462
530
463
ze .setMethod ( compressThis ? ZipArchiveEntry .DEFLATED : ZipArchiveEntry .STORED );
531
464
ze .setUnixMode ( UnixStat .FILE_FLAG | mode );
532
- /*
533
- * ZipOutputStream.putNextEntry expects the ZipEntry to
534
- * know its size and the CRC sum before you start writing
535
- * the data when using STORED mode - unless it is seekable.
536
- *
537
- * This forces us to process the data twice.
538
- */
539
465
540
466
InputStream payload ;
541
467
if ( ze .isUnixSymlink () )
@@ -544,28 +470,9 @@ protected void zipFile( @WillClose InputStream in, ParallelScatterZipCreator zOu
544
470
final byte [] bytes = enc .encode ( symlinkDestination ).array ();
545
471
payload = new ByteArrayInputStream ( bytes );
546
472
}
547
- else if ( zipArchiveOutputStream .isSeekable () || compressThis )
548
- {
549
- payload = maybeSequence ( header , read , in );
550
- }
551
473
else
552
474
{
553
- if ( in .markSupported () )
554
- {
555
- in .mark ( Integer .MAX_VALUE );
556
- readWithZipStats ( in , header , read , ze , null ); // this cant be necessary with c-compress ???
557
- in .reset ();
558
- payload = maybeSequence ( header , read , in );
559
- }
560
- else
561
- {
562
- // Store data into a byte[]
563
- // todo: explain how on earth this code works with zip streams > 128KB ???
564
- ByteArrayOutputStream bos = new ByteArrayOutputStream ( 128 * 1024 );
565
- readWithZipStats ( in , header , read , ze , bos );
566
- ByteArrayInputStream bis = new ByteArrayInputStream ( bos .toByteArray () );
567
- payload = maybeSequence ( header , read , bis );
568
- }
475
+ payload = maybeSequence ( header , read , in );
569
476
}
570
477
zOut .addArchiveEntry ( ze , createInputStreamSupplier ( payload ) );
571
478
@@ -579,7 +486,7 @@ private InputStream maybeSequence( byte[] header, int hdrBytes, InputStream in )
579
486
580
487
private boolean isZipHeader ( byte [] header )
581
488
{
582
- return header [0 ] == 0x50 && header [1 ] == 0x4b && header [2 ] == 03 && header [3 ] == 04 ;
489
+ return header [0 ] == 0x50 && header [1 ] == 0x4b && header [2 ] == 3 && header [3 ] == 4 ;
583
490
}
584
491
585
492
/**
@@ -800,7 +707,7 @@ public void reset()
800
707
/**
801
708
* method for subclasses to override
802
709
*
803
- * @param zOut
710
+ * @param zOut The output stream
804
711
*/
805
712
protected void initZipOutputStream ( ParallelScatterZipCreator zOut )
806
713
throws ArchiverException , IOException
0 commit comments