|
|
|
@ -15,8 +15,6 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.springframework.web.socket; |
|
|
|
package org.springframework.web.socket; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
|
|
|
|
import java.nio.ByteBuffer; |
|
|
|
import java.nio.ByteBuffer; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -34,11 +32,9 @@ public final class BinaryMessage extends WebSocketMessage<ByteBuffer> { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new {@link BinaryMessage} instance. |
|
|
|
* Create a new {@link BinaryMessage} instance. |
|
|
|
* @param payload a non-null payload |
|
|
|
* @param payload a non-null payload |
|
|
|
* @param isLast if the message is the last of a series of partial messages |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public BinaryMessage(ByteBuffer payload) { |
|
|
|
public BinaryMessage(ByteBuffer payload) { |
|
|
|
super(payload); |
|
|
|
this(payload, true); |
|
|
|
this.bytes = null; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -46,8 +42,26 @@ public final class BinaryMessage extends WebSocketMessage<ByteBuffer> { |
|
|
|
* @param payload a non-null payload |
|
|
|
* @param payload a non-null payload |
|
|
|
* @param isLast if the message is the last of a series of partial messages |
|
|
|
* @param isLast if the message is the last of a series of partial messages |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
public BinaryMessage(ByteBuffer payload, boolean isLast) { |
|
|
|
|
|
|
|
super(payload, isLast); |
|
|
|
|
|
|
|
this.bytes = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Create a new {@link BinaryMessage} instance. |
|
|
|
|
|
|
|
* @param payload a non-null payload |
|
|
|
|
|
|
|
*/ |
|
|
|
public BinaryMessage(byte[] payload) { |
|
|
|
public BinaryMessage(byte[] payload) { |
|
|
|
this(payload, 0, (payload == null ? 0 : payload.length)); |
|
|
|
this(payload, 0, (payload == null ? 0 : payload.length), true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Create a new {@link BinaryMessage} instance. |
|
|
|
|
|
|
|
* @param payload a non-null payload |
|
|
|
|
|
|
|
* @param isLast if the message is the last of a series of partial messages |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public BinaryMessage(byte[] payload, boolean isLast) { |
|
|
|
|
|
|
|
this(payload, 0, (payload == null ? 0 : payload.length), isLast); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -58,8 +72,8 @@ public final class BinaryMessage extends WebSocketMessage<ByteBuffer> { |
|
|
|
* @param len the length of the array considered for the payload |
|
|
|
* @param len the length of the array considered for the payload |
|
|
|
* @param isLast if the message is the last of a series of partial messages |
|
|
|
* @param isLast if the message is the last of a series of partial messages |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public BinaryMessage(byte[] payload, int offset, int len) { |
|
|
|
public BinaryMessage(byte[] payload, int offset, int len, boolean isLast) { |
|
|
|
super(payload != null ? ByteBuffer.wrap(payload, offset, len) : null); |
|
|
|
super(payload != null ? ByteBuffer.wrap(payload, offset, len) : null, isLast); |
|
|
|
if(offset == 0 && len == payload.length) { |
|
|
|
if(offset == 0 && len == payload.length) { |
|
|
|
this.bytes = payload; |
|
|
|
this.bytes = payload; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -82,18 +96,9 @@ public final class BinaryMessage extends WebSocketMessage<ByteBuffer> { |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Returns access to the message payload as an {@link InputStream}. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public InputStream getInputStream() { |
|
|
|
|
|
|
|
byte[] array = getByteArray(); |
|
|
|
|
|
|
|
return (array != null) ? new ByteArrayInputStream(array) : null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
protected int getPayloadSize() { |
|
|
|
int size = (getPayload() != null) ? getPayload().remaining() : 0; |
|
|
|
return (getPayload() != null) ? getPayload().remaining() : 0; |
|
|
|
return "WebSocket binary message size=" + size; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|