1616import java .nio .file .Files ;
1717import java .nio .file .Path ;
1818
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+ */
1938public final class StudentFileAwareZipper implements Zipper {
2039
2140 private static final Logger log = LoggerFactory .getLogger (StudentFileAwareZipper .class );
@@ -24,17 +43,45 @@ public final class StudentFileAwareZipper implements Zipper {
2443
2544 private StudentFilePolicy filePolicy ;
2645
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+ */
2750 public StudentFileAwareZipper () {}
2851
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+ */
2959 public StudentFileAwareZipper (StudentFilePolicy filePolicy ) {
3060 this .filePolicy = filePolicy ;
3161 }
3262
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+ */
3370 @ Override
3471 public void setStudentFilePolicy (StudentFilePolicy studentFilePolicy ) {
3572 this .filePolicy = studentFilePolicy ;
3673 }
3774
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+ */
3885 @ Override
3986 public byte [] zip (Path rootDirectory ) throws IOException {
4087 log .debug ("Starting to zip {}" , rootDirectory );
0 commit comments