1 | package de.uka.ipd.sdq.sensorframework.tests.util; |
2 | |
3 | // |
4 | // DirDeleter.java |
5 | // |
6 | import java.io.File; |
7 | import java.util.ArrayList; |
8 | import java.util.Iterator; |
9 | |
10 | public class DirDeleter extends Thread |
11 | { |
12 | @SuppressWarnings("unchecked") |
13 | private ArrayList dirList = new ArrayList(); |
14 | |
15 | @SuppressWarnings("unchecked") |
16 | public synchronized void add(File dir) |
17 | { |
18 | dirList.add(dir); |
19 | } |
20 | |
21 | @SuppressWarnings("unchecked") |
22 | public void run() |
23 | { |
24 | synchronized (this) |
25 | { |
26 | Iterator iterator = dirList.iterator(); |
27 | while (iterator.hasNext()) |
28 | { |
29 | File dir = (File)iterator.next(); |
30 | deleteDirectory(dir); |
31 | iterator.remove(); |
32 | } |
33 | } |
34 | } |
35 | |
36 | private void deleteDirectory(File dir) |
37 | { |
38 | File[] fileArray = dir.listFiles(); |
39 | |
40 | if (fileArray != null) |
41 | { |
42 | for (int i = 0; i < fileArray.length; i++) |
43 | { |
44 | if (fileArray[i].isDirectory()) |
45 | deleteDirectory(fileArray[i]); |
46 | else |
47 | fileArray[i].delete(); |
48 | } |
49 | } |
50 | dir.delete(); |
51 | } |
52 | } |