mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-12-11 03:43:34 +01:00
Fixed possible stream leak
Thanks, eclipse!
This commit is contained in:
parent
256d4b0abd
commit
322acbc636
@ -3,6 +3,7 @@ package com.onarandombox.MultiverseCore.localization;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
@ -96,22 +97,20 @@ public class SimpleMessageProvider implements LazyLocaleMessageProvider {
|
||||
InputStream resstream = null;
|
||||
InputStream filestream = null;
|
||||
|
||||
try {
|
||||
try {
|
||||
filestream = new FileInputStream(new File(core.getDataFolder(), l.getLanguage() + ".yml"));
|
||||
} catch (FileNotFoundException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
resstream = core.getResource(new StringBuilder(LOCALIZATION_FOLDER_NAME).append("/")
|
||||
.append(l.getLanguage()).append(".yml").toString());
|
||||
resstream = core.getResource(new StringBuilder(LOCALIZATION_FOLDER_NAME)
|
||||
.append("/").append(l.getLanguage()).append(".yml").toString());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
if ((resstream == null) && (filestream == null))
|
||||
throw new NoSuchLocalizationException(l);
|
||||
|
||||
messages.put(l, new HashMap<MultiverseMessage, String>(MultiverseMessage.values().length));
|
||||
|
||||
messages.put(l, new HashMap<MultiverseMessage, String>(
|
||||
MultiverseMessage.values().length));
|
||||
FileConfiguration resconfig = (resstream == null) ? null : YamlConfiguration.loadConfiguration(resstream);
|
||||
FileConfiguration fileconfig = (filestream == null) ? null : YamlConfiguration.loadConfiguration(filestream);
|
||||
for (MultiverseMessage m : MultiverseMessage.values()) {
|
||||
@ -124,6 +123,20 @@ public class SimpleMessageProvider implements LazyLocaleMessageProvider {
|
||||
|
||||
messages.get(l).put(m, value);
|
||||
}
|
||||
} finally {
|
||||
if (filestream != null)
|
||||
try {
|
||||
filestream.close();
|
||||
} catch (IOException e) {
|
||||
// silently discard
|
||||
}
|
||||
if (resstream != null)
|
||||
try {
|
||||
resstream.close();
|
||||
} catch (IOException e) {
|
||||
// silently discard
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user