@@ -0,0 +1,2422 @@
+package foam.dao;%0A%0Aimport foam.core.Detachable;%0Aimport foam.core.FObject;%0Aimport foam.core.Journal;%0Aimport foam.lib.json.JournalParser;%0Aimport foam.lib.json.Outputter;%0A%0Aimport java.io.*;%0A%0A/**%0A * Created by carlos on 2017-05-22.%0A */%0Apublic class FileJournal implements Journal %7B%0A%0A    protected BufferedWriter bw;%0A    protected BufferedReader br;%0A    protected File file;%0A%0A    public FileJournal(String filename) throws IOException %7B%0A%0A        this.file = new File(filename);%0A%0A        if (!file.exists()) %7B%0A            file.createNewFile();%0A        %7D%0A%0A        this.bw = new BufferedWriter(new FileWriter(file, true));%0A        this.br = new BufferedReader(new FileReader(file));%0A    %7D%0A%0A    /**%0A     * Persists data into the File System.%0A     *%0A     * @param obj%0A     * @param sub%0A     */%0A    @Override%0A    public void put(FObject obj, Detachable sub) %7B%0A        try %7B%0A            Outputter outputter = new Outputter();%0A            this.bw.write(%22p(foam.json.parse(%22 + outputter.stringify(obj) + %22))%22);%0A            this.bw.newLine();%0A            this.bw.flush();%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace();%0A        %7D%0A    %7D%0A%0A    /**%0A     * deletes the entire journal file%0A     */%0A    public void removeAll() %7B%0A        this.file.delete();%0A    %7D%0A%0A    @Override%0A    public void remove(FObject obj, Detachable sub) %7B%0A        try %7B%0A            Outputter outputter = new Outputter();%0A            this.bw.write(%22r(foam.json.parse(%22 + outputter.stringify(obj) + %22))%22);%0A            this.bw.newLine();%0A            this.bw.flush();%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace();%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void eof() %7B%0A%0A    %7D%0A%0A    @Override%0A    public void reset(Detachable sub) %7B%0A%0A    %7D%0A%0A    /**%0A     * %22replays%22 the persisted journaled file history into a dao.%0A     *%0A     * @param delegate%0A     * @return%0A     * @throws IOException%0A     */%0A    @Override%0A    public void replay(DAO delegate) throws IOException %7B%0A        JournalParser journalParser = new JournalParser();%0A%0A        String line;%0A        while ((line = this.br.readLine()) != null) %7B%0A            String operation = journalParser.parseOperation(line);%0A            FObject object = journalParser.parseObject(line);%0A            switch (operation) %7B%0A                case %22p%22:%0A                    delegate.put(object);%0A                case %22r%22:%0A                    delegate.remove(object);%0A            %7D%0A        %7D%0A    %7D%0A%7D

implement file io operations