Example usage for io.netty.buffer ByteBuf equals

List of usage examples for io.netty.buffer ByteBuf equals

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf equals.

Prototype

@Override
public abstract boolean equals(Object obj);

Source Link

Document

Determines if the content of the specified buffer is identical to the content of this array.

Usage

From source file:com.corundumstudio.socketio.transport.FlashPolicyHandler.java

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof ByteBuf) {
        ByteBuf message = (ByteBuf) msg;
        ByteBuf data = message.slice(0, requestBuffer.readableBytes());
        if (data.equals(requestBuffer)) {
            message.release();//from w ww  .  java2s.  c  o m
            ChannelFuture f = ctx.writeAndFlush(Unpooled.copiedBuffer(responseBuffer));
            f.addListener(ChannelFutureListener.CLOSE);
            return;
        }
        ctx.pipeline().remove(this);
    }
    ctx.fireChannelRead(msg);
}

From source file:com.spotify.netty4.handler.codec.zmtp.VerifyingDecoder.java

License:Apache License

@Override
public void content(final ChannelHandlerContext ctx, final ByteBuf data, final List<Object> out) {
    if (data.readableBytes() < frameSize) {
        return;/*from  w w  w  . ja va2 s.  c  o m*/
    }
    final ByteBuf expectedFrame = expected.message.frame(readIndex);
    final ByteBuf frame = data.readBytes((int) frameSize);
    if (!expectedFrame.equals(frame)) {
        throw new IllegalStateException("read frame did not match expected frame: " + "readIndex=" + readIndex
                + ", " + "expected frame=" + expectedFrame + "read frame=" + frame);
    }
    readIndex++;
}

From source file:de.cubeisland.engine.core.webapi.HttpRequestHandler.java

License:Open Source License

private void handleHttpRequest(ChannelHandlerContext context, FullHttpRequest message, String path,
        Parameters params, User authUser) {
    ApiHandler handler = this.server.getApiHandler(path);
    if (handler == null) {
        this.error(context, ROUTE_NOT_FOUND);
        return;//  ww  w .j a  v a  2 s .c o  m
    }

    JsonNode data = null;
    ByteBuf requestContent = message.content();
    if (!requestContent.equals(EMPTY_BUFFER)) {
        try {
            byte[] bytes = new byte[requestContent.readableBytes()];
            requestContent.readBytes(bytes);
            data = this.objectMapper.readTree(bytes);
        } catch (Exception ex) {
            this.log.debug(ex, "Failed to parse the request body!");
            this.error(context, MALFORMED_DATA);
            return;
        }
    }
    final RequestMethod method = RequestMethod.getByName(message.getMethod().name());

    ApiRequest apiRequest = new ApiRequest((InetSocketAddress) context.channel().remoteAddress(), method,
            params, message.headers(), data, authUser);
    try {
        this.success(context, handler.execute(apiRequest));
    } catch (ApiRequestException e) {
        this.error(context, REQUEST_EXCEPTION, e);
    } catch (Throwable t) {
        this.error(context, UNKNOWN_ERROR);
    }
}

From source file:io.scalecube.socketio.pipeline.FlashPolicyHandler.java

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    // ?//from  w  w w  . j  a va  2  s . co  m
    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);
}

From source file:io.tetrapod.core.flashpolicy.FlashPolicyServerDecoder.java

License:Apache License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    ByteBuf data = in.readBytes(REQUEST.readableBytes());

    if (data.equals(REQUEST)) {
        out.add(Boolean.TRUE);/* w  w  w.j  ava  2s  . c  o m*/
    } else {
        ctx.close();
    }
    data.release();
}

From source file:jj.repl.telnet.TelnetConnectionHandler.java

License:Apache License

@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
    dumpBuffer("received", msg);
    // sanity check
    assert state != null : "got into read without expecting anything next";
    switch (state) {

    case AwaitingClientNegotiation:
        // cancel the awaiting timer
        awaitingInitialNegotiation.cancelKey().cancel();
        // try to read it
        ctx.writeAndFlush(makeMessage(IAC, DO, TRANSMIT_BINARY));
        //ctx.writeAndFlush(makeMessage(IAC, SB, TERMINAL_TYPE, TerminalType.SEND, IAC, SE));
        state = State.AwaitingWillTransmitBinary;
        break;//from   w ww .ja v  a 2 s  .  c o m

    case AwaitingWillTransmitBinary:
        if (msg.equals(makeMessage(IAC, WILL, TRANSMIT_BINARY))) {
            ctx.writeAndFlush(makeMessage(IAC, WILL, CHARSET));
            state = State.AwaitingWillNegotiateCharset;
        } else {
            state = State.Done;
        }
        break;

    case AwaitingWillNegotiateCharset:

        dumpBuffer("charset!", msg);
        state = State.Done;
        break;

    default:
        ctx.fireChannelRead(msg);

    }
}

From source file:org.apache.tajo.plan.function.stream.TextFieldSerializerDeserializer.java

License:Apache License

private static boolean isNull(ByteBuf val, ByteBuf nullBytes) {
    return !val.isReadable() || nullBytes.equals(val);
}

From source file:org.apache.tajo.plan.function.stream.TextFieldSerializerDeserializer.java

License:Apache License

private static boolean isNullText(ByteBuf val, ByteBuf nullBytes) {
    return val.readableBytes() > 0 && nullBytes.equals(val);
}

From source file:org.atmosphere.nettosphere.extra.FlashPolicyServerDecoder.java

License:Apache License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) {

    ByteBuf data = buffer.readBytes(requestBuffer.readableBytes());
    if (data.equals(requestBuffer)) {
        return;//w w w.j av a2 s  .  c o  m
    }
    ctx.close();
}

From source file:org.ratpackframework.reload.internal.ReloadableFileBackedFactory.java

License:Apache License

private void refresh() throws IOException {
    lock.lock();//  ww  w . jav  a2s. c om
    try {
        long lastModifiedTime = file.lastModified();
        ByteBuf bytes = IoUtils.readFile(file);

        if (lastModifiedTime == lastModifiedHolder.get() && bytes.equals(contentHolder.get())) {
            return;
        }

        delegateHolder.set(delegate.produce(file, bytes));

        this.lastModifiedHolder.set(lastModifiedTime);
        this.contentHolder.set(bytes);
    } finally {
        lock.unlock();
    }
}