This commit is contained in:
坏黑 2018-10-28 23:17:04 +08:00
parent df51e398b1
commit 4ee0a555aa
3 changed files with 63 additions and 80 deletions

View File

@ -88,6 +88,7 @@
<include>com.ilummc.eagletdl</include>
<include>org.ow2.asm</include>
<include>com.google.code.gson</include>
<include>net.objecthunter</include>
</includes>
</artifactSet>
<createDependencyReducedPom>false</createDependencyReducedPom>
@ -154,6 +155,11 @@
<artifactId>scala-library</artifactId>
<version>2.12.7</version>
</dependency>
<dependency>
<groupId>net.objecthunter</groupId>
<artifactId>exp4j</artifactId>
<version>0.4.8</version>
</dependency>
<dependency>
<groupId>bukkit</groupId>
<artifactId>bukkit1_12</artifactId>

View File

@ -302,76 +302,15 @@ public class FileUtils {
* @param file2 文件2
*/
public static void fileChannelCopy(File file1, File file2) {
FileInputStream fileIn = null;
FileOutputStream fileOut = null;
FileChannel channelIn = null;
FileChannel channelOut = null;
try {
fileIn = new FileInputStream(file1);
fileOut = new FileOutputStream(file2);
channelIn = fileIn.getChannel();
channelOut = fileOut.getChannel();
try (FileInputStream fileIn = new FileInputStream(file1);
FileOutputStream fileOut = new FileOutputStream(file2);
FileChannel channelIn = fileIn.getChannel();
FileChannel channelOut = fileOut.getChannel()) {
channelIn.transferTo(0, channelIn.size(), channelOut);
} catch (IOException ignored) {
} finally {
IOUtils.closeQuietly(channelIn);
IOUtils.closeQuietly(channelOut);
IOUtils.closeQuietly(fileIn);
IOUtils.closeQuietly(fileOut);
}
}
/**
* 通过输入流读取文本
*
* @param in 输入流
* @param size 大小
* @param encode 编码
* @return 文本
*/
public static String getStringFromInputStream(InputStream in, int size, String encode) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[size];
int i;
while ((i = in.read(b)) > 0) {
bos.write(b, 0, i);
}
return new String(bos.toByteArray(), encode);
} catch (IOException ignored) {
}
return null;
}
/**
* 通过文件读取文本
*
* @param file 文件
* @param size 大小
* @param encode 编码
* @return 文本
*/
public static String getStringFromFile(File file, int size, String encode) {
FileInputStream fin = null;
BufferedInputStream bin = null;
try {
fin = new FileInputStream(file);
bin = new BufferedInputStream(fin);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[size];
int i;
while ((i = bin.read(b)) > 0) {
bos.write(b, 0, i);
}
return new String(bos.toByteArray(), encode);
} catch (IOException ignored) {
} finally {
IOUtils.closeQuietly(bin);
IOUtils.closeQuietly(fin);
}
return null;
}
/**
* 通过 URL 读取文本
*
@ -397,14 +336,9 @@ public class FileUtils {
try {
conn = new URL(url).openConnection();
bin = new BufferedInputStream(conn.getInputStream());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[size];
int i;
while ((i = bin.read(b)) > 0) {
bos.write(b, 0, i);
}
return new String(bos.toByteArray(), conn.getContentEncoding() == null ? "UTF-8" : conn.getContentEncoding());
} catch (IOException ignored) {
return getStringFromInputStream(bin, size, conn.getContentEncoding() == null ? "UTF-8" : conn.getContentEncoding());
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.close(conn);
IOUtils.closeQuietly(bin);
@ -412,6 +346,55 @@ public class FileUtils {
return null;
}
/**
* 通过文件读取文本
*
* @param file 文件
* @param size 大小
* @param encode 编码
* @return 文本
*/
public static String getStringFromFile(File file, int size, String encode) {
try (FileInputStream fin = new FileInputStream(file); BufferedInputStream bin = new BufferedInputStream(fin)) {
return getStringFromInputStream(fin, size, encode);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* 通过输入流读取文本
*
* @param in 输入流
* @param size 大小
* @param encode 编码
* @return 文本
*/
public static String getStringFromInputStream(InputStream in, int size, String encode) {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
byte[] b = new byte[size];
int i;
while ((i = in.read(b)) > 0) {
bos.write(b, 0, i);
}
return new String(bos.toByteArray(), encode);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* 下载文件
*
* @param url 下载地址
* @param file 下载位置
*/
public static void download(String url, File file) {
download(url, file, false);
}
/**
* 下载文件
*
@ -440,10 +423,6 @@ public class FileUtils {
}
}
public static void download(String url, File file) {
download(url, file, false);
}
@Deprecated
public static void download(String url, String filename, File saveDir) {
download(url, new File(saveDir, filename));

View File

@ -18,7 +18,6 @@ public class ScriptHandler {
private static ScriptEngine scriptEngine;
private static ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
private static FileConfiguration scriptsFile;
public static void inst() {
try {
@ -31,8 +30,7 @@ public class ScriptHandler {
public static CompiledScript compile(String script) {
try {
Compilable compilable = (Compilable) scriptEngine;
return compilable.compile(script);
return ((Compilable) scriptEngine).compile(script);
} catch (Exception e) {
TLogger.getGlobalLogger().info("§4JavaScript §c" + script + "§4 Compile Failed: §c" + e.toString());
return null;