Coverage Report - org.codehaus.plexus.archiver.zip.PlexusArchiverZipFileResourceCollection
 
Classes in this File Line Coverage Branch Coverage Complexity
PlexusArchiverZipFileResourceCollection
83 %
10/12
75 %
3/4
1,625
PlexusArchiverZipFileResourceCollection$CloseableIterator
66 %
10/15
100 %
2/2
1,625
 
 1  0
 package org.codehaus.plexus.archiver.zip;
 2  
 
 3  
 import java.io.Closeable;
 4  
 import java.io.File;
 5  
 import java.io.IOException;
 6  
 import java.nio.charset.Charset;
 7  
 import java.util.Enumeration;
 8  
 import java.util.Iterator;
 9  
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
 10  
 import org.apache.commons.compress.archivers.zip.ZipFile;
 11  
 import org.codehaus.plexus.components.io.resources.AbstractPlexusIoArchiveResourceCollection;
 12  
 import org.codehaus.plexus.components.io.resources.EncodingSupported;
 13  
 import org.codehaus.plexus.components.io.resources.PlexusIoResource;
 14  
 
 15  354
 public class PlexusArchiverZipFileResourceCollection
 16  
     extends AbstractPlexusIoArchiveResourceCollection implements EncodingSupported
 17  
 {
 18  
 
 19  
     /**
 20  
      * The zip file resource collections role hint.
 21  
      */
 22  
     public static final String ROLE_HINT = "zip";
 23  
 
 24  8
     private Charset charset = Charset.forName( "UTF-8" );
 25  
 
 26  
     @Override
 27  
     protected Iterator<PlexusIoResource> getEntries()
 28  
         throws IOException
 29  
     {
 30  8
         final File f = getFile();
 31  8
         if ( f == null )
 32  
         {
 33  0
             throw new IOException( "The tar archive file has not been set." );
 34  
         }
 35  8
         final ZipFile zipFile = new ZipFile( f, charset != null ? charset.name() : "UTF8" );
 36  8
         return new CloseableIterator( zipFile );
 37  
     }
 38  
 
 39  
     @Override
 40  
     public boolean isConcurrentAccessSupported()
 41  
     {
 42  
         // Well maybe someday investigate if we can do concurrent zip
 43  247
         return false;
 44  
     }
 45  
 
 46  346
     class CloseableIterator
 47  
         implements Iterator<PlexusIoResource>, Closeable
 48  
     {
 49  
 
 50  
         final Enumeration en;
 51  
 
 52  
         private final ZipFile zipFile;
 53  
 
 54  0
         public CloseableIterator( ZipFile zipFile )
 55  8
         {
 56  8
             this.en = zipFile.getEntriesInPhysicalOrder();
 57  8
             this.zipFile = zipFile;
 58  8
         }
 59  
 
 60  
         @Override
 61  
         public boolean hasNext()
 62  
         {
 63  354
             return en.hasMoreElements();
 64  
         }
 65  
 
 66  
         @Override
 67  
         public PlexusIoResource next()
 68  
         {
 69  346
             final ZipArchiveEntry entry = (ZipArchiveEntry) en.nextElement();
 70  346
             return entry.isUnixSymlink()
 71  0
                        ? new ZipSymlinkResource( zipFile, entry, getStreamTransformer() )
 72  0
                        : new ZipResource( zipFile, entry, getStreamTransformer() );
 73  
 
 74  
         }
 75  
 
 76  
         @Override
 77  
         public void remove()
 78  
         {
 79  0
             throw new UnsupportedOperationException( "Removing isn't implemented." );
 80  
         }
 81  
 
 82  
         @Override
 83  
         public void close()
 84  
             throws IOException
 85  
         {
 86  6
             zipFile.close();
 87  6
         }
 88  
 
 89  
     }
 90  
 
 91  
     @Override
 92  
     public void setEncoding( Charset charset )
 93  
     {
 94  5
         this.charset = charset;
 95  5
     }
 96  
 
 97  
 }