1 5 package com.tc.test; 6 7 import org.apache.commons.io.FileUtils; 8 9 import java.io.File ; 10 import java.io.FileNotFoundException ; 11 import java.io.IOException ; 12 13 17 public class TempDirectoryHelper extends BaseDirectoryHelper { 18 19 private final boolean cleanDir; 20 21 public TempDirectoryHelper(Class theClass, boolean cleanDir) throws IOException { 22 this(theClass, TestConfigObject.getInstance().tempDirectoryRoot(), cleanDir); 23 } 24 25 public TempDirectoryHelper(Class theClass) throws IOException { 26 this(theClass, TestConfigObject.getInstance().tempDirectoryRoot(), true); 27 } 28 29 TempDirectoryHelper(Class theClass, String directoryPath, boolean cleanDir) { 31 super(theClass, directoryPath); 32 this.cleanDir = cleanDir; 33 } 34 35 protected File fetchDirectory() throws IOException { 36 File root = getRoot(); 37 if (!root.exists()) { 38 root.mkdirs(); 39 } 40 ClassBasedDirectoryTree tree = new ClassBasedDirectoryTree(getRoot()); 41 File out = tree.getOrMakeDirectory(getTargetClass()); 42 if ((!out.exists()) && (!out.mkdirs())) { 43 FileNotFoundException fnfe = new FileNotFoundException ("Directory '" + out.getAbsolutePath() 44 + "' can't be created."); 45 throw fnfe; 46 } 47 48 if (cleanDir) { 49 FileUtils.cleanDirectory(out); 50 } 51 return out; 52 } 53 54 } | Popular Tags |