1 package org.codehaus.plexus.archiver.bzip2;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
42
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
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 }