KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > system > LocalIO


1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * 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
21 public class LocalIO
22 {
23     /**
24      * sorts a string alphabetically
25      * probably better off just calling java.util.Arrays.sort
26      */

27     public static String JavaDoc[] sortStrings(String JavaDoc[] array)
28     {
29         for(int i = array.length; --i >= 0;)
30         {
31             boolean swapped = false;
32
33             for(int j = 0; j < i; j++)
34             {
35                 if(array[j].compareTo(array[j + 1]) > 0)
36                 {
37                     String JavaDoc T = new String JavaDoc(array[j]);
38                     array[j] = new String JavaDoc(array[j + 1]);
39                     array[j + 1] = new String JavaDoc(T);
40                     swapped = true;
41                 }
42             }
43
44             if(!swapped)
45             {
46                 break;
47             }
48         }
49
50         return array;
51     }
52
53     /** recursive removal of a local directoy */
54     public static void cleanLocalDir(String JavaDoc dir, String JavaDoc path)
55     {
56         if(dir.endsWith("\\"))
57         {
58             System.out.println("oops... fucked up, need to fix \\-problem!!!");
59         }
60
61         if(!dir.endsWith("/"))
62         {
63             dir = dir + "/";
64         }
65
66         //String remoteDir = StringUtils.removeStart(dir,path);
67
//System.out.println(">>> " + dir);
68
File f2 = new File(path + dir);
69         String JavaDoc[] tmp = f2.list();
70
71         for(int i = 0; i < tmp.length; i++)
72         {
73             File f3 = new File(path + dir + tmp[i]);
74
75             if(f3.isDirectory())
76             {
77                 //System.out.println(dir);
78
cleanLocalDir(dir + tmp[i], path);
79                 f3.delete();
80             }
81             else
82             {
83                 //System.out.println(dir+tmp[i]);
84
f3.delete();
85             }
86         }
87     }
88
89     /** sleep amount of time in millisconds */
90     public static void pause(int time)
91     {
92         try
93         {
94             Thread.sleep(time);
95         }
96         catch(Exception JavaDoc ex)
97         {
98             ex.printStackTrace();
99         }
100     }
101 }
102
Popular Tags