Split code.

This commit is contained in:
Christian P. MOMON 2013-08-23 02:58:41 +02:00
parent 8cca172abd
commit c0b41a43ea

View file

@ -24,6 +24,45 @@ import java.net.URL;
*/ */
public class FileTools public class FileTools
{ {
/**
*
*
* @param fileName
* Source.
*
* @return Extension value or null.
*/
public static String addBeforeExtension(final String fileName, final String addition)
{
String result;
if (fileName == null)
{
result = null;
}
else if (addition == null)
{
result = fileName;
}
else
{
//
int separatorIndex = fileName.lastIndexOf('.');
//
if (separatorIndex > 0)
{
result = fileName.substring(0, separatorIndex) + addition + fileName.substring(separatorIndex);
}
else
{
result = fileName + addition;
}
}
//
return result;
}
/** /**
* *
@ -49,20 +88,7 @@ public class FileTools
{ {
// //
String sourceFileName = file.getAbsolutePath(); String sourceFileName = file.getAbsolutePath();
int separatorIndex = sourceFileName.lastIndexOf('.'); String targetFileName = addBeforeExtension(sourceFileName, addition);
//
String targetFileName;
if (separatorIndex > 0)
{
targetFileName = sourceFileName.substring(0, separatorIndex) + addition + sourceFileName.substring(separatorIndex);
}
else
{
targetFileName = sourceFileName + addition;
}
//
result = new File(targetFileName); result = new File(targetFileName);
} }