Don't rely on platform default encoding, which can lead to inconsistent results on different platforms

This commit is contained in:
Daniel Gredler
2018-08-28 15:27:38 -04:00
parent cd76ed6be9
commit 868144a630
2 changed files with 6 additions and 4 deletions
@@ -42,6 +42,7 @@ import com.threerings.getdown.util.*;
import com.threerings.getdown.util.Base64; import com.threerings.getdown.util.Base64;
import static com.threerings.getdown.Log.log; import static com.threerings.getdown.Log.log;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* Parses and provide access to the information contained in the <code>getdown.txt</code> * Parses and provide access to the information contained in the <code>getdown.txt</code>
@@ -1242,7 +1243,7 @@ public class Application
if (_latest != null) { if (_latest != null) {
try (InputStream in = ConnectionUtil.open(_latest, 0, 0).getInputStream(); try (InputStream in = ConnectionUtil.open(_latest, 0, 0).getInputStream();
InputStreamReader reader = new InputStreamReader(in); InputStreamReader reader = new InputStreamReader(in, UTF_8);
BufferedReader bin = new BufferedReader(reader)) { BufferedReader bin = new BufferedReader(reader)) {
for (String[] pair : Config.parsePairs(bin, Config.createOpts(false))) { for (String[] pair : Config.parsePairs(bin, Config.createOpts(false))) {
if (pair[0].equals("version")) { if (pair[0].equals("version")) {
@@ -9,7 +9,6 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.PrintStream; import java.io.PrintStream;
@@ -20,6 +19,7 @@ import com.samskivert.util.StringUtil;
import com.threerings.getdown.data.SysProps; import com.threerings.getdown.data.SysProps;
import static com.threerings.getdown.Log.log; import static com.threerings.getdown.Log.log;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* Version related utilities. * Version related utilities.
@@ -33,7 +33,7 @@ public class VersionUtil
{ {
long fileVersion = -1; long fileVersion = -1;
try (BufferedReader bin = try (BufferedReader bin =
new BufferedReader(new InputStreamReader(new FileInputStream(vfile)))) { new BufferedReader(new InputStreamReader(new FileInputStream(vfile), UTF_8))) {
String vstr = bin.readLine(); String vstr = bin.readLine();
if (!StringUtil.isBlank(vstr)) { if (!StringUtil.isBlank(vstr)) {
fileVersion = Long.parseLong(vstr); fileVersion = Long.parseLong(vstr);
@@ -81,7 +81,8 @@ public class VersionUtil
*/ */
public static long readReleaseVersion (File relfile, String versRegex) public static long readReleaseVersion (File relfile, String versRegex)
{ {
try (BufferedReader in = new BufferedReader(new FileReader(relfile))) { try (BufferedReader in =
new BufferedReader(new InputStreamReader(new FileInputStream(relfile), UTF_8))) {
String line = null, relvers = null; String line = null, relvers = null;
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
if (line.startsWith("JAVA_VERSION=")) { if (line.startsWith("JAVA_VERSION=")) {