Skip to content

Package: TARArchiveComponentVisitor

TARArchiveComponentVisitor

nameinstructionbranchcomplexitylinemethod
TARArchiveComponentVisitor(ArchiveOutputStream)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
addEntryToOutoutStream(ArchiveEntry)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
finish()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
handleArchiveDevNode(ArchiveDevNode)
M: 9 C: 31
78%
M: 2 C: 1
33%
M: 2 C: 1
33%
M: 3 C: 10
77%
M: 0 C: 1
100%
handleArchiveDirectory(ArchiveDirectory)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
handleArchiveFile(ArchiveFile)
M: 0 C: 30
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
handleArchiveSymlink(ArchiveSymlink)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: package archive;
2:
3: import java.io.FileNotFoundException;
4: import java.io.IOException;
5:
6: import org.apache.commons.compress.archivers.ArchiveEntry;
7: import org.apache.commons.compress.archivers.ArchiveOutputStream;
8: import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
9: import org.apache.commons.compress.utils.IOUtils;
10:
11: /**
12: * Implementation of the ArchiveComponentVisitor to create entries in TAR archives.
13: */
14: public class TARArchiveComponentVisitor implements ArchiveComponentVisitor {
15:
16:         /**
17:          * The outputstream to write the archive.
18:          */
19:         private final ArchiveOutputStream outputStream;
20:
21:         /**
22:          * Constructor, which sets the output stream to write in the archive.
23:          *
24:          * @param outputStream
25:          * the output stream
26:          */
27:         public TARArchiveComponentVisitor(final ArchiveOutputStream outputStream) {
28:                 super();
29:                 this.outputStream = outputStream;
30:         }
31:
32:         /**
33:          * Adds and closes an entry to the archive.
34:          *
35:          * @param entry
36:          * the entry which should be added
37:          * @throws IOException
38:          */
39:         private void addEntryToOutoutStream(final ArchiveEntry entry) throws IOException {
40:                 outputStream.putArchiveEntry(entry);
41:                 outputStream.closeArchiveEntry();
42:         }
43:
44:         @Override
45:         public void handleArchiveFile(final ArchiveFile archiveFile)
46:                         throws FileNotFoundException, IOException {
47:                 final TarArchiveEntry entry = new TarArchiveEntry(archiveFile.getName());
48:                 entry.setSize(archiveFile.getArchiveData().getSize());
49:                 entry.setMode(archiveFile.getMode());
50:                 outputStream.putArchiveEntry(entry);
51:                 IOUtils.copy(archiveFile.getArchiveData().createInputStream(), outputStream);
52:                 outputStream.closeArchiveEntry();
53:         }
54:
55:         @Override
56:         public void handleArchiveDirectory(final ArchiveDirectory directory)
57:                         throws FileNotFoundException, IOException {
58:                 final TarArchiveEntry entry =
59:                                 new TarArchiveEntry(directory.getName(), TarArchiveEntry.LF_DIR);
60:                 entry.setMode(directory.getMode());
61:                 addEntryToOutoutStream(entry);
62:         }
63:
64:         @Override
65:         public void handleArchiveSymlink(final ArchiveSymlink symlink) throws IOException {
66:                 final TarArchiveEntry entry =
67:                                 new TarArchiveEntry(symlink.getName(), TarArchiveEntry.LF_SYMLINK);
68:                 entry.setLinkName(symlink.getLinktarget());
69:                 addEntryToOutoutStream(entry);
70:         }
71:
72:         @Override
73:         public void handleArchiveDevNode(final ArchiveDevNode node)
74:                         throws IOException, IllegalDeviceTypeException {
75:                 byte devtype = (byte) '1';
76:•                switch (node.getDevtype()) {
77:                 case 'b':
78:                         devtype = TarArchiveEntry.LF_BLK;
79:                         break;
80:                 case 'c':
81:                         devtype = TarArchiveEntry.LF_CHR;
82:                         break;
83:                 default:
84:                         throw new IllegalDeviceTypeException(node.getDevtype());
85:                 }
86:                 final TarArchiveEntry entry = new TarArchiveEntry(node.getName(), devtype);
87:                 entry.setDevMajor(node.getMajor());
88:                 entry.setDevMinor(node.getMinor());
89:                 entry.setMode(node.getMode());
90:                 addEntryToOutoutStream(entry);
91:         };
92:
93:         @Override
94:         public void finish() throws IOException {
95:                 this.outputStream.finish();
96:         }
97:
98: }