mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-20 23:31:23 +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.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -97,32 +98,44 @@ public class SimpleMessageProvider implements LazyLocaleMessageProvider {
|
|||||||
InputStream filestream = null;
|
InputStream filestream = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
filestream = new FileInputStream(new File(core.getDataFolder(), l.getLanguage() + ".yml"));
|
try {
|
||||||
} catch (FileNotFoundException e) {
|
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());
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
if ((resstream == null) && (filestream == null))
|
||||||
|
throw new NoSuchLocalizationException(l);
|
||||||
|
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()) {
|
||||||
|
String value = m.getDefault();
|
||||||
|
|
||||||
try {
|
if (resconfig != null)
|
||||||
resstream = core.getResource(new StringBuilder(LOCALIZATION_FOLDER_NAME).append("/")
|
value = resconfig.getString(m.toString(), value);
|
||||||
.append(l.getLanguage()).append(".yml").toString());
|
if (fileconfig != null)
|
||||||
} catch (Exception e) {
|
value = fileconfig.getString(m.toString(), value);
|
||||||
}
|
|
||||||
|
|
||||||
if ((resstream == null) && (filestream == null))
|
messages.get(l).put(m, value);
|
||||||
throw new NoSuchLocalizationException(l);
|
}
|
||||||
|
} finally {
|
||||||
messages.put(l, new HashMap<MultiverseMessage, String>(MultiverseMessage.values().length));
|
if (filestream != null)
|
||||||
|
try {
|
||||||
FileConfiguration resconfig = (resstream == null) ? null : YamlConfiguration.loadConfiguration(resstream);
|
filestream.close();
|
||||||
FileConfiguration fileconfig = (filestream == null) ? null : YamlConfiguration.loadConfiguration(filestream);
|
} catch (IOException e) {
|
||||||
for (MultiverseMessage m : MultiverseMessage.values()) {
|
// silently discard
|
||||||
String value = m.getDefault();
|
}
|
||||||
|
if (resstream != null)
|
||||||
if (resconfig != null)
|
try {
|
||||||
value = resconfig.getString(m.toString(), value);
|
resstream.close();
|
||||||
if (fileconfig != null)
|
} catch (IOException e) {
|
||||||
value = fileconfig.getString(m.toString(), value);
|
// silently discard
|
||||||
|
}
|
||||||
messages.get(l).put(m, value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user