Java Code Examples for io.netty.buffer.ByteBuf#equals()

The following examples show how to use io.netty.buffer.ByteBuf#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebSocketClientHandshaker00.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Process server response:
 * </p>
 *
 * <pre>
 * HTTP/1.1 101 WebSocket Protocol Handshake
 * Upgrade: WebSocket
 * Connection: Upgrade
 * Sec-WebSocket-Origin: http://example.com
 * Sec-WebSocket-Location: ws://example.com/demo
 * Sec-WebSocket-Protocol: sample
 *
 * 8jKS'y:G*Co,Wxa-
 * </pre>
 *
 * @param response
 *            HTTP response returned from the server for the request sent by beginOpeningHandshake00().
 * @throws WebSocketHandshakeException
 */
@Override
protected void verify(FullHttpResponse response) {
    if (!response.status().equals(HttpResponseStatus.SWITCHING_PROTOCOLS)) {
        throw new WebSocketHandshakeException("Invalid handshake response getStatus: " + response.status());
    }

    HttpHeaders headers = response.headers();

    CharSequence upgrade = headers.get(HttpHeaderNames.UPGRADE);
    if (!WEBSOCKET.contentEqualsIgnoreCase(upgrade)) {
        throw new WebSocketHandshakeException("Invalid handshake response upgrade: "
                + upgrade);
    }

    if (!headers.containsValue(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE, true)) {
        throw new WebSocketHandshakeException("Invalid handshake response connection: "
                + headers.get(HttpHeaderNames.CONNECTION));
    }

    ByteBuf challenge = response.content();
    if (!challenge.equals(expectedChallengeResponseBytes)) {
        throw new WebSocketHandshakeException("Invalid challenge");
    }
}
 
Example 2
Source File: FlashPolicyHandler.java    From spring-boot-netty with MIT License 6 votes vote down vote up
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
    if (msg instanceof ByteBuf) {
        final ByteBuf message = (ByteBuf) msg;
        final int readableBytes = requestBuffer.readableBytes();
        final ByteBuf data = message.slice(0, readableBytes);

        if (data.equals(requestBuffer)) {
            message.release();
            final ChannelFuture f = ctx.writeAndFlush(copiedBuffer(responseBuffer));
            f.addListener(ChannelFutureListener.CLOSE);
            return;
        }

        ctx.pipeline().remove(this);
    }

    ctx.fireChannelRead(msg);
}
 
Example 3
Source File: HealthCheckHandler.java    From nomulus with Apache License 2.0 5 votes vote down vote up
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
  ByteBuf buf = (ByteBuf) msg;
  if (buf.equals(checkRequest)) {
    ChannelFuture unusedFuture = ctx.writeAndFlush(checkResponse);
  }
  buf.release();
}
 
Example 4
Source File: WebSocketClientHandshaker00.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Process server response:
 * </p>
 *
 * <pre>
 * HTTP/1.1 101 WebSocket Protocol Handshake
 * Upgrade: WebSocket
 * Connection: Upgrade
 * Sec-WebSocket-Origin: http://example.com
 * Sec-WebSocket-Location: ws://example.com/demo
 * Sec-WebSocket-Protocol: sample
 *
 * 8jKS'y:G*Co,Wxa-
 * </pre>
 *
 * @param response
 *            HTTP response returned from the server for the request sent by beginOpeningHandshake00().
 * @throws WebSocketHandshakeException
 */
@Override
protected void verify(FullHttpResponse response) {
    final HttpResponseStatus status = new HttpResponseStatus(101, "WebSocket Protocol Handshake");

    if (!response.getStatus().equals(status)) {
        throw new WebSocketHandshakeException("Invalid handshake response getStatus: " + response.getStatus());
    }

    HttpHeaders headers = response.headers();

    String upgrade = headers.get(Names.UPGRADE);
    if (!Values.WEBSOCKET.equalsIgnoreCase(upgrade)) {
        throw new WebSocketHandshakeException("Invalid handshake response upgrade: "
                + upgrade);
    }

    String connection = headers.get(Names.CONNECTION);
    if (!Values.UPGRADE.equalsIgnoreCase(connection)) {
        throw new WebSocketHandshakeException("Invalid handshake response connection: "
                + connection);
    }

    ByteBuf challenge = response.content();
    if (!challenge.equals(expectedChallengeResponseBytes)) {
        throw new WebSocketHandshakeException("Invalid challenge");
    }
}
 
Example 5
Source File: RedissonTransactionalBucket.java    From redisson with Apache License 2.0 5 votes vote down vote up
private boolean isEquals(Object value, Object oldValue) {
    ByteBuf valueBuf = encode(value);
    ByteBuf oldValueBuf = encode(oldValue);
    
    try {
        return valueBuf.equals(oldValueBuf);
    } finally {
        valueBuf.readableBytes();
        oldValueBuf.readableBytes();
    }
}
 
Example 6
Source File: BaseTransactionalSet.java    From redisson with Apache License 2.0 5 votes vote down vote up
private boolean isEqual(Object value, Object oldValue) {
    ByteBuf valueBuf = ((RedissonObject) set).encode(value);
    ByteBuf oldValueBuf = ((RedissonObject) set).encode(oldValue);
    
    try {
        return valueBuf.equals(oldValueBuf);
    } finally {
        valueBuf.readableBytes();
        oldValueBuf.readableBytes();
    }
}
 
Example 7
Source File: BaseTransactionalMap.java    From redisson with Apache License 2.0 5 votes vote down vote up
private boolean isEqual(Object value, Object oldValue) {
    ByteBuf valueBuf = ((RedissonObject) map).encodeMapValue(value);
    ByteBuf oldValueBuf = ((RedissonObject) map).encodeMapValue(oldValue);
    
    try {
        return valueBuf.equals(oldValueBuf);
    } finally {
        valueBuf.readableBytes();
        oldValueBuf.readableBytes();
    }
}
 
Example 8
Source File: FlashPolicyHandler.java    From socketio with Apache License 2.0 5 votes vote down vote up
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
  if (msg instanceof ByteBuf) {
    ByteBuf message = (ByteBuf) msg;
    if (message.readableBytes() >= policyRequestBuffer.readableBytes()) {
      ByteBuf data = message.slice(0, policyRequestBuffer.readableBytes());
      if (data.equals(policyRequestBuffer)) {
        // Remove SSL handler from pipeline otherwise on channel close SSL handler
        // will fail all pending writes instead of flushing them and as a result
        // client won't get flash policy file.
        if (ctx.pipeline().get(SocketIOChannelInitializer.SSL_HANDLER) != null) {
          ctx.pipeline().remove(SocketIOChannelInitializer.SSL_HANDLER);
        }

        // Send flash policy file and close connection
        ByteBuf response = PipelineUtils.copiedBuffer(ctx.alloc(), policyResponse);
        ChannelFuture f = ctx.writeAndFlush(response);
        f.addListener(ChannelFutureListener.CLOSE);
        if (log.isDebugEnabled())
          log.debug("Sent flash policy file to channel: {}", ctx.channel());
        message.release();
        return;
      }
    }
    ctx.pipeline().remove(this);
  }
  ctx.fireChannelRead(msg);
}
 
Example 9
Source File: TextFieldSerializerDeserializer.java    From tajo with Apache License 2.0 4 votes vote down vote up
private static boolean isNull(ByteBuf val, ByteBuf nullBytes) {
  return !val.isReadable() || nullBytes.equals(val);
}
 
Example 10
Source File: TextFieldSerializerDeserializer.java    From tajo with Apache License 2.0 4 votes vote down vote up
private static boolean isNull(ByteBuf val, ByteBuf nullBytes) {
  return !val.isReadable() || nullBytes.equals(val);
}
 
Example 11
Source File: TextFieldSerializerDeserializer.java    From tajo with Apache License 2.0 4 votes vote down vote up
private static boolean isNullText(ByteBuf val, ByteBuf nullBytes) {
  return val.readableBytes() > 0 && nullBytes.equals(val);
}