Repository: commons-cli
Updated Branches:
  refs/heads/master 70a392756 -> 0b453953f


implement EXISTING_FILE_VALUE type handler

when the user pass option type FileInputStream.class, I think the expected 
behavior for the return value is the same type, which the user passed.
Before this there was no check whether the file exist.

Project: http://git-wip-us.apache.org/repos/asf/commons-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-cli/commit/abfcc821
Tree: http://git-wip-us.apache.org/repos/asf/commons-cli/tree/abfcc821
Diff: http://git-wip-us.apache.org/repos/asf/commons-cli/diff/abfcc821

Branch: refs/heads/master
Commit: abfcc8211f529ab75f3b3edd4a827e484109eb0b
Parents: a41477b
Author: Bela Schaum <scha...@users.noreply.github.com>
Authored: Mon Apr 17 13:45:09 2017 +0200
Committer: GitHub <nore...@github.com>
Committed: Mon Apr 17 13:45:09 2017 +0200

----------------------------------------------------------------------
 .../org/apache/commons/cli/TypeHandler.java     | 21 +++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-cli/blob/abfcc821/src/main/java/org/apache/commons/cli/TypeHandler.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/cli/TypeHandler.java 
b/src/main/java/org/apache/commons/cli/TypeHandler.java
index f981265..4654f1d 100644
--- a/src/main/java/org/apache/commons/cli/TypeHandler.java
+++ b/src/main/java/org/apache/commons/cli/TypeHandler.java
@@ -18,6 +18,7 @@
 package org.apache.commons.cli;
 
 import java.io.File;
+import java.io.FileInputStream;
 
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -87,7 +88,7 @@ public class TypeHandler
         }
         else if (PatternOptionBuilder.EXISTING_FILE_VALUE == clazz)
         {
-            return createFile(str);
+            return openFile(str);
         }
         else if (PatternOptionBuilder.FILES_VALUE == clazz)
         {
@@ -223,6 +224,24 @@ public class TypeHandler
     }
 
     /**
+     * Returns the opened FileInputStream represented by <code>str</code>.
+     *
+     * @param str the file location
+     * @return The file input stream represented by <code>str</code>.
+     */
+    public static FileInputStream openFile(String str) throws ParseException
+    {
+        try
+        {
+            return new FileInputStream(str);
+        }
+        catch (FileNotFoundException e)
+        {
+            throw new ParseException("Unable to find file: " + str);
+        }
+    }
+
+    /**
      * Returns the File[] represented by <code>str</code>.
      * <p>
      * This method is not yet implemented and always throws an

Reply via email to