View Javadoc
1   package org.codehaus.plexus.archiver.gzip;
2   
3   /*
4    * Copyright (C) 2011-2016, Neticoa SAS France - Tous droits réservés.
5    * Author(s) : Franck Bonin, Neticoa SAS France
6    *
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   *
19   */
20  
21  import java.io.File;
22  import java.io.IOException;
23  import java.io.InputStream;
24  import java.io.FileInputStream;
25  
26  import java.util.List;
27  import java.util.ArrayList;
28  import java.net.URL;
29  
30  import java.util.zip.GZIPInputStream;
31  import org.codehaus.plexus.archiver.AbstractArchiveContentLister;
32  import org.codehaus.plexus.archiver.ArchiveContentEntry;
33  import org.codehaus.plexus.archiver.ArchiverException;
34  
35  //import javax.annotation.Nonnull;
36  
37  //import static org.codehaus.plexus.archiver.util.Streams.*;
38  
39  import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource;
40  import org.codehaus.plexus.components.io.resources.PlexusIoResource;
41  
42  import org.apache.commons.io.FilenameUtils;
43  
44  /**
45   * @author Franck Bonin
46   * @version $Revision$ $Date$
47   */
48  public class GZipArchiveContentLister
49      extends AbstractArchiveContentLister
50  {
51      private static final String OPERATION_GZIP = "gzip";
52  
53      public GZipArchiveContentLister()
54      {
55      }
56  
57      public GZipArchiveContentLister( File sourceFile )
58      {
59          super( sourceFile );
60      }
61      
62      /**
63       * GZip content resource
64       */
65      protected class GZipFileInfo
66      extends AbstractPlexusIoResource
67      {
68          private final File sourceFile;
69          
70          public GZipFileInfo( File sourceFile )
71          {
72              super( sourceFile.getName(), sourceFile.lastModified(),
73                   PlexusIoResource.UNKNOWN_RESOURCE_SIZE, true, false, true );
74              this.sourceFile = sourceFile;
75          }
76  
77          public URL getURL()
78              throws IOException
79          {
80              return null;
81          }
82  
83          public InputStream getContents()
84              throws IOException
85          {
86              return new GZIPInputStream( new FileInputStream( sourceFile ) );
87          }
88      }
89      
90      protected List<ArchiveContentEntry> execute()
91          throws ArchiverException
92      {
93          ArrayList<ArchiveContentEntry> archiveContentList = new ArrayList<ArchiveContentEntry>();
94          getLogger().debug( "listing: " + getSourceFile() );
95  
96          ArchiveContentEntry ae = ArchiveContentEntry.createFileEntry( 
97              FilenameUtils.removeExtension( getSourceFile().getName() ), new GZipFileInfo( getSourceFile() ), -1 );
98          archiveContentList.add( ae );
99  
100         getLogger().debug( "listing complete" );
101         
102         return archiveContentList;
103     }
104 }