specify utf8 encoding

this should fix the following known bugs:
 - putting a U+2019 in the config causes it to become corrupted and
   ~double in size every launch
 - scripts become assembled incorrectly and the nbsp after your name in
   the chatbox becomes incorrect
 - the feed panel doesn't show emoji
This commit is contained in:
Max Weber
2020-08-24 09:41:54 -06:00
committed by Adam
parent ca2416a838
commit 431e09588b
32 changed files with 117 additions and 70 deletions

View File

@@ -33,6 +33,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Comparator;
@@ -103,7 +104,7 @@ public class FlatStorage implements Storage
for (Index idx : store.getIndexes())
{
String file = idx.getId() + EXTENSION;
try (BufferedReader br = new BufferedReader(new InputStreamReader(openReader(file))))
try (BufferedReader br = new BufferedReader(new InputStreamReader(openReader(file), StandardCharsets.UTF_8)))
{
int lineNo = 0;
Archive archive = null;
@@ -213,7 +214,7 @@ public class FlatStorage implements Storage
for (Index idx : store.getIndexes())
{
String file = idx.getId() + EXTENSION;
try (PrintStream br = new PrintStream(openWriter(file)))
try (PrintStream br = new PrintStream(openWriter(file), false, StandardCharsets.UTF_8.name()))
{
br.printf("protocol=%d\n", idx.getProtocol());
br.printf("revision=%d\n", idx.getRevision());

View File

@@ -26,8 +26,8 @@ package net.runelite.cache.io;
import com.google.common.base.Preconditions;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
public final class OutputStream extends java.io.OutputStream
{
@@ -181,16 +181,7 @@ public final class OutputStream extends java.io.OutputStream
public void writeString(String str)
{
byte[] b;
try
{
b = str.getBytes("ISO-8859-1");
}
catch (UnsupportedEncodingException ex)
{
throw new RuntimeException(ex);
}
writeBytes(b);
writeBytes(str.getBytes(StandardCharsets.ISO_8859_1));
writeByte(0);
}

View File

@@ -26,6 +26,8 @@ package net.runelite.cache.script.assembler;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import net.runelite.cache.definitions.ScriptDefinition;
import net.runelite.cache.script.Instructions;
import net.runelite.cache.script.assembler.rs2asmParser.ProgContext;
@@ -45,7 +47,7 @@ public class Assembler
public ScriptDefinition assemble(InputStream in) throws IOException
{
// Get our lexer
rs2asmLexer lexer = new rs2asmLexer(new ANTLRInputStream(in));
rs2asmLexer lexer = new rs2asmLexer(new ANTLRInputStream(new InputStreamReader(in, StandardCharsets.UTF_8)));
LexerErrorListener errorListener = new LexerErrorListener();
lexer.addErrorListener(errorListener);