From 16d0b5c228dd8d981a0d79944c70248ea813d63b Mon Sep 17 00:00:00 2001 From: ementalo Date: Wed, 27 Jun 2012 13:35:39 +0100 Subject: package name change to net.ess3 --- .../net/ess3/update/chat/AbstractFileCommand.java | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 EssentialsUpdate/src/net/ess3/update/chat/AbstractFileCommand.java (limited to 'EssentialsUpdate/src/net/ess3/update/chat/AbstractFileCommand.java') diff --git a/EssentialsUpdate/src/net/ess3/update/chat/AbstractFileCommand.java b/EssentialsUpdate/src/net/ess3/update/chat/AbstractFileCommand.java new file mode 100644 index 000000000..2e6d44f20 --- /dev/null +++ b/EssentialsUpdate/src/net/ess3/update/chat/AbstractFileCommand.java @@ -0,0 +1,75 @@ +package net.ess3.update.chat; + +import net.ess3.update.PastieUpload; +import java.io.*; +import java.nio.charset.Charset; + +import net.ess3.update.PastieUpload; +import org.bukkit.plugin.Plugin; + + +public abstract class AbstractFileCommand implements Command +{ + private final transient Plugin plugin; + private final static Charset UTF8 = Charset.forName("utf-8"); + + public AbstractFileCommand(final Plugin plugin) + { + this.plugin = plugin; + } + + protected BufferedReader getServerLogReader() throws IOException + { + final File bukkitFolder = plugin.getDataFolder().getAbsoluteFile().getParentFile().getParentFile(); + if (bukkitFolder == null || !bukkitFolder.exists()) + { + throw new IOException("Bukkit folder not found."); + } + final File logFile = new File(bukkitFolder, "server.log"); + if (!logFile.exists()) + { + throw new IOException("Server log not found."); + } + final FileInputStream fis = new FileInputStream(logFile); + try + { + if (logFile.length() > 1000000) + { + fis.skip(logFile.length() - 1000000); + } + return new BufferedReader(new InputStreamReader(fis)); + } + catch (IOException ex) + { + fis.close(); + throw ex; + } + } + + 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)); + + } + + protected String uploadToPastie(final StringBuilder input) throws IOException + { + if (input.length() > 15000) + { + input.delete(0, input.length() - 15000); + input.append("## Cropped after 15000 bytes"); + } + final PastieUpload pastie = new PastieUpload(); + return pastie.send(input.toString()); + } +} -- cgit v1.2.3