16
16
import java .nio .file .Files ;
17
17
import java .nio .file .Path ;
18
18
19
+ /**
20
+ * This {@link Zipper} implementation recursively zips the files of a directory.
21
+ * Only files considered to be student files by the specified {@link StudentFilePolicy}
22
+ * are included in the archive.
23
+ *
24
+ * <p>The {@link StudentFilePolicy} provided either via the
25
+ * {@link #StudentFileAwareZipper(StudentFilePolicy) constructor} or a
26
+ * {@link #setStudentFilePolicy(StudentFilePolicy) setter method} is used to determine whether
27
+ * a file or directory should be included in the archive.</p>
28
+ *
29
+ * <p>Individual directories can be excluded from archival by adding a file in the directory
30
+ * root with the name of {@code .tmcnosubmit}. For example, if the folder {@code sensitive/}
31
+ * should be excluded, the file {@code sensitive/.tmcnosubmit} should be created. The contents
32
+ * of the file are ignored.</p>
33
+ *
34
+ * <p>File system roots (e.g. {@code /} on *nix and {@code C:\} on Windows platforms) cannot
35
+ * be zipped, as this {@link Zipper} includes the specified {@code rootDirectory}
36
+ * in the zip file as a parent directory.</p>
37
+ */
19
38
public final class StudentFileAwareZipper implements Zipper {
20
39
21
40
private static final Logger log = LoggerFactory .getLogger (StudentFileAwareZipper .class );
@@ -24,17 +43,45 @@ public final class StudentFileAwareZipper implements Zipper {
24
43
25
44
private StudentFilePolicy filePolicy ;
26
45
46
+ /**
47
+ * Instantiates a new {@link StudentFileAwareZipper} without a {@link StudentFilePolicy}.
48
+ * The {@link #setStudentFilePolicy(StudentFilePolicy)} method can be used to set the policy.
49
+ */
27
50
public StudentFileAwareZipper () {}
28
51
52
+ /**
53
+ * Instantiates a new {@link StudentFileAwareZipper} with the
54
+ * specified {@link StudentFilePolicy}.
55
+ *
56
+ * @param filePolicy Determines which files and directories are included in the archive.
57
+ * @see #setStudentFilePolicy(StudentFilePolicy)
58
+ */
29
59
public StudentFileAwareZipper (StudentFilePolicy filePolicy ) {
30
60
this .filePolicy = filePolicy ;
31
61
}
32
62
63
+ /**
64
+ * Sets the {@link StudentFilePolicy} which determines which files and directories
65
+ * are included in the archive.
66
+ *
67
+ * @param studentFilePolicy Determines which files and directories are included in the archive.
68
+ * @see #StudentFileAwareZipper(StudentFilePolicy)
69
+ */
33
70
@ Override
34
71
public void setStudentFilePolicy (StudentFilePolicy studentFilePolicy ) {
35
72
this .filePolicy = studentFilePolicy ;
36
73
}
37
74
75
+ /**
76
+ * Recursively zips all files and directories which are considered to be student files.
77
+ *
78
+ * @param rootDirectory The root directory of the files and directories to zip.
79
+ * Included in the archive. Cannot be a file system root.
80
+ * @return Byte array containing the bytes of the {@link ZipArchiveOutputStream}.
81
+ * @throws IOException if reading a file or directory fails.
82
+ * @throws IllegalArgumentException if attempting to zip a file system root.
83
+ * @see #setStudentFilePolicy(StudentFilePolicy)
84
+ */
38
85
@ Override
39
86
public byte [] zip (Path rootDirectory ) throws IOException {
40
87
log .debug ("Starting to zip {}" , rootDirectory );
0 commit comments