Skip to content

Commit 9c8cab0

Browse files
author
bytekeeper
committed
Use builtin "endian" conversion.
1 parent 354607c commit 9c8cab0

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

src/main/java/bwapi/Client.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,33 +109,18 @@ public interface EventHandler {
109109
}
110110

111111
class LittleEndianPipe {
112-
RandomAccessFile pipe;
112+
private final RandomAccessFile pipe;
113113

114114
LittleEndianPipe(final String name, final String mode) throws FileNotFoundException {
115115
pipe = new RandomAccessFile(name, mode);
116116
}
117117

118-
final int readByte() throws IOException {
119-
return pipe.readByte();
120-
}
121-
122-
final void writeByte(final int b) throws IOException {
123-
pipe.writeByte(b);
124-
}
125-
126118
final int readInt() throws IOException {
127-
final int b1 = readByte();
128-
final int b2 = readByte();
129-
final int b3 = readByte();
130-
final int b4 = readByte();
131-
return (b4 << 24) | (b3 << 16) | (b2 << 8) | b1;
119+
return Integer.reverseBytes(pipe.readInt());
132120
}
133121

134122
final void writeInt(final int i) throws IOException {
135-
writeByte(i >> 24);
136-
writeByte((i >> 16) & 0xff);
137-
writeByte((i >> 8) & 0xff);
138-
writeByte(i & 0xff);
123+
pipe.writeInt(Integer.reverseBytes(i));
139124
}
140125
}
141126

0 commit comments

Comments
 (0)