diff --git a/common/source/java/ch/systemsx/cisd/common/utilities/FileUtilities.java b/common/source/java/ch/systemsx/cisd/common/utilities/FileUtilities.java index a4fd2b8c61c35e661bb3886e60a49c931d06a3fc..8c41ad8126e58baddbb51f55707dc640e975142e 100644 --- a/common/source/java/ch/systemsx/cisd/common/utilities/FileUtilities.java +++ b/common/source/java/ch/systemsx/cisd/common/utilities/FileUtilities.java @@ -478,7 +478,7 @@ public final class FileUtilities * @param defaultFileName the default name for the new file if the digit pattern could not be found (probably the * starting file). * @param regex pattern to find out the counter. If <code>null</code> then {@link #ONE_OR_MORE_DIGITS}} will be - * taken. The given <var>regex</var> must contain <code>(\\d+)</code>. + * taken. The given <var>regex</var> must contain <code>(\\d+)</code> or <code>([0-9]+)</code>. */ public final static File createNextNumberedFile(File path, Pattern regex, String defaultFileName) { @@ -491,7 +491,7 @@ public final class FileUtilities { pattern = regex; } - assert pattern.pattern().indexOf("(\\d+)") > -1; + assert pattern.pattern().indexOf("(\\d+)") > -1 || pattern.pattern().indexOf("([0-9]+)") > -1; String pathName = path.getName(); final Matcher matcher = pattern.matcher(pathName); diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/FileUtilitiesTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/FileUtilitiesTest.java index 56f446b9ab45f9ebed1f9fe5f0c52b6460e7d21e..57c82262047b5b77b5c3dec1fa3505ff9b69e032 100644 --- a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/FileUtilitiesTest.java +++ b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/FileUtilitiesTest.java @@ -190,6 +190,14 @@ public class FileUtilitiesTest { // Nothing to do here } + try + { + FileUtilities.createNextNumberedFile(file, Pattern.compile("dummyPattern"), "abc_[1]"); + fail("Must contain either '(\\d+)' or ([0-9]+)."); + } catch (AssertionError e) + { + // Nothing to do here + } newFile = FileUtilities.createNextNumberedFile(file, pattern, "abc_[1]"); assertEquals(FilenameUtils.getName(new File(workingDirectory, "abc_[1]").getPath()), FilenameUtils .getName(newFile.getPath()));