diff --git a/src/main/java/com/gmail/nossr50/config/ConfigLoader.java b/src/main/java/com/gmail/nossr50/config/ConfigLoader.java index 35914f950..31a041496 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigLoader.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigLoader.java @@ -1,7 +1,9 @@ package com.gmail.nossr50.config; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -51,30 +53,45 @@ public abstract class ConfigLoader { InputStream inputStream = plugin.getResource(fileName); - if (inputStream != null) { - try { - copyStreamToFile(inputStream, configFile); + if (inputStream == null) { + plugin.getLogger().severe("Missing resource file: '" + fileName + "' please notify the plugin authors"); + return; + } + + OutputStream outputStream = null; + + try { + outputStream = new FileOutputStream(configFile); + + int read; + byte[] bytes = new byte[1024]; + + while ((read = inputStream.read(bytes)) != -1) { + outputStream.write(bytes, 0, read); } - catch (Exception e) { + } + catch (FileNotFoundException e) { + e.printStackTrace(); + } + catch (IOException e) { + e.printStackTrace(); + } + finally { + if (outputStream != null) { + try { + outputStream.close(); + } + catch (IOException e) { + e.printStackTrace(); + } + } + + try { + inputStream.close(); + } + catch (IOException e) { e.printStackTrace(); } } - else { - plugin.getLogger().severe("Missing resource file: '" + fileName + "' please notify the plugin authors"); - } - } - - private static void copyStreamToFile(InputStream inputStream, File file) throws Exception { - OutputStream outputStream = new FileOutputStream(file); - - int read = 0; - byte[] bytes = new byte[1024]; - - while ((read = inputStream.read(bytes)) != -1) { - outputStream.write(bytes, 0, read); - } - - inputStream.close(); - outputStream.close(); } } diff --git a/src/main/java/com/gmail/nossr50/database/DatabaseManager.java b/src/main/java/com/gmail/nossr50/database/DatabaseManager.java index 01725e485..cc1efe392 100644 --- a/src/main/java/com/gmail/nossr50/database/DatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/DatabaseManager.java @@ -626,15 +626,6 @@ public final class DatabaseManager { } } finally { - if (resultSet != null) { - try { - resultSet.close(); - } - catch (SQLException e) { - // Ignore the error, we're leaving - } - } - if (statement != null) { try { statement.close(); diff --git a/src/main/java/com/gmail/nossr50/util/ItemUtils.java b/src/main/java/com/gmail/nossr50/util/ItemUtils.java index 9f882e2b1..ab9fc612e 100644 --- a/src/main/java/com/gmail/nossr50/util/ItemUtils.java +++ b/src/main/java/com/gmail/nossr50/util/ItemUtils.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.util; -import java.util.HashSet; import java.util.List; import org.bukkit.ChatColor; @@ -675,13 +674,7 @@ public class ItemUtils { * @return true if the item is a miscellaneous drop, false otherwise */ public static boolean isMiscDrop(ItemStack is) { - HashSet miscItems = ItemWeightConfig.getInstance().getMiscItems(); - - if (miscItems.contains(is.getType())) { - return true; - } else { - return false; - } + return ItemWeightConfig.getInstance().getMiscItems().contains(is.getType()); } public static boolean isMcMMOItem(ItemStack is) { diff --git a/src/main/java/com/gmail/nossr50/util/spout/SpoutUtils.java b/src/main/java/com/gmail/nossr50/util/spout/SpoutUtils.java index 1f780b87f..be404e757 100644 --- a/src/main/java/com/gmail/nossr50/util/spout/SpoutUtils.java +++ b/src/main/java/com/gmail/nossr50/util/spout/SpoutUtils.java @@ -6,9 +6,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.util.ArrayList; -import java.util.jar.JarEntry; import java.util.jar.JarFile; import org.bukkit.Material; @@ -51,8 +49,7 @@ public class SpoutUtils { * @param theFilePath The name of the file path */ private static void writeFile(String theFileName, String theFilePath) { - InputStream is = null; - OutputStream os = null; + BufferedOutputStream os = null; JarFile jar = null; try { @@ -64,8 +61,9 @@ public class SpoutUtils { } jar = new JarFile(mcMMO.mcmmo); - JarEntry entry = jar.getJarEntry("resources/" + theFileName); - is = jar.getInputStream(entry); + + @SuppressWarnings("resource") + InputStream is = jar.getInputStream(jar.getJarEntry("resources/" + theFileName)); byte[] buf = new byte[2048]; int nbRead; @@ -75,8 +73,6 @@ public class SpoutUtils { while ((nbRead = is.read(buf)) != -1) { os.write(buf, 0, nbRead); } - - os.flush(); } catch (FileNotFoundException e) { e.printStackTrace(); @@ -85,9 +81,9 @@ public class SpoutUtils { e.printStackTrace(); } finally { - if (is != null) { + if (jar != null) { try { - is.close(); + jar.close(); } catch (IOException ex) { ex.printStackTrace(); @@ -101,15 +97,6 @@ public class SpoutUtils { ex.printStackTrace(); } } - - if (jar != null) { - try { - jar.close(); - } - catch (IOException ex) { - ex.printStackTrace(); - } - } } }