diff options
author | ElgarL <ElgarL@palmergames.com> | 2012-04-13 14:40:26 +0100 |
---|---|---|
committer | ElgarL <ElgarL@palmergames.com> | 2012-04-13 14:40:26 +0100 |
commit | a028abe03630c1990105f5dbfef5ba44bf11602d (patch) | |
tree | c63635515b5d9138063b6520a62b06eab4e34a4f /EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java | |
parent | 677534c0b7319691c3139559943b2a5c4e8d2c88 (diff) | |
download | Essentials-a028abe03630c1990105f5dbfef5ba44bf11602d.tar Essentials-a028abe03630c1990105f5dbfef5ba44bf11602d.tar.gz Essentials-a028abe03630c1990105f5dbfef5ba44bf11602d.tar.lz Essentials-a028abe03630c1990105f5dbfef5ba44bf11602d.tar.xz Essentials-a028abe03630c1990105f5dbfef5ba44bf11602d.zip |
Update all code formatting to use tabs for indentation.
Diffstat (limited to 'EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java')
-rw-r--r-- | EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java | 216 |
1 files changed, 112 insertions, 104 deletions
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java index 663da1123..d75737c66 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java @@ -22,13 +22,12 @@ import java.util.List; import org.anjocaido.groupmanager.GroupManager; import org.anjocaido.groupmanager.data.Group; - /** - * + * * @author gabrielcouto */ public abstract class Tasks { - + /** * Gets the exception stack trace as a string. * @@ -36,35 +35,38 @@ public abstract class Tasks { * @return stack trace as a string */ public static String getStackTraceAsString(Exception exception) { + StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); exception.printStackTrace(pw); return sw.toString(); } - public static void copy(InputStream src, File dst) throws IOException { - InputStream in = src; - OutputStream out = new FileOutputStream(dst); - - // Transfer bytes from in to out - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - } - out.close(); - try { - in.close(); - } catch (Exception e) { - } - } - - public static void copy(File src, File dst) throws IOException { - InputStream in = new FileInputStream(src); - copy(in, dst); - } - - /** + public static void copy(InputStream src, File dst) throws IOException { + + InputStream in = src; + OutputStream out = new FileOutputStream(dst); + + // Transfer bytes from in to out + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + out.close(); + try { + in.close(); + } catch (Exception e) { + } + } + + public static void copy(File src, File dst) throws IOException { + + InputStream in = new FileInputStream(src); + copy(in, dst); + } + + /** * Appends a string to a file * * @param data @@ -82,86 +84,92 @@ public abstract class Tasks { out.append(System.getProperty("line.separator")); out.append(data); out.append(System.getProperty("line.separator")); - + out.close(); } - public static void removeOldFiles(GroupManager gm, File folder) { - if (folder.isDirectory()) { - long oldTime = System.currentTimeMillis() - (((long)gm.getGMConfig().getBackupDuration()*60*60)*1000); - for (File olds : folder.listFiles()) { - if (olds.isFile()) { - if (olds.lastModified() < oldTime) { - try { - olds.delete(); - } catch (Exception e) { - } - } - } - } - } - } - - public static String getDateString() { - GregorianCalendar now = new GregorianCalendar(); - String date = ""; - date += now.get(Calendar.DAY_OF_MONTH); - date += "-"; - date += now.get(Calendar.HOUR); - date += "-"; - date += now.get(Calendar.MINUTE); - return date; - } - - public static String getStringListInString(List<String> list) { - if (list == null) { - return ""; - } - String result = ""; - for (int i = 0; i < list.size(); i++) { - result += list.get(i); - if (i < list.size() - 1) { - result += ", "; - } - } - return result; - } - - public static String getStringArrayInString(String[] list) { - if (list == null) { - return ""; - } - String result = ""; - for (int i = 0; i < list.length; i++) { - result += list[i]; - if (i < ((list.length) - 1)) { - result += ", "; - } - } - return result; - } - - public static String getGroupListInString(List<Group> list) { - if (list == null) { - return ""; - } - String result = ""; - for (int i = 0; i < list.size(); i++) { - result += list.get(i).getName(); - if (i < list.size() - 1) { - result += ", "; - } - } - return result; - } - - public static String join(String[] arr, String separator) { - if (arr.length == 0) - return ""; - String out = arr[0].toString(); - for (int i = 1; i < arr.length; i++) - out += separator + arr[i]; - return out; - } + public static void removeOldFiles(GroupManager gm, File folder) { + + if (folder.isDirectory()) { + long oldTime = System.currentTimeMillis() - (((long) gm.getGMConfig().getBackupDuration() * 60 * 60) * 1000); + for (File olds : folder.listFiles()) { + if (olds.isFile()) { + if (olds.lastModified() < oldTime) { + try { + olds.delete(); + } catch (Exception e) { + } + } + } + } + } + } + + public static String getDateString() { + + GregorianCalendar now = new GregorianCalendar(); + String date = ""; + date += now.get(Calendar.DAY_OF_MONTH); + date += "-"; + date += now.get(Calendar.HOUR); + date += "-"; + date += now.get(Calendar.MINUTE); + return date; + } + + public static String getStringListInString(List<String> list) { + + if (list == null) { + return ""; + } + String result = ""; + for (int i = 0; i < list.size(); i++) { + result += list.get(i); + if (i < list.size() - 1) { + result += ", "; + } + } + return result; + } + + public static String getStringArrayInString(String[] list) { + + if (list == null) { + return ""; + } + String result = ""; + for (int i = 0; i < list.length; i++) { + result += list[i]; + if (i < ((list.length) - 1)) { + result += ", "; + } + } + return result; + } + + public static String getGroupListInString(List<Group> list) { + + if (list == null) { + return ""; + } + String result = ""; + for (int i = 0; i < list.size(); i++) { + result += list.get(i).getName(); + if (i < list.size() - 1) { + result += ", "; + } + } + return result; + } + + public static String join(String[] arr, String separator) { + + if (arr.length == 0) + return ""; + String out = arr[0].toString(); + for (int i = 1; i < arr.length; i++) + out += separator + arr[i]; + return out; + } } |