1 25 package org.archive.util; 26 27 import java.io.File ; 28 import java.io.IOException ; 29 30 import junit.framework.TestCase; 31 32 33 39 public class TmpDirTestCase extends TestCase 40 { 41 45 private static final String TEST_TMP_SYSTEM_PROPERTY_NAME = "testtmpdir"; 46 47 50 private static final String DEFAULT_TEST_TMP_DIR = File.separator + "tmp" + 51 File.separator + "heritrix-junit-tests"; 52 53 56 private File tmpDir = null; 57 58 59 public TmpDirTestCase() 60 { 61 super(); 62 } 63 64 public TmpDirTestCase(String testName) 65 { 66 super(testName); 67 } 68 69 72 protected void setUp() throws Exception { 73 super.setUp(); 74 String tmpDirStr = System.getProperty(TEST_TMP_SYSTEM_PROPERTY_NAME); 75 tmpDirStr = (tmpDirStr == null)? DEFAULT_TEST_TMP_DIR: tmpDirStr; 76 this.tmpDir = new File (tmpDirStr); 77 if (!this.tmpDir.exists()) 78 { 79 this.tmpDir.mkdirs(); 80 } 81 82 if (!this.tmpDir.canWrite()) 83 { 84 throw new IOException (this.tmpDir.getAbsolutePath() + 85 " is unwriteable."); 86 } 87 } 88 89 92 protected void tearDown() throws Exception 93 { 94 super.tearDown(); 95 } 96 97 100 public File getTmpDir() 101 { 102 return this.tmpDir; 103 } 104 105 110 public void cleanUpOldFiles(String basename) { 111 cleanUpOldFiles(getTmpDir(), basename); 112 } 113 114 120 public void cleanUpOldFiles(File basedir, String prefix) { 121 File [] files = FileUtils.getFilesWithPrefix(basedir, prefix); 122 if (files != null) { 123 for (int i = 0; i < files.length; i++) { 124 FileUtils.deleteDir(files[i]); 125 } 126 } 127 } 128 } 129 | Popular Tags |