commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r963317 - in /commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp: FTPFileFilter.java FTPFileFilters.java FTPListParseEngine.java
Date Mon, 12 Jul 2010 15:17:22 GMT
Author: sebb
Date: Mon Jul 12 15:17:20 2010
New Revision: 963317

URL: http://svn.apache.org/viewvc?rev=963317&view=rev
Log:
NET-244 Add low-level support for FTPFileFilter filters

Added:
    commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPFileFilter.java
  (with props)
    commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPFileFilters.java
  (with props)
Modified:
    commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPListParseEngine.java

Added: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPFileFilter.java?rev=963317&view=auto
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPFileFilter.java
(added)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPFileFilter.java
Mon Jul 12 15:17:20 2010
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ */
+
+package org.apache.commons.net.ftp;
+
+/**
+ * Perform filtering on FTPFile entries.
+ */
+public interface FTPFileFilter {
+    /**
+     * Checks if an FTPFile entry should be included or not.
+     * 
+     * @param file entry to be checked for inclusion. May be <code>null</code>.
+     * @return <code>true</code> if the file is to be included, <code>false</code>
otherwise
+     */
+    public boolean accept(FTPFile file);
+}

Propchange: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPFileFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPFileFilter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPFileFilters.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPFileFilters.java?rev=963317&view=auto
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPFileFilters.java
(added)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPFileFilters.java
Mon Jul 12 15:17:20 2010
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ */
+
+package org.apache.commons.net.ftp;
+
+/**
+ * Implements some simple FTPFileFilter classes.
+ */
+public class FTPFileFilters {
+
+    /**
+     * Accepts all FTPFile entries, including null
+     */
+    public static final FTPFileFilter ALL = new FTPFileFilter() {
+        public boolean accept(FTPFile file) {
+            return true;
+        }
+    };
+
+    /**
+     * Accepts all non-null FTPFile entries
+     */
+    public static final FTPFileFilter NON_NULL = new FTPFileFilter() {
+        public boolean accept(FTPFile file) {
+            return file != null;
+        }
+    };
+
+    /**
+     * Accepts all (non-null) FTPFile directory entries
+     */
+    public static final FTPFileFilter DIRECTORIES = new FTPFileFilter() {
+        public boolean accept(FTPFile file) {
+            return file != null && file.isDirectory();
+        }
+    };
+
+}

Propchange: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPFileFilters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPFileFilters.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPListParseEngine.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPListParseEngine.java?rev=963317&r1=963316&r2=963317&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPListParseEngine.java
(original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPListParseEngine.java
Mon Jul 12 15:17:20 2010
@@ -21,6 +21,7 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -247,14 +248,40 @@ public class FTPListParseEngine {
     public FTPFile[] getFiles()
     throws IOException
     {
-        List<FTPFile> tmpResults = new LinkedList<FTPFile>();
+        return getFiles(FTPFileFilters.ALL);
+    }
+
+    /**
+     * Returns an array of FTPFile objects containing the whole list of
+     * files returned by the server as read by this object's parser.
+     * The files are filtered before being added to the array.
+     * 
+     * @param filter FTPFileFilter, must not be <code>null</code>.
+     * 
+     * @return an array of FTPFile objects containing the whole list of
+     *         files returned by the server as read by this object's parser.
+     * <p><b> 
+     * NOTE:</b> This array may contain null members if any of the 
+     * individual file listings failed to parse.  The caller should 
+     * check each entry for null before referencing it, or use the
+     * a filter such as {@link FTPFileFilters#NON_NULL} which does not 
+     * allow null entries.
+     * 
+     * @exception IOException
+     */
+    public FTPFile[] getFiles(FTPFileFilter filter)
+    throws IOException
+    {
+        List<FTPFile> tmpResults = new ArrayList<FTPFile>();
         Iterator<String> iter = this.entries.iterator();
         while (iter.hasNext()) {
             String entry = iter.next();
             FTPFile temp = this.parser.parseFTPEntry(entry);
-            tmpResults.add(temp);
+            if (filter.accept(temp)){
+                tmpResults.add(temp);
+            }
         }
-        return tmpResults.toArray(new FTPFile[0]);
+        return tmpResults.toArray(new FTPFile[tmpResults.size()]);
 
     }
 



Mime
View raw message