01: /*
02: * This program is free software; you can redistribute it and/or
03: * modify it under the terms of the GNU General Public License
04: * as published by the Free Software Foundation; either version 2
05: * of the License, or (at your option) any later version.
06: *
07: * This program is distributed in the hope that it will be useful,
08: * but WITHOUT ANY WARRANTY; without even the implied warranty of
09: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10: * GNU General Public License for more details.
11:
12: * You should have received a copy of the GNU General Public License
13: * along with this program; if not, write to the Free Software
14: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15: */
16: package net.sf.jftp.system;
17:
18: import java.io.*;
19:
20: public class LocalIO {
21: /**
22: * sorts a string alphabetically
23: * probably better off just calling java.util.Arrays.sort
24: */
25: public static String[] sortStrings(String[] array) {
26: for (int i = array.length; --i >= 0;) {
27: boolean swapped = false;
28:
29: for (int j = 0; j < i; j++) {
30: if (array[j].compareTo(array[j + 1]) > 0) {
31: String T = new String(array[j]);
32: array[j] = new String(array[j + 1]);
33: array[j + 1] = new String(T);
34: swapped = true;
35: }
36: }
37:
38: if (!swapped) {
39: break;
40: }
41: }
42:
43: return array;
44: }
45:
46: /** recursive removal of a local directoy */
47: public static void cleanLocalDir(String dir, String path) {
48: if (dir.endsWith("\\")) {
49: System.out
50: .println("oops... fucked up, need to fix \\-problem!!!");
51: }
52:
53: if (!dir.endsWith("/")) {
54: dir = dir + "/";
55: }
56:
57: //String remoteDir = StringUtils.removeStart(dir,path);
58: //System.out.println(">>> " + dir);
59: File f2 = new File(path + dir);
60: String[] tmp = f2.list();
61:
62: for (int i = 0; i < tmp.length; i++) {
63: File f3 = new File(path + dir + tmp[i]);
64:
65: if (f3.isDirectory()) {
66: //System.out.println(dir);
67: cleanLocalDir(dir + tmp[i], path);
68: f3.delete();
69: } else {
70: //System.out.println(dir+tmp[i]);
71: f3.delete();
72: }
73: }
74: }
75:
76: /** sleep amount of time in millisconds */
77: public static void pause(int time) {
78: try {
79: Thread.sleep(time);
80: } catch (Exception ex) {
81: ex.printStackTrace();
82: }
83: }
84: }
|