From c0b41a43ea5670ab07b9c8c949fa7806461fa62b Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Fri, 23 Aug 2013 02:58:41 +0200 Subject: [PATCH] Split code. --- src/fr/devinsy/util/FileTools.java | 54 ++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/src/fr/devinsy/util/FileTools.java b/src/fr/devinsy/util/FileTools.java index c33c125..47b30cd 100644 --- a/src/fr/devinsy/util/FileTools.java +++ b/src/fr/devinsy/util/FileTools.java @@ -24,6 +24,45 @@ import java.net.URL; */ 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(); - int separatorIndex = sourceFileName.lastIndexOf('.'); - - // - String targetFileName; - if (separatorIndex > 0) - { - targetFileName = sourceFileName.substring(0, separatorIndex) + addition + sourceFileName.substring(separatorIndex); - } - else - { - targetFileName = sourceFileName + addition; - } - - // + String targetFileName = addBeforeExtension(sourceFileName, addition); result = new File(targetFileName); }