Skip to content

Commit 8317bb5

Browse files
committed
Removed unused code
1 parent ff42607 commit 8317bb5

File tree

1 file changed

+21
-114
lines changed

1 file changed

+21
-114
lines changed

src/main/java/org/codehaus/plexus/archiver/zip/AbstractZipArchiver.java

Lines changed: 21 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
* limitations under the License.
1818
*/
1919

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;
2626
import org.codehaus.plexus.archiver.AbstractArchiver;
2727
import org.codehaus.plexus.archiver.ArchiveEntry;
2828
import org.codehaus.plexus.archiver.Archiver;
@@ -36,6 +36,17 @@
3636
import org.codehaus.plexus.util.IOUtil;
3737

3838
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;
3950

4051
import static org.codehaus.plexus.archiver.util.Streams.bufferedOutputStream;
4152
import static org.codehaus.plexus.archiver.util.Streams.fileOutputStream;
@@ -325,36 +336,6 @@ private void createArchiveMain()
325336
success = true;
326337
}
327338

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-
358339
/**
359340
* Add the given resources.
360341
*
@@ -365,8 +346,6 @@ protected static boolean isFileUpdated( ArchiveEntry entry, Map entries )
365346
protected final void addResources( ResourceIterator resources, ParallelScatterZipCreator zOut )
366347
throws IOException, ArchiverException
367348
{
368-
File base = null;
369-
370349
while ( resources.hasNext() )
371350
{
372351
ArchiveEntry entry = resources.next();
@@ -383,7 +362,7 @@ protected final void addResources( ResourceIterator resources, ParallelScatterZi
383362
name = name + "/";
384363
}
385364

386-
addParentDirs( entry, base, name, zOut, "" );
365+
addParentDirs( entry, null, name, zOut, "" );
387366

388367
if ( entry.getResource().isFile() )
389368
{
@@ -448,52 +427,6 @@ private void addParentDirs( ArchiveEntry archiveEntry, File baseDir, String entr
448427
}
449428
}
450429

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-
497430
/**
498431
* Adds a new entry to the archive, takes care of duplicates as well.
499432
*
@@ -529,13 +462,6 @@ protected void zipFile( @WillClose InputStream in, ParallelScatterZipCreator zOu
529462

530463
ze.setMethod( compressThis ? ZipArchiveEntry.DEFLATED : ZipArchiveEntry.STORED );
531464
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-
*/
539465

540466
InputStream payload;
541467
if ( ze.isUnixSymlink() )
@@ -544,28 +470,9 @@ protected void zipFile( @WillClose InputStream in, ParallelScatterZipCreator zOu
544470
final byte[] bytes = enc.encode( symlinkDestination ).array();
545471
payload = new ByteArrayInputStream( bytes );
546472
}
547-
else if ( zipArchiveOutputStream.isSeekable() || compressThis )
548-
{
549-
payload = maybeSequence( header, read, in );
550-
}
551473
else
552474
{
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 );
569476
}
570477
zOut.addArchiveEntry( ze, createInputStreamSupplier( payload ) );
571478

@@ -579,7 +486,7 @@ private InputStream maybeSequence( byte[] header, int hdrBytes, InputStream in )
579486

580487
private boolean isZipHeader( byte[] header )
581488
{
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;
583490
}
584491

585492
/**
@@ -800,7 +707,7 @@ public void reset()
800707
/**
801708
* method for subclasses to override
802709
*
803-
* @param zOut
710+
* @param zOut The output stream
804711
*/
805712
protected void initZipOutputStream( ParallelScatterZipCreator zOut )
806713
throws ArchiverException, IOException

0 commit comments

Comments
 (0)