From a9ea8e830daf48f47815b682b8e2ba974e1b189c Mon Sep 17 00:00:00 2001 From: Tastybento Date: Sat, 10 Feb 2018 14:05:05 -0800 Subject: [PATCH] Code smells cleanup Extract nested try block into a separate method. --- .../bskyblock/managers/LocalesManager.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java b/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java index 65788007b..37e87f158 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java @@ -79,20 +79,13 @@ public final class LocalesManager { try { for (String name : lister.listJar(LOCALE_FOLDER)) { // We cannot use Bukkit's saveResource, because we want it to go into a specific folder, so... - try (InputStream initialStream = plugin.getResource(name)) { - // Get the last part of the name - int lastIndex = name.lastIndexOf('/'); - File targetFile = new File(localeDir, name.substring(lastIndex >= 0 ? lastIndex : 0, name.length())); - if (DEBUG) { - plugin.getLogger().info("DEBUG: targetFile = " + targetFile.getAbsolutePath()); - } - if (!targetFile.exists()) { - java.nio.file.Files.copy(initialStream, targetFile.toPath()); - } - } catch (IOException e) { - plugin.getLogger().severe("Could not copy locale files from jar " + e.getMessage()); + // Get the last part of the name + int lastIndex = name.lastIndexOf('/'); + File targetFile = new File(localeDir, name.substring(lastIndex >= 0 ? lastIndex : 0, name.length())); + if (DEBUG) { + plugin.getLogger().info("DEBUG: targetFile = " + targetFile.getAbsolutePath()); } - + copyFile(name, targetFile); } } catch (IOException e) { plugin.getLogger().severe("Could not copy locale files from jar " + e.getMessage()); @@ -124,4 +117,16 @@ public final class LocalesManager { } } } + + private void copyFile(String name, File targetFile) { + try (InputStream initialStream = plugin.getResource(name)) { + if (!targetFile.exists()) { + java.nio.file.Files.copy(initialStream, targetFile.toPath()); + } + } catch (IOException e) { + plugin.getLogger().severe("Could not copy locale files from jar " + e.getMessage()); + } + + + } }