KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > se > mog > io > UnixFileSystem


1 /*
2  * This file is part of DrFTPD, Distributed FTP Daemon.
3  *
4  * DrFTPD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * DrFTPD is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with DrFTPD; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package se.mog.io;
19
20 import java.io.BufferedReader JavaDoc;
21 import java.io.FileReader JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.util.Enumeration JavaDoc;
24 import java.util.StringTokenizer JavaDoc;
25 import java.util.Vector JavaDoc;
26
27 /**
28  * @author <a HREF="mailto:drftpd@mog.se">Morgan Christiansson</a>
29  *
30  * To change the template for this generated type comment go to
31  * Window>Preferences>Java>Code Generation>Code and Comments
32  */

33 class UnixFileSystem extends FileSystem {
34
35     public File[] listMounts() throws IOException JavaDoc {
36
37         BufferedReader JavaDoc reader = new BufferedReader JavaDoc(new FileReader JavaDoc("/etc/mtab"));
38         try {
39             Vector JavaDoc mountPoints = new Vector JavaDoc();
40             String JavaDoc line;
41             while ((line = reader.readLine()) != null) {
42                 if (line.charAt(0) == '#')
43                     continue;
44                 Enumeration JavaDoc st = new StringTokenizer JavaDoc(line, " \t");
45                 if (!st.hasMoreElements())
46                     continue;
47                 /*String fs_spec = */
48                 st.nextElement();
49                 if (!st.hasMoreElements()) {
50                     System.err.println(
51                         "WARN: /etc/mtab is corrupt, skipping line");
52                     continue;
53                 }
54                 //String fs_file = st.nextToken();
55
mountPoints.add(new File((String JavaDoc) st.nextElement()));
56                 /*
57                 String fs_vfstype = st.nextToken();
58                 String fs_mntops = st.nextToken()
59                 int fs_freq = Integer.parseInt(st.nextToken());
60                 int fs_passno = Integer.parseInt(st.nextToken());
61                 */

62             }
63             return (File[]) mountPoints.toArray(new File[mountPoints.size()]);
64         } finally {
65             reader.close();
66         }
67     }
68
69     public static void main(String JavaDoc args[]) throws IOException JavaDoc {
70         File mounts[] = new UnixFileSystem().listMounts();
71         for (int i = 0; i < mounts.length; i++) {
72             System.out.println(mounts[i]);
73         }
74     }
75
76     public native DiskFreeSpace getDiskFreeSpace(File file);
77 }
78
Popular Tags