01: /*
02: * This file is part of DrFTPD, Distributed FTP Daemon.
03: *
04: * DrFTPD is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * 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 org.drftpd.remotefile;
19:
20: import java.util.ArrayList;
21: import java.util.Iterator;
22:
23: /**
24: * @author mog
25: * @version $Id: LinkedRemoteFileUtils.java 1471 2006-05-14 04:59:54Z dark $
26: */
27: public class LinkedRemoteFileUtils {
28: protected LinkedRemoteFileUtils() {
29: super ();
30: }
31:
32: // public static void getAllDirectories(LinkedRemoteFileInterface dir,
33: // Collection directories) {
34: // for (Iterator iter = dir.getDirectories().iterator(); iter.hasNext();) {
35: // LinkedRemoteFile subdir = (LinkedRemoteFile) iter.next();
36: // getAllDirectories(subdir, directories);
37: // }
38: //
39: // directories.add(dir);
40: // }
41:
42: // public static void getAllSFVFiles(LinkedRemoteFile dir, Collection sfvFiles) {
43: // for (Iterator iter = dir.getDirectories().iterator(); iter.hasNext();) {
44: // LinkedRemoteFile subdir = (LinkedRemoteFile) iter.next();
45: // getAllSFVFiles(subdir, sfvFiles);
46: // }
47: // sfvFiles.add(dir);
48: // }
49:
50: private static void getAllFilesInternal(
51: LinkedRemoteFileInterface dir,
52: ArrayList<LinkedRemoteFileInterface> files) {
53: for (Iterator iter = dir.getFiles().iterator(); iter.hasNext();) {
54: LinkedRemoteFileInterface file = (LinkedRemoteFileInterface) iter
55: .next();
56:
57: if (file.isDirectory()) {
58: getAllFilesInternal(file, files);
59: } else if (file.isFile()) {
60: files.add(file);
61: } else if (file.isLink()) {
62: // is a symlink, should we do anything?
63: } else {
64: throw new IllegalArgumentException();
65: }
66: }
67: }
68:
69: public static ArrayList<LinkedRemoteFileInterface> getAllFiles(
70: LinkedRemoteFileInterface dir) {
71: ArrayList<LinkedRemoteFileInterface> files = new ArrayList<LinkedRemoteFileInterface>();
72: getAllFilesInternal(dir, files);
73: return files;
74: }
75: }
|