raphaelts3 / wyd2encdec

Shift amounts outside the valid range may produce unexpected results JAVA-E0399
Anti-pattern
Major
2 years ago2 years old
Shifting by 8 is equivalent to shifting by 0
11    private byte[] longBuffer = new byte[8];
12
13    public synchronized void putByte(byte val) throws IOException {
14        byteBuffer[0] = (byte) (val >>> 8);15        write(byteBuffer);
16    }
17
Shifting by 8 is equivalent to shifting by 0
28    public synchronized char readChar() throws IOException {
29        read(tmpBuffer, 0, 2);
30
31        return (char) ((tmpBuffer[0] & 0xFF) + (tmpBuffer[1] << 8));32    }
33
34    public synchronized short readShort() throws IOException {
Shifting by 8 is equivalent to shifting by 0
34    public synchronized short readShort() throws IOException {
35        read(tmpBuffer, 0, 2);
36
37        return (short) ((tmpBuffer[0] & 0xFF) + (tmpBuffer[1] << 8));38    }
39
40    public synchronized int readInt() throws IOException {
Shifting by 56 is equivalent to shifting by 0
53
54        return ((tmpBuffer[0] & 0xFFL)) + ((tmpBuffer[1] & 0xFFL) << 8) + ((tmpBuffer[2] & 0xFFL) << 16)
55                + ((tmpBuffer[3] & 0xFFL) << 24) + ((tmpBuffer[4] & 0xFFL) << 32) + ((tmpBuffer[5] & 0xFFL) << 40)
56                + ((tmpBuffer[6] & 0xFFL) << 48) + (((long) tmpBuffer[7]) << 56);57    }
58
59    public synchronized double readDouble(double val) throws IOException {
Shifting by 24 is equivalent to shifting by 0
41        read(tmpBuffer, 0, 4);
42
43        return ((tmpBuffer[0] & 0xFF)) + ((tmpBuffer[1] & 0xFF) << 8) + ((tmpBuffer[2] & 0xFF) << 16)
44                + ((tmpBuffer[3]) << 24);45    }
46
47    public synchronized float readFloat() throws IOException {