From 1cabe6c14c3b1d08401b54ceba6c9d50dd390e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Tue, 9 Jul 2019 21:53:38 +0800 Subject: [PATCH] Update Files.java --- src/main/scala/io/izzel/taboolib/util/Files.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/scala/io/izzel/taboolib/util/Files.java b/src/main/scala/io/izzel/taboolib/util/Files.java index d5ee309..056b213 100644 --- a/src/main/scala/io/izzel/taboolib/util/Files.java +++ b/src/main/scala/io/izzel/taboolib/util/Files.java @@ -224,6 +224,10 @@ public class Files { return Optional.ofNullable(readFromURL(url)).orElse(def); } + public static String readFromURL(String url, Charset charset, String def) { + return Optional.ofNullable(readFromURL(url, charset)).orElse(def); + } + public static String readFromURL(String url) { try (InputStream inputStream = new URL(url).openStream(); BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream)) { return new String(IO.readFully(bufferedInputStream)); @@ -233,6 +237,15 @@ public class Files { return null; } + public static String readFromURL(String url, Charset charset) { + try (InputStream inputStream = new URL(url).openStream(); BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream)) { + return new String(IO.readFully(bufferedInputStream), charset); + } catch (Throwable t) { + t.printStackTrace(); + } + return null; + } + public static String readFromFile(File file) { return readFromFile(file, 1024, StandardCharsets.UTF_8); }