
package forager.server;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Handles the active and completed task lists and allows them to be flushed
 * and synced to disk.
 *
 * @author malensek
 */
public class ListManager {

    public static final String DEFAULT_LIST_NAME = "tasklist";

    private FileOutputStream taskListOut;
    private PrintWriter taskListWriter;

    private FileOutputStream completedListOut;
    private PrintWriter completedListWriter;

    public ListManager() throws IOException {
        this(DEFAULT_LIST_NAME);
    }

    public ListManager(String taskListName) throws IOException {
        taskListOut = new FileOutputStream(taskListName, true);
        taskListWriter = new PrintWriter(
                new BufferedOutputStream(taskListOut));

        String completedName = taskListName + ".done";
        completedListOut = new FileOutputStream(completedName, true);
        completedListWriter = new PrintWriter(
                new BufferedOutputStream(completedListOut));
    }

    public void addTask(String command) {
        taskListWriter.println(command);
    }

    public void addCompletedTask(String command) {
        completedListWriter.println(command);
    }

    public void sync() throws IOException {
        taskListWriter.flush();
        taskListOut.getFD().sync();
    }
}

@@ -1410,11 +1410,335 @@
 );%0A    %7D
+%0A%0A    public static boolean listsExist() %7B%0A        return listsExist(DEFAULT_LIST_NAME);%0A    %7D%0A%0A    public static boolean listsExist(String taskListName) %7B%0A        File listFile = new File(taskListName);%0A        File doneFile = new File(taskListName + %22.done%22);%0A        return (listFile.exists() %7C%7C doneFile.exists());%0A    %7D
 %0A%7D%0A

Add checks for list files