package controller;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

import com.thoughtworks.xstream.XStream;

import model.Task;
import model.TaskList;

public class Storage {
	
	private static final String TASK_FILE = "uClear.xml";
	
	private static final String ERROR_IO = "Error when trying to read/write the file.";
	
	// These two Reader and Writer are used to access and manipulate the given
	// text file
	private BufferedReader reader;
	private BufferedWriter writer;
	
	public Storage() {
		this.initilize();
	}
	
	public String save(TaskList list) {
		return null;
	}
	
	public TaskList load() {
		return null;
	}
	
	public String serialize(Task task) {
		XStream xstream = new XStream();
		xstream.alias("task", Task.class);
		String xml = xstream.toXML(task);
		return xml;
	}
	
	
	private void initilize() {
		File inputFile = new File(TASK_FILE);
		try {
			if (inputFile.exists()) {
				this.reader = new BufferedReader(new FileReader(inputFile));
				this.writer = new BufferedWriter(new FileWriter(inputFile, true));
			} else {
				// if the file does not exist, we create a new file
				this.writer = new BufferedWriter(new FileWriter(inputFile, false));
				this.reader = new BufferedReader(new FileReader(inputFile));
			}
		} catch (Exception e) {
			throw new Error(ERROR_IO);
		}
	}
	
	
	private void readFromFile() {
		
	}
	
	private  void saveToFile() {
		
	}
	
	public static void main(String[] args) {
		Task a = new Task("going to movies tonight");
		Storage storge = new Storage();
		System.out.println(serialize(a));
	}
}

@@ -150,16 +150,44 @@
 eWriter;
+%0Aimport java.io.IOException;
 %0A%0Aimport
@@ -900,24 +900,170 @@
  xml;%0A%09%7D%0A%09%0A%09
+private void close() %7B%0A%09%09try %7B%0A%09%09%09this.reader.close();%0A%09%09%09this.writer.close();%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09throw new Error(ERROR_IO);%0A%09%09%7D%0A%09%09%0A%09%7D
 %0A%09private vo
@@ -1791,16 +1791,23 @@
 println(
+storge.
 serializ
@@ -1813,13 +1813,31 @@
 ze(a));%0A
+%09%09storge.close();%0A
 %09%7D%0A%7D%0A

Test storage class