diff --git a/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java b/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java index 0b2b132ab..4b0178e6e 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java @@ -34,10 +34,7 @@ import org.reflections.Reflections; import org.reflections.serializers.XmlSerializer; import org.reflections.util.ConfigurationBuilder; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.net.URL; import java.nio.file.Files; import java.security.MessageDigest; @@ -168,7 +165,7 @@ public class FileUtils { byte[] sha256; try { - sha256 = MessageDigest.getInstance("SHA-256").digest(Files.readAllBytes(file.toPath())); + sha256 = MessageDigest.getInstance("SHA-256").digest(readAllBytes(file)); } catch (Exception e) { throw new RuntimeException("Could not calculate pack hash", e); } @@ -186,7 +183,7 @@ public class FileUtils { byte[] sha1; try { - sha1 = MessageDigest.getInstance("SHA-1").digest(Files.readAllBytes(file.toPath())); + sha1 = MessageDigest.getInstance("SHA-1").digest(readAllBytes(file)); } catch (Exception e) { throw new RuntimeException("Could not calculate pack hash", e); } @@ -210,4 +207,22 @@ public class FileUtils { return reflections; } + + /** + * An android compatible version of {@link Files#readAllBytes} + * + * @param file File to read bytes of + * @return The byte array of the file + */ + public static byte[] readAllBytes(File file) { + int size = (int) file.length(); + byte[] bytes = new byte[size]; + try { + BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file)); + buf.read(bytes, 0, bytes.length); + buf.close(); + } catch (IOException ignored) { } + + return bytes; + } } diff --git a/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java b/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java index aac344dc6..664ef208f 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java @@ -140,9 +140,10 @@ public class LocaleUtils { if (locale.equals("en_us")) { try { - Path hashFile = GeyserConnector.getInstance().getBootstrap().getConfigFolder().resolve("locales/en_us.hash"); - if (hashFile.toFile().exists()) { - curHash = String.join("", Files.readAllLines(hashFile)); + File hashFile = GeyserConnector.getInstance().getBootstrap().getConfigFolder().resolve("locales/en_us.hash").toFile(); + if (hashFile.exists()) { + BufferedReader br = new BufferedReader(new FileReader(hashFile)); + curHash = br.readLine().trim(); } } catch (IOException ignored) { } targetHash = clientJarInfo.getSha1();