View Javadoc
1   package org.codehaus.plexus.archiver.bzip2;
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 org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
31  import org.codehaus.plexus.archiver.AbstractArchiveContentLister;
32  import org.codehaus.plexus.archiver.ArchiveContentEntry;
33  import org.codehaus.plexus.archiver.ArchiverException;
34  
35  import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource;
36  import org.codehaus.plexus.components.io.resources.PlexusIoResource;
37  
38  import org.apache.commons.io.FilenameUtils;
39  
40  /**
41   * @author Franck Bonin
42   * @version $Revision$ $Date$
43   */
44  public class BZip2ArchiveContentLister
45      extends AbstractArchiveContentLister
46  {
47      private static final String OPERATION_BZIP2 = "bzip2";
48  
49      public BZip2ArchiveContentLister()
50      {
51      }
52  
53      public BZip2ArchiveContentLister( File sourceFile )
54      {
55          super( sourceFile );
56      }
57      
58      /**
59       * BZip2 content resource
60       */
61      protected class BZip2FileInfo
62      extends AbstractPlexusIoResource
63      {
64          private final File sourceFile;
65          
66          public BZip2FileInfo( File sourceFile )
67          {
68              super( sourceFile.getName(), sourceFile.lastModified(),
69                   PlexusIoResource.UNKNOWN_RESOURCE_SIZE, true, false, true );
70              this.sourceFile = sourceFile;
71          }
72  
73          public URL getURL()
74              throws IOException
75          {
76              return null;
77          }
78  
79          public InputStream getContents()
80              throws IOException
81          {
82              return new BZip2CompressorInputStream( new FileInputStream( sourceFile ) );
83          }
84      }
85      
86      protected List<ArchiveContentEntry> execute()
87          throws ArchiverException
88      {
89          ArrayList<ArchiveContentEntry> archiveContentList = new ArrayList<ArchiveContentEntry>();
90          getLogger().debug( "listing: " + getSourceFile() );
91  
92          ArchiveContentEntry ae = ArchiveContentEntry.createFileEntry( 
93              FilenameUtils.removeExtension( getSourceFile().getName() ), new BZip2FileInfo( getSourceFile() ), -1 );
94          archiveContentList.add( ae );
95  
96          getLogger().debug( "listing complete" );
97          
98          return archiveContentList;
99      }
100 }