Skip to content
Snippets Groups Projects
Commit 8a51f79a authored by ribeaudc's avatar ribeaudc
Browse files

change:

- Improvements done in 'BDSStorageProcessor'.

SVN: 3087
parent 5ddb52f3
No related branches found
No related tags found
No related merge requests found
......@@ -603,8 +603,8 @@ public final class FileUtilities
* If the new suggested file already exists, then this method is called recursively.
* </p>
*
* @param defaultFileNameOrNull the default name for the new file if the digit pattern could not be found in its name. If
* empty then "1" will be appended to its name.
* @param defaultFileNameOrNull the default name for the new file if the digit pattern could not be found in its
* name. If empty then "1" will be appended to its name.
* @param regexOrNull pattern to find out the counter. If <code>null</code> then a default (<code>(\\d+)</code>)
* will be used. The given <var>regex</var> must contain <code>(\\d+)</code> or <code>([0-9]+)</code>.
*/
......@@ -660,7 +660,7 @@ public final class FileUtilities
}
/**
* For given <var>root</var> and <var>file</var> extracts the relative <code>File</code>.
* For given <var>root</var> and <var>file</var> extracts the relative path.
* <p>
* If given <var>file</var> does not contain given <var>root</var> path in its absolute path, then returns
* <code>null</code> (as the relative file could not be determined).
......@@ -668,17 +668,15 @@ public final class FileUtilities
*
* @return a relative file with no starting separator.
*/
public final static String getRelativeFile(final String root, final String file)
public final static String getRelativeFile(final File root, final File file)
{
assert file != null;
if (StringUtils.isEmpty(root))
{
return file;
}
final String strRoot = root + File.separator;
if (file.startsWith(strRoot))
assert root != null : "Given root can not be null.";
assert file != null : "Given file can not be null.";
final String rootPath = root.getAbsolutePath() + File.separator;
final String filePath = file.getAbsolutePath();
if (filePath.startsWith(rootPath))
{
return file.substring(strRoot.length());
return filePath.substring(rootPath.length());
} else
{
return null;
......
......@@ -326,21 +326,23 @@ public class FileUtilitiesTest
try
{
FileUtilities.getRelativeFile(null, null);
fail("Given file can not be null.");
fail("Given root and file can not be null.");
} catch (AssertionError e)
{
// Nothing to do here
}
File file = new File(workingDirectory, "hello");
assertEquals(workingDirectory.getAbsolutePath() + File.separator + "hello", file.getAbsolutePath());
assertEquals(file.getAbsolutePath(), FileUtilities.getRelativeFile(null, file.getAbsolutePath()));
assertEquals(file.getAbsolutePath(), FileUtilities.getRelativeFile("", file.getAbsolutePath()));
// If the given string is the empty string, then the result is the empty abstract pathname.
final File rootFile = new File("");
System.out.println(rootFile.getAbsolutePath());
assertEquals("targets" + File.separator + workingDirectory.getName() + File.separator + "hello", FileUtilities
.getRelativeFile(rootFile, file));
String root = "/temp";
assertEquals("/temp", root);
String relativeFile = FileUtilities.getRelativeFile(root, file.getAbsolutePath());
String relativeFile = FileUtilities.getRelativeFile(new File(root), file);
assertNull(relativeFile);
root = workingDirectory.getAbsolutePath();
relativeFile = FileUtilities.getRelativeFile(root, file.getAbsolutePath());
relativeFile = FileUtilities.getRelativeFile(new File(root), file);
assertEquals("hello", relativeFile);
}
......@@ -398,19 +400,19 @@ public class FileUtilitiesTest
f.deleteOnExit();
Timer t = new Timer();
t.schedule(new TimerTask()
{
@Override
public void run()
{
try
{
f.createNewFile();
} catch (IOException ex)
@Override
public void run()
{
throw new CheckedExceptionTunnel(ex);
try
{
f.createNewFile();
} catch (IOException ex)
{
throw new CheckedExceptionTunnel(ex);
}
}
}
}, 250L);
}, 250L);
assertTrue(FileUtilities.isAvailable(f, 500L));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment