diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/Generator.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/Generator.java index 22dec2edad5..429a20754af 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/Generator.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/Generator.java @@ -284,7 +284,9 @@ public class Generator { byte[] mask = frame.getMask(); buffer.put(mask); - int maskInt = ByteBuffer.wrap(mask).getInt(); + int maskInt = 0; + for (byte maskByte : mask) + maskInt = (maskInt << 8) + (maskByte & 0xFF); // perform data masking here ByteBuffer payload = frame.getPayload(); diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/payload/DeMaskProcessor.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/payload/DeMaskProcessor.java index 9f01bd577c5..55f67559c77 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/payload/DeMaskProcessor.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/payload/DeMaskProcessor.java @@ -24,7 +24,8 @@ import org.eclipse.jetty.websocket.api.extensions.Frame; public class DeMaskProcessor implements PayloadProcessor { - private byte maskBytes[]; + private byte[] maskBytes; + private int maskInt; private int maskOffset; @Override @@ -35,14 +36,14 @@ public class DeMaskProcessor implements PayloadProcessor return; } - int maskInt = ByteBuffer.wrap(maskBytes).getInt(); + int maskInt = this.maskInt; int start = payload.position(); int end = payload.limit(); int offset = this.maskOffset; int remaining; while ((remaining = end - start) > 0) { - if (remaining >= 4 && (offset % 4) == 0) + if (remaining >= 4 && (offset & 3) == 0) { payload.putInt(start,payload.getInt(start) ^ maskInt); start += 4; @@ -61,6 +62,10 @@ public class DeMaskProcessor implements PayloadProcessor public void reset(byte mask[]) { this.maskBytes = mask; + int maskInt = 0; + for (byte maskByte : maskBytes) + maskInt = (maskInt << 8) + (maskByte & 0xFF); + this.maskInt = maskInt; this.maskOffset = 0; }