diff --git a/core/src/io/anuke/mindustry/io/TypeIO.java b/core/src/io/anuke/mindustry/io/TypeIO.java index 6061472054..a8829cb90a 100644 --- a/core/src/io/anuke/mindustry/io/TypeIO.java +++ b/core/src/io/anuke/mindustry/io/TypeIO.java @@ -27,7 +27,6 @@ import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import static io.anuke.mindustry.Vars.*; @@ -332,12 +331,7 @@ public class TypeIO{ @WriteClass(String.class) public static void writeString(ByteBuffer buffer, String string){ if(string != null){ - Charset charset = Charset.defaultCharset(); - byte[] nameBytes = charset.name().getBytes(StandardCharsets.UTF_8); - buffer.put((byte)nameBytes.length); - buffer.put(nameBytes); - - byte[] bytes = string.getBytes(charset); + byte[] bytes = string.getBytes(StandardCharsets.UTF_8); buffer.putShort((short) bytes.length); buffer.put(bytes); }else{ @@ -349,14 +343,10 @@ public class TypeIO{ public static String readString(ByteBuffer buffer){ byte length = buffer.get(); if(length != -1){ - byte[] cbytes = new byte[length]; - buffer.get(cbytes); - Charset charset = Charset.forName(new String(cbytes, StandardCharsets.UTF_8)); - short slength = buffer.getShort(); byte[] bytes = new byte[slength]; buffer.get(bytes); - return new String(bytes, charset); + return new String(bytes, StandardCharsets.UTF_8); }else{ return null; } @@ -378,12 +368,7 @@ public class TypeIO{ public static void writeStringData(DataOutput buffer, String string) throws IOException{ if(string != null){ - Charset charset = Charset.defaultCharset(); - byte[] nameBytes = charset.name().getBytes(StandardCharsets.UTF_8); - buffer.writeByte((byte)nameBytes.length); - buffer.write(nameBytes); - - byte[] bytes = string.getBytes(charset); + byte[] bytes = string.getBytes(StandardCharsets.UTF_8); buffer.writeShort((short) bytes.length); buffer.write(bytes); }else{ @@ -394,14 +379,10 @@ public class TypeIO{ public static String readStringData(DataInput buffer) throws IOException{ byte length = buffer.readByte(); if(length != -1){ - byte[] cbytes = new byte[length]; - buffer.readFully(cbytes); - Charset charset = Charset.forName(new String(cbytes, StandardCharsets.UTF_8)); - short slength = buffer.readShort(); byte[] bytes = new byte[slength]; buffer.readFully(bytes); - return new String(bytes, charset); + return new String(bytes, StandardCharsets.UTF_8); }else{ return null; }