View Javadoc
1   package org.codehaus.plexus.archiver.snappy;
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  /* SNAPPY
31        [INFO] Restricted to JDK 1.5 yet org.xerial.snappy:snappy-java:jar:1.1.1.6:compile
32               contains org/xerial/snappy/OSInfo.class targeted to JDK 1.6
33        [WARNING] Rule 0: org.apache.maven.plugins.enforcer.EnforceBytecodeVersion failed with message:
34        Found Banned Dependency: org.xerial.snappy:snappy-java:jar:1.1.1.6
35  */
36  //import org.xerial.snappy.SnappyInputStream;
37  import org.codehaus.plexus.archiver.AbstractArchiveContentLister;
38  import org.codehaus.plexus.archiver.ArchiveContentEntry;
39  import org.codehaus.plexus.archiver.ArchiverException;
40  
41  import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource;
42  import org.codehaus.plexus.components.io.resources.PlexusIoResource;
43  
44  import org.apache.commons.io.FilenameUtils;
45  
46  /**
47   * @author Franck Bonin
48   * @version $Revision$ $Date$
49   */
50  public class SnappyArchiveContentLister
51      extends AbstractArchiveContentLister
52  {
53      private static final String OPERATION_SNAPPY = "snappy";
54  
55      public SnappyArchiveContentLister()
56      {
57      }
58  
59      public SnappyArchiveContentLister( File sourceFile )
60      {
61          super( sourceFile );
62      }
63      
64      /**
65       * Snappy content resource
66       */
67      protected class SnappyFileInfo
68      extends AbstractPlexusIoResource
69      {
70          private final File sourceFile;
71          
72          public SnappyFileInfo( File sourceFile )
73          {
74              super( sourceFile.getName(), sourceFile.lastModified(),
75                   PlexusIoResource.UNKNOWN_RESOURCE_SIZE, true, false, true );
76              this.sourceFile = sourceFile;
77          }
78  
79          public URL getURL()
80              throws IOException
81          {
82              return null;
83          }
84  
85          public InputStream getContents()
86              throws IOException
87          {
88              // SNAPPY
89              return /*new SnappyInputStream*/( new FileInputStream( sourceFile ) );
90          }
91      }
92      
93      protected List<ArchiveContentEntry> execute()
94          throws ArchiverException
95      {
96          ArrayList<ArchiveContentEntry> archiveContentList = new ArrayList<ArchiveContentEntry>();
97          getLogger().debug( "listing: " + getSourceFile() );
98  
99          ArchiveContentEntry ae = ArchiveContentEntry.createFileEntry( 
100             FilenameUtils.removeExtension( getSourceFile().getName() ), new SnappyFileInfo( getSourceFile() ), -1 );
101         archiveContentList.add( ae );
102 
103         getLogger().debug( "listing complete" );
104         
105         return archiveContentList;
106     }
107 }