View Javadoc
1   package org.codehaus.plexus.archiver.snappy;
2   
3   import java.io.File;
4   import java.io.FileInputStream;
5   import java.io.IOException;
6   import java.io.InputStream;
7   import java.util.HashMap;
8   import javax.annotation.Nonnull;
9   import javax.annotation.WillNotClose;
10  import org.codehaus.plexus.components.io.attributes.FileAttributes;
11  import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
12  import org.codehaus.plexus.components.io.resources.PlexusIoCompressedFileResourceCollection;
13  import org.codehaus.plexus.util.IOUtil;
14  
15  /**
16   * Implementation of {@link org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection} for
17   * snappy compressed files.
18   */
19  public class PlexusIoSnappyResourceCollection
20      extends PlexusIoCompressedFileResourceCollection
21  {
22  
23      @Nonnull
24      @Override
25      protected @WillNotClose
26      InputStream getInputStream( File file )
27          throws IOException
28      {
29          InputStream fis = new FileInputStream( file );
30          try
31          {
32              final InputStream result = SnappyUnArchiver.getSnappyInputStream( fis );
33              fis = null;
34              return result;
35          }
36          finally
37          {
38              IOUtil.close( fis );
39          }
40      }
41  
42      @Override protected PlexusIoResourceAttributes getAttributes( File file ) throws IOException
43      {
44          return new FileAttributes( file, new HashMap<Integer, String>(), new HashMap<Integer, String>() );
45      }
46  
47      @Override
48      protected String getDefaultExtension()
49      {
50          return ".snappy";
51      }
52  
53  }