Author: andy
Date: Thu Nov 28 22:07:37 2013
New Revision: 1546465

URL: http://svn.apache.org/r1546465
Log:
Covenice operation to create a unique file name - incremental counter 
guaranteed.
Format -- directory/base(???).ext where (??) is empty or "-1", "-2", ....

Modified:
    jena/trunk/jena-arq/src/main/java/org/apache/jena/atlas/io/IO.java

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/atlas/io/IO.java
URL: 
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/atlas/io/IO.java?rev=1546465&r1=1546464&r2=1546465&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/atlas/io/IO.java 
(original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/atlas/io/IO.java Thu Nov 
28 22:07:37 2013
@@ -302,4 +302,27 @@ public class IO
         return sw.toString();  
     }
 
+    public static String uniqueFilename(String directory, String base, String 
ext) {
+        File d = new File(directory) ;
+        if ( !d.exists() )
+            throw new IllegalArgumentException("Not found: " + directory) ;
+        try {
+            String fn0 = d.getCanonicalPath() + File.separator + base ;
+            String fn = fn0 ;
+            int x = 1 ;
+            while (true) {
+                if ( ext != null )
+                    fn = fn + "."+ext ;
+                File f = new File(fn) ;
+                if ( ! f.exists() )
+                    return fn ;
+                fn = fn0 + "-" + (x++) ;
+            }
+        } catch (IOException e) {
+            IO.exception(e) ;
+            return null ;
+        }
+
+    }
+
 }


Reply via email to