Package: Fli4LArchiver
Fli4LArchiver
| name | instruction | branch | complexity | line | method | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Fli4LArchiver() | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| createArchive(ArchiveComponentVisitor, List) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| createCPIO(OutputStream, List) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| createTAR(OutputStream, List) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
Coverage
1: package archive;
2: 
3: import java.io.FileNotFoundException;
4: import java.io.IOException;
5: import java.io.OutputStream;
6: import java.util.Iterator;
7: import java.util.List;
8: 
9: import org.apache.commons.compress.archivers.ArchiveException;
10: import org.apache.commons.compress.archivers.ArchiveOutputStream;
11: import org.apache.commons.compress.archivers.ArchiveStreamFactory;
12: 
13: /**
14:  * The Fli4LArchiver provides Methods to join a list of ArchiveComponents together in a CPIO or TAR
15:  * archive.
16:  * 
17:  * @author max
18:  *
19:  */
20: public class Fli4LArchiver {
21: 
22:         /**
23:          * Adds an entry to the CPIO-archive for each archiveComponent.
24:          * 
25:          * @param outputStream
26:          *            the OutputStream to the CPIO-archive
27:          * @param archiveComponents
28:          *            the ArchiveComponents to be add to the archive
29:          * @throws ArchiveException
30:          *             if the archive could not be created
31:          * @throws FileNotFoundException
32:          * @throws IOException
33:          * @throws IllegalDeviceTypeException
34:          *             when a unsupported devtype is declared
35:          */
36:         public void createCPIO(final OutputStream outputStream,
37:                         final List<AbstractArchiveComponent> archiveComponents) throws ArchiveException,
38:                         FileNotFoundException, IOException, IllegalDeviceTypeException {
39:                 final ArchiveOutputStream archiveOutputStream = new ArchiveStreamFactory()
40:                                 .createArchiveOutputStream(ArchiveStreamFactory.CPIO, outputStream);
41:                 final ArchiveComponentVisitor visitor =
42:                                 new CPIOArchiveComponentVisitor(archiveOutputStream);
43:                 createArchive(visitor, archiveComponents);
44:         }
45: 
46:         /**
47:          * Adds an entry to the TAR-archive for each archiveCpmponent.
48:          * 
49:          * @param outputStream
50:          *            the outputStream to the TARarchive
51:          * @param archiveComponents
52:          *            the Archive Components to be add to the archive
53:          * @throws FileNotFoundException
54:          * @throws IOException
55:          * @throws ArchiveException
56:          * @throws IllegalDeviceTypeException
57:          *             when a unsupported devtype is declared
58:          */
59:         public void createTAR(final OutputStream outputStream,
60:                         final List<AbstractArchiveComponent> archiveComponents) throws FileNotFoundException,
61:                         IOException, ArchiveException, IllegalDeviceTypeException {
62:                 final ArchiveOutputStream archiveOutputStream = new ArchiveStreamFactory()
63:                                 .createArchiveOutputStream(ArchiveStreamFactory.TAR, outputStream);
64:                 final ArchiveComponentVisitor visitor =
65:                                 new TARArchiveComponentVisitor(archiveOutputStream);
66:                 createArchive(visitor, archiveComponents);
67:         }
68: 
69:         /**
70:          * Creates an archive with the specified type archiveType.
71:          * 
72:          * @param visitor
73:          *            the visitor to create the archive entries
74:          * @param archiveComponents
75:          *            the components, that should be put to the archive
76:          * @throws FileNotFoundException
77:          * @throws IOException
78:          * @throws IllegalDeviceTypeException
79:          *             when a unsupported devtype is declared
80:          */
81:         private void createArchive(final ArchiveComponentVisitor visitor,
82:                         final List<AbstractArchiveComponent> archiveComponents)
83:                         throws FileNotFoundException, IOException, IllegalDeviceTypeException {
84:                 final Iterator<AbstractArchiveComponent> iterator = archiveComponents.iterator();
85:•                while (iterator.hasNext()) {
86:                         final AbstractArchiveComponent currentArchiveComponent = iterator.next();
87:                         currentArchiveComponent.accept(visitor);
88:                 }
89:                 visitor.finish();
90:         }
91: 
92: }