cache: actually fix script assembly encoding
This commit is contained in:
@@ -26,9 +26,10 @@ package net.runelite.cache.io;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public final class OutputStream extends java.io.OutputStream
|
||||
{
|
||||
@@ -57,7 +58,7 @@ public final class OutputStream extends java.io.OutputStream
|
||||
int newCapacity = buffer.capacity() * 2;
|
||||
|
||||
ByteBuffer old = buffer;
|
||||
((Buffer) old).flip();
|
||||
old.flip();
|
||||
|
||||
buffer = ByteBuffer.allocate(newCapacity);
|
||||
|
||||
@@ -182,16 +183,17 @@ 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);
|
||||
Charset utf8charset = Charset.forName("UTF-8");
|
||||
Charset cp1252charset = Charset.forName("Cp1252");
|
||||
|
||||
ByteBuffer inputBuffer = ByteBuffer.wrap(str.getBytes());
|
||||
|
||||
CharBuffer data = utf8charset.decode(inputBuffer);
|
||||
|
||||
ByteBuffer outputBuffer = cp1252charset.encode(data);
|
||||
byte[] outputData = outputBuffer.array();
|
||||
|
||||
writeBytes(outputData);
|
||||
writeByte(0);
|
||||
}
|
||||
|
||||
@@ -209,4 +211,4 @@ public final class OutputStream extends java.io.OutputStream
|
||||
buffer.put((byte) b);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user