Skip to content

Commit

Permalink
Removed a ton of bulk from the raklib which should improve performanc…
Browse files Browse the repository at this point in the history
…e but it does still require some tweaking!
  • Loading branch information
RazvanDu committed Dec 2, 2015
1 parent 93601cf commit 29a68d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/dragonet/utilities/io/PEBinaryReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.UUID;

public class PEBinaryReader implements Closeable {
Expand Down Expand Up @@ -83,7 +84,7 @@ public String readString(int lenLen) throws IOException {
falloc(lenLen);
int length = (int) readNat(lenLen);
falloc(length);
return new String(read(length), "UTF-8");
return new String(read(length), StandardCharsets.UTF_8);
}

public byte readByte() throws IOException {
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/dragonet/utilities/io/PEBinaryWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
import java.net.Inet4Address;
import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.UUID;

public class PEBinaryWriter implements Flushable, Closeable {

protected OutputStream os;
protected boolean endianness;

Charset charset = Charset.forName("UTF-8");

public PEBinaryWriter(OutputStream os) {
this(os, PEBinaryUtils.BIG_ENDIAN);
}
Expand Down Expand Up @@ -76,8 +80,10 @@ public void writeAddress(InetAddress addr, short port) throws IOException {
}

public void writeString(String string, int lenLen) throws IOException {
write(string.length(), lenLen);
os.write(string.getBytes());
//write(string.getBytes(charset).length(), lenLen);
writeShort((short)string.getBytes(charset).length);
os.write(string.getBytes(charset));
// lenLen is useless??
}

public void writeByte(byte b) throws IOException {
Expand Down

0 comments on commit 29a68d8

Please sign in to comment.