diff --git a/launcher/src/main/java/com/skcraft/launcher/util/LocaleEncodingControl.java b/launcher/src/main/java/com/skcraft/launcher/util/LocaleEncodingControl.java index 33d942040..72e5932e1 100644 --- a/launcher/src/main/java/com/skcraft/launcher/util/LocaleEncodingControl.java +++ b/launcher/src/main/java/com/skcraft/launcher/util/LocaleEncodingControl.java @@ -34,13 +34,7 @@ public ResourceBundle newBundle(String baseName, Locale locale, String format, C bis.mark(3); { byte[] buf = new byte[3]; - int nread = 0; - while (nread < 3) { - int read = bis.read(buf); - - if (read == -1) throw new EOFException("Locale file is truncated or empty!"); - nread += read; - } + readFully(bis, buf); // the BOM is 0xEF,0xBB,0xBF isUtf8 = buf[0] == (byte) 0xEF && buf[1] == (byte) 0xBB && buf[2] == (byte) 0xBF; @@ -80,4 +74,19 @@ private InputStream getResourceAsStream(String resourceName, ClassLoader loader, return loader.getResourceAsStream(resourceName); } + + private void readFully(InputStream is, byte[] buf) throws IOException { + int offset = 0; + int length = buf.length; + + while (length > 0) { + int n = is.read(buf, offset, length); + if (n == -1) { + throw new EOFException(); + } + + offset += n; + length -= n; + } + } }