package jp.naist.sd.kenja.factextractor;

public class FileFormatTreeWriter extends TreeWriter {

}

@@ -39,62 +39,1417 @@
 r;%0A%0A
-public class FileFormatTreeWriter extends TreeWriter %7B%0A
+import java.io.File;%0Aimport java.io.IOException;%0A%0Aimport com.google.common.base.Charsets;%0Aimport com.google.common.io.Files;%0A%0Apublic class FileFormatTreeWriter extends TreeWriter %7B%0A%09private File baseDir;%0A%09private File currentDir;%0A%09%0A%09public FileFormatTreeWriter(File baseDir) %7B%0A%09%09this.baseDir = baseDir;%0A%09%09if (!baseDir.exists()) %7B%0A%09%09%09try %7B%0A%09%09%09%09Files.createParentDirs(baseDir);%0A%09%09%09%09baseDir.mkdir();%0A%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%09// TODO Auto-generated catch block%0A%09%09%09%09e.printStackTrace();%0A%09%09%09%7D%0A%09%09%7D%0A%09%09currentDir = baseDir;%0A%09%7D%0A%09%0A%09@Override%0A%09public void writeTree(Tree tree) %7B%0A%09%09File parentDir = currentDir;%0A%09%09if (!tree.isRoot()) %7B%0A%09%09%09currentDir = new File(currentDir, tree.getName());%0A%09%09%09if (!currentDir.exists())%0A%09%09%09%09currentDir.mkdir();%0A%09%09%7D%0A%0A%09%09for (Blob blob : tree.getBlobs()) %7B%0A%09%09%09writeBlob(blob);%0A%09%09%7D%0A%0A%09%09for (Tree childTree : tree.getChildTrees()) %7B%0A%09%09%09writeTree(childTree);%0A%09%09%7D%0A%09%09currentDir = parentDir;%0A%09%7D%09%0A%09%0A%09@Override%0A%09public void writeBlob(Blob blob) %7B%0A%09%09if (!currentDir.exists())%0A%09%09%09try %7B%0A%09%09%09%09Files.createParentDirs(currentDir);%0A%09%09%09%09currentDir.mkdir();%0A%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%09// TODO Auto-generated catch block%0A%09%09%09%09e.printStackTrace();%0A%09%09%09%7D%0A%09%09File blobFile = new File(currentDir, blob.getName());%0A%09%09try %7B%0A%09%09%09blobFile.createNewFile();%0A%09%09%09Files.write(blob.getBody(), blobFile, Charsets.US_ASCII);%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%7D
 %0A%7D%0A

copy implementation from TreeWriter