Fixing up (byte[],int,int) vs (ByteBuffer) approaches on events

This commit is contained in:
Joakim Erdfelt 2012-06-28 12:49:59 -07:00
parent deef1a3ac1
commit 9b31c35f15
2 changed files with 28 additions and 1 deletions

View File

@ -113,4 +113,16 @@ public class EventMethod
{
return this.paramTypes;
}
public boolean isParameterPresent(Class<?> type)
{
for (Class<?> param : paramTypes)
{
if (param.equals(type))
{
return true;
}
}
return false;
}
}

View File

@ -1,5 +1,8 @@
package org.eclipse.jetty.websocket.api;
import java.nio.ByteBuffer;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.websocket.annotations.WebSocket;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.frames.BinaryFrame;
@ -97,7 +100,19 @@ public class WebSocketEventDriver implements Parser.Listener
if ((frame instanceof BinaryFrame) && (events.onBinary != null))
{
BinaryFrame bin = (BinaryFrame)frame;
events.onBinary.call(websocket,connection,bin.getPayload());
if (events.onBinary.isParameterPresent(ByteBuffer.class))
{
// Byte buffer approach
events.onBinary.call(websocket,connection,bin.getPayload());
}
else
{
// Byte array approach
byte buf[] = BufferUtil.toArray(bin.getPayload());
events.onBinary.call(websocket,connection,buf,0,buf.length);
}
return;
}