commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1788350 - /commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java
Date Fri, 24 Mar 2017 00:27:10 GMT
Author: sebb
Date: Fri Mar 24 00:27:09 2017
New Revision: 1788350

URL: http://svn.apache.org/viewvc?rev=1788350&view=rev
Log:
Simplify

Modified:
    commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java

Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java?rev=1788350&r1=1788349&r2=1788350&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java
(original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java
Fri Mar 24 00:27:09 2017
@@ -260,29 +260,19 @@ public class MVSFTPEntryParser extends C
      */
     @Override
     public FTPFile parseFTPEntry(String entry) {
-        boolean isParsed = false;
-        FTPFile f = new FTPFile();
-
         if (isType == FILE_LIST_TYPE) {
-            isParsed = parseFileList(f, entry);
+            return parseFileList(entry);
         } else if (isType == MEMBER_LIST_TYPE) {
-            isParsed = parseMemberList(f, entry);
-            if (!isParsed) {
-                isParsed = parseSimpleEntry(f, entry);
-            }
+            return parseMemberList(entry);
         } else if (isType == UNIX_LIST_TYPE) {
-            return unixFTPEntryParser.parseFTPEntry(entry);
+             return unixFTPEntryParser.parseFTPEntry(entry);
         } else if (isType == JES_LEVEL_1_LIST_TYPE) {
-            isParsed = parseJeslevel1List(f, entry);
+            return parseJeslevel1List(entry);
         } else if (isType == JES_LEVEL_2_LIST_TYPE) {
-            isParsed = parseJeslevel2List(f, entry);
-        }
-
-        if (!isParsed) {
-            f = null;
+            return parseJeslevel2List(entry);
         }
 
-        return f;
+        return null;
     }
 
     /**
@@ -305,13 +295,12 @@ public class MVSFTPEntryParser extends C
      * a tape archive. These entries is currently not supported by this parser.
      * A null value is returned.
      *
-     * @param file
-     *            will be updated with Name, Type, Timestamp if parsed.
      * @param entry zosDirectoryEntry
-     * @return true: entry was parsed, false: entry was not parsed.
+     * @return null: entry was not parsed.
      */
-    private boolean parseFileList(FTPFile file, String entry) {
+    private FTPFile parseFileList(String entry) {
         if (matches(entry)) {
+            FTPFile file = new FTPFile();
             file.setRawListing(entry);
             String name = group(2);
             String dsorg = group(1);
@@ -326,13 +315,13 @@ public class MVSFTPEntryParser extends C
                 file.setType(FTPFile.DIRECTORY_TYPE);
             }
             else {
-                return false;
+                return null;
             }
 
-            return true;
+            return file;
         }
 
-        return false;
+        return null;
     }
 
     /**
@@ -356,12 +345,11 @@ public class MVSFTPEntryParser extends C
      * [9] Id: User id for last update
      * </pre>
      *
-     * @param file
-     *            will be updated with Name, Type and Timestamp if parsed.
      * @param entry zosDirectoryEntry
-     * @return true: entry was parsed, false: entry was not parsed.
+     * @return null: entry was not parsed.
      */
-    private boolean parseMemberList(FTPFile file, String entry) {
+    private FTPFile parseMemberList(String entry) {
+        FTPFile file = new FTPFile();
         if (matches(entry)) {
             file.setRawListing(entry);
             String name = group(1);
@@ -373,32 +361,24 @@ public class MVSFTPEntryParser extends C
             } catch (ParseException e) {
                 // just ignore parsing errors.
                 // TODO check this is ok
-                return false; // this is a parsing failure too.
+                // Drop thru to try simple parser
             }
-            return true;
+            return file;
         }
 
-        return false;
-    }
-
-    /**
-     * Assigns the name to the first word of the entry. Only to be used from a
-     * safe context, for example from a memberlist, where the regex for some
-     * reason fails. Then just assign the name field of FTPFile.
-     *
-     * @param file
-     * @param entry
-     * @return true if the entry string is non-null and non-empty
-     */
-    private boolean parseSimpleEntry(FTPFile file, String entry) {
+        /*
+         * Assigns the name to the first word of the entry. Only to be used from a
+         * safe context, for example from a memberlist, where the regex for some
+         * reason fails. Then just assign the name field of FTPFile.
+         */
         if (entry != null && entry.trim().length() > 0) {
             file.setRawListing(entry);
             String name = entry.split(" ")[0];
             file.setName(name);
             file.setType(FTPFile.FILE_TYPE);
-            return true;
+            return file;
         }
-        return false;
+        return null;
     }
 
     /**
@@ -417,23 +397,22 @@ public class MVSFTPEntryParser extends C
      * [5] The string "Spool Files"
      *</pre>
      *
-     * @param file
-     *            will be updated with Name, Type and Timestamp if parsed.
      * @param entry zosDirectoryEntry
-     * @return true: entry was parsed, false: entry was not parsed.
+     * @return null: entry was not parsed.
      */
-    private boolean parseJeslevel1List(FTPFile file, String entry) {
+    private FTPFile parseJeslevel1List(String entry) {
         if (matches(entry)) {
+            FTPFile file = new FTPFile();
             if (group(3).equalsIgnoreCase("OUTPUT")) {
                 file.setRawListing(entry);
                 String name = group(2); /* Job Number, used by GET */
                 file.setName(name);
                 file.setType(FTPFile.FILE_TYPE);
-                return true;
+                return file;
             }
         }
 
-        return false;
+        return null;
     }
 
     /**
@@ -455,23 +434,22 @@ public class MVSFTPEntryParser extends C
      * [6] The rest
      * </pre>
      *
-     * @param file
-     *            will be updated with Name, Type and Timestamp if parsed.
      * @param entry zosDirectoryEntry
-     * @return true: entry was parsed, false: entry was not parsed.
+     * @return null: entry was not parsed.
      */
-    private boolean parseJeslevel2List(FTPFile file, String entry) {
+    private FTPFile parseJeslevel2List(String entry) {
         if (matches(entry)) {
+            FTPFile file = new FTPFile();
             if (group(4).equalsIgnoreCase("OUTPUT")) {
                 file.setRawListing(entry);
                 String name = group(2); /* Job Number, used by GET */
                 file.setName(name);
                 file.setType(FTPFile.FILE_TYPE);
-                return true;
+                return file;
             }
         }
 
-        return false;
+        return null;
     }
 
     /**



Mime
View raw message