mirror of
https://github.com/SKCraft/Launcher.git
synced 2024-11-24 12:16:28 +01:00
parent
23e01defea
commit
90ff8dfdb7
@ -2,10 +2,7 @@ package com.skcraft.launcher.util;
|
|||||||
|
|
||||||
import lombok.extern.java.Log;
|
import lombok.extern.java.Log;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
@ -30,27 +27,32 @@ public class LocaleEncodingControl extends ResourceBundle.Control {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BufferedInputStream bis = new BufferedInputStream(is);
|
||||||
|
|
||||||
// Let's do the timewalk
|
// Let's do the timewalk
|
||||||
boolean isUtf8;
|
boolean isUtf8;
|
||||||
is.mark(3);
|
bis.mark(3);
|
||||||
{
|
{
|
||||||
byte[] buf = new byte[3];
|
byte[] buf = new byte[3];
|
||||||
int read = 0;
|
int nread = 0;
|
||||||
while (read < 3) {
|
while (nread < 3) {
|
||||||
read = is.read(buf);
|
int read = bis.read(buf);
|
||||||
|
|
||||||
|
if (read == -1) throw new EOFException("Locale file is truncated or empty!");
|
||||||
|
nread += read;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the BOM is 0xEF,0xBB,0xBF
|
// the BOM is 0xEF,0xBB,0xBF
|
||||||
isUtf8 = buf[0] == (byte) 0xEF && buf[1] == (byte) 0xBB && buf[2] == (byte) 0xBF;
|
isUtf8 = buf[0] == (byte) 0xEF && buf[1] == (byte) 0xBB && buf[2] == (byte) 0xBF;
|
||||||
}
|
}
|
||||||
is.reset();
|
bis.reset();
|
||||||
|
|
||||||
if (isUtf8) {
|
if (isUtf8) {
|
||||||
log.info("Found UTF-8 locale file " + resourceName);
|
log.info("Found UTF-8 locale file " + resourceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Charset charset = isUtf8 ? StandardCharsets.UTF_8 : StandardCharsets.ISO_8859_1;
|
Charset charset = isUtf8 ? StandardCharsets.UTF_8 : StandardCharsets.ISO_8859_1;
|
||||||
Reader reader = new InputStreamReader(is, charset);
|
Reader reader = new InputStreamReader(bis, charset);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PropertyResourceBundle bundle = new PropertyResourceBundle(reader);
|
PropertyResourceBundle bundle = new PropertyResourceBundle(reader);
|
||||||
|
Loading…
Reference in New Issue
Block a user