View Javadoc
1   package org.codehaus.plexus.archiver.gzip;
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 java.util.zip.GZIPInputStream;
9   import javax.annotation.Nonnull;
10  import org.codehaus.plexus.archiver.util.Streams;
11  import org.codehaus.plexus.components.io.attributes.FileAttributes;
12  import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
13  import org.codehaus.plexus.components.io.resources.PlexusIoCompressedFileResourceCollection;
14  import org.codehaus.plexus.util.IOUtil;
15  
16  /**
17   * Abstract base class for compressed files, aka singleton
18   * resource collections.
19   */
20  public class PlexusIoGzipResourceCollection
21      extends PlexusIoCompressedFileResourceCollection
22  {
23  
24      @Override
25      protected String getDefaultExtension()
26      {
27          return ".gz";
28      }
29  
30      @Nonnull
31      @Override
32      protected InputStream getInputStream( File file )
33          throws IOException
34      {
35          InputStream fis = new FileInputStream( file );
36          try
37          {
38              InputStream result = Streams.bufferedInputStream( new GZIPInputStream( fis ) );
39              fis = null;
40              return result;
41          }
42          finally
43          {
44              IOUtil.close( fis );
45          }
46      }
47  
48      @Override
49      protected PlexusIoResourceAttributes getAttributes( File file )
50          throws IOException
51      {
52          return new FileAttributes( file, new HashMap<Integer, String>(), new HashMap<Integer, String>() );
53      }
54  
55  }