mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
Merge branch 'development' into task/seperated-library-loading
This commit is contained in:
@@ -73,7 +73,7 @@
|
||||
<dependency>
|
||||
<groupId>org.parabot</groupId>
|
||||
<artifactId>internal-api</artifactId>
|
||||
<version>1.4.46</version>
|
||||
<version>1.4.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -210,17 +210,8 @@ public class Core {
|
||||
* Method that removes the cache contents after 3 days
|
||||
*/
|
||||
private static void validateCache() {
|
||||
File[] cache = Directories.getCachePath().listFiles();
|
||||
|
||||
if (cache != null) {
|
||||
for (File f : cache) {
|
||||
long age = new Date().getTime() - f.lastModified();
|
||||
|
||||
if (age > 3 * 24 * 60 * 60 * 1000) {
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Already handled by Directories initiating
|
||||
// Method will be used once BDN V3 has a functionality for this
|
||||
}
|
||||
|
||||
public static void downloadNewVersion() {
|
||||
|
||||
@@ -1,52 +1,10 @@
|
||||
package org.parabot.environment.api.utils;
|
||||
|
||||
import org.parabot.api.misc.StringUtil;
|
||||
|
||||
/**
|
||||
* @author mkyong, JKetelaar
|
||||
*/
|
||||
public class StringUtils {
|
||||
public class StringUtils extends StringUtil {
|
||||
|
||||
private static java.util.Random random = new java.util.Random();
|
||||
private static char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".toCharArray();
|
||||
|
||||
public static String convertHexToString(String hex) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringBuilder temp = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hex.length() - 1; i += 2) {
|
||||
|
||||
// grab the hex in pairs
|
||||
String output = hex.substring(i, (i + 2));
|
||||
// convert hex to decimal
|
||||
int decimal = Integer.parseInt(output, 16);
|
||||
// convert the decimal to character
|
||||
sb.append((char) decimal);
|
||||
|
||||
temp.append(decimal);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String implode(String separator, String... data) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < data.length - 1; i++) {
|
||||
//data.length - 1 => to not add separator at the end
|
||||
if (!data[i].matches(" *")) {//empty string are ""; " "; " "; and so on
|
||||
sb.append(data[i]);
|
||||
sb.append(separator);
|
||||
}
|
||||
}
|
||||
sb.append(data[data.length - 1].trim());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String randomString(final int length) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 20; i++) {
|
||||
char c = chars[random.nextInt(chars.length)];
|
||||
sb.append(c);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.parabot;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.parabot.core.Directories;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author JKetelaar
|
||||
*/
|
||||
public class CacheValidationTest {
|
||||
|
||||
@Test
|
||||
public void test() throws IOException {
|
||||
Directories.validate();
|
||||
|
||||
File fileOne = new File(Directories.getCachePath(), "should-exist.tmp");
|
||||
File fileTwo = new File(Directories.getCachePath(), "should-not-exist.tmp");
|
||||
|
||||
fileOne.createNewFile();
|
||||
fileTwo.createNewFile();
|
||||
|
||||
fileTwo.setLastModified(System.currentTimeMillis() / 1000 - 350000);
|
||||
|
||||
Directories.clearCache(259200, false);
|
||||
|
||||
Assert.assertTrue(fileOne.exists());
|
||||
Assert.assertTrue(!fileTwo.exists());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user