View Javadoc
1   package org.codehaus.plexus.archiver.bzip2;
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.components.io.resources.PlexusIoResourceCollection;
14  import org.codehaus.plexus.util.IOUtil;
15  
16  /**
17   * Implementation of {@link PlexusIoResourceCollection} for
18   * bzip2 compressed files.
19   */
20  public class PlexusIoBzip2ResourceCollection
21      extends PlexusIoCompressedFileResourceCollection
22  {
23  
24      @Nonnull
25      @Override
26      protected @WillNotClose
27      InputStream getInputStream( File file )
28          throws IOException
29      {
30          InputStream fis = new FileInputStream( file );
31          try
32          {
33              final InputStream result = BZip2UnArchiver.getBZip2InputStream( fis );
34              fis = null;
35              return result;
36          }
37          finally
38          {
39              IOUtil.close( fis );
40          }
41      }
42  
43      @Override protected PlexusIoResourceAttributes getAttributes( File file ) throws IOException
44      {
45          return new FileAttributes( file, new HashMap<Integer, String>(), new HashMap<Integer, String>() );
46      }
47  
48      @Override
49      protected String getDefaultExtension()
50      {
51          return ".bz2";
52      }
53  
54  }