Close file input on exception

This commit is contained in:
snowleo 2011-10-27 00:08:48 +02:00
parent 4b6fc99a62
commit 8200fc2a98

View File

@ -33,29 +33,37 @@ public abstract class AbstractFileCommand implements Command
throw new IOException("Server log not found.");
}
final FileInputStream fis = new FileInputStream(logFile);
if (logFile.length() > 1000000)
try
{
fis.skip(logFile.length() - 1000000);
if (logFile.length() > 1000000)
{
fis.skip(logFile.length() - 1000000);
}
return new BufferedReader(new InputStreamReader(fis));
}
catch (IOException ex)
{
fis.close();
throw ex;
}
return new BufferedReader(new InputStreamReader(fis));
}
protected BufferedReader getPluginConfig(final String pluginName, final String fileName) throws IOException
{
final File configFolder = new File(plugin.getDataFolder().getAbsoluteFile().getParentFile(), pluginName);
if (!configFolder.exists())
{
throw new IOException(pluginName+" plugin folder not found.");
}
final File configFile = new File(configFolder, fileName);
if (!configFile.exists())
{
throw new IOException(pluginName+" plugin file "+fileName+" not found.");
}
return new BufferedReader(new InputStreamReader(new FileInputStream(configFile), UTF8));
if (!configFolder.exists())
{
throw new IOException(pluginName + " plugin folder not found.");
}
final File configFile = new File(configFolder, fileName);
if (!configFile.exists())
{
throw new IOException(pluginName + " plugin file " + fileName + " not found.");
}
return new BufferedReader(new InputStreamReader(new FileInputStream(configFile), UTF8));
}
protected String uploadToPastie(final StringBuilder input) throws IOException
{
if (input.length() > 15000)