Example usage for io.netty.buffer ByteBuf getInt

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

Introduction

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

Prototype

public abstract int getInt(int index);

Source Link

Document

Gets a 32-bit integer at the specified absolute index in this buffer.

Usage

From source file:org.dcache.xrootd.protocol.messages.StatRequest.java

License:Open Source License

public StatRequest(ByteBuf buffer) {
    super(buffer, kXR_stat);
    options = buffer.getUnsignedByte(4);
    fhandle = buffer.getInt(16);
}

From source file:org.dcache.xrootd.protocol.messages.StatxRequest.java

License:Open Source License

public StatxRequest(ByteBuf buffer) {
    super(buffer, kXR_statx);

    int dlen = buffer.getInt(20);
    paths = buffer.toString(24, dlen, US_ASCII).split("\n");
    opaques = new String[paths.length];

    for (int i = 0; i < paths.length; i++) {
        String path = paths[i];/*  w w w.  ja va2  s .com*/
        int pos = path.indexOf('?');
        if (pos > -1) {
            paths[i] = path.substring(0, pos);
            opaques[i] = path.substring(pos + 1);
        }
    }
}

From source file:org.dcache.xrootd.protocol.messages.SyncRequest.java

License:Open Source License

public SyncRequest(ByteBuf buffer) {
    super(buffer, kXR_sync);
    fhandle = buffer.getInt(4);
}

From source file:org.dcache.xrootd.protocol.messages.WriteRequest.java

License:Open Source License

public WriteRequest(ByteBuf buffer) {
    super(buffer, kXR_write);

    fhandle = buffer.getInt(4);
    offset = buffer.getLong(8);//from   w ww  . j a  v a  2  s.c o m
    dlen = buffer.getInt(20);
    data = buffer.alloc().ioBuffer(dlen); // Most likely this will be written to disk
    buffer.getBytes(24, data);
}

From source file:org.dcache.xrootd.security.UnsignedIntBucket.java

License:Open Source License

public static UnsignedIntBucket deserialize(BucketType type, ByteBuf buffer) {

    return new UnsignedIntBucket(type, buffer.getInt(0));
}

From source file:org.dcache.xrootd.tpc.core.XrootdClientDecoder.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
    ChannelId id = ctx.channel().id();/* w ww  . ja v  a  2s.  co  m*/
    int readable = in.readableBytes();

    if (readable < SERVER_RESPONSE_LEN) {
        return;
    }

    int pos = in.readerIndex();
    int headerFrameLength = in.getInt(pos + 4);

    if (headerFrameLength < 0) {
        LOGGER.error("Decoder {}, channel {}: received illegal " + "frame length in " + "xrootd header: {}."
                + " Closing channel.", sourceUrn, id, headerFrameLength);
        ctx.channel().close();
        return;
    }

    int length = SERVER_RESPONSE_LEN + headerFrameLength;

    if (readable < length) {
        return;
    }

    ByteBuf frame = in.readSlice(length);
    int requestId = client.getExpectedResponse();

    try {
        switch (frame.getUnsignedShort(2)) {
        case kXR_error:
            LOGGER.trace("Decoder {}, channel {}: adding error response.", sourceUrn, id);
            out.add(new InboundErrorResponse(frame));
            return;
        case kXR_wait:
            LOGGER.trace("Decoder {}, channel {}: adding wait response.", sourceUrn, id);
            out.add(new InboundWaitResponse(frame, requestId));
            return;
        case kXR_waitresp:
            LOGGER.trace("Decoder {}, channel {}: adding waitresp response.", sourceUrn, id);
            out.add(new InboundWaitRespResponse(frame, requestId));
            return;
        case kXR_redirect:
            LOGGER.trace("Decoder {}, channel {}: adding redirect response.", sourceUrn, id);
            out.add(new InboundRedirectResponse(frame, requestId));
            return;
        case kXR_attn:
            LOGGER.trace("Decoder {}, channel {}: adding attn response.", sourceUrn, id);
            out.add(new InboundAttnResponse(frame, requestId));
            return;
        }

        switch (requestId) {
        case kXR_handshake:
            LOGGER.trace("Decoder {}, channel {}: adding handshake response.", sourceUrn, id);
            out.add(new InboundHandshakeResponse(frame));
            break;
        case kXR_protocol:
            LOGGER.trace("Decoder {}, channel {}: adding protocol response.", sourceUrn, id);
            out.add(new InboundProtocolResponse(frame));
            break;
        case kXR_login:
            LOGGER.trace("Decoder {}, channel {}: adding login response.", sourceUrn, id);
            out.add(new InboundLoginResponse(frame));
            break;
        case kXR_auth:
            LOGGER.trace("Decoder {}, channel {}: adding authentication response.", sourceUrn, id);
            out.add(new InboundAuthenticationResponse(frame));
            break;
        case kXR_open:
            LOGGER.trace("Decoder {}, channel {}: adding open response.", sourceUrn, id);
            out.add(new InboundOpenReadOnlyResponse(frame));
            break;
        case kXR_read:
            LOGGER.trace("Decoder {}, channel {}: adding read response.", sourceUrn, id);
            out.add(new InboundReadResponse(frame));
            break;
        case kXR_query:
            LOGGER.trace("Decoder {}, channel {}: adding query response.", sourceUrn, id);
            out.add(new InboundChecksumResponse(frame));
            break;
        case kXR_close:
            LOGGER.trace("Decoder {}, channel {}: adding close response.", sourceUrn, id);
            out.add(new InboundCloseResponse(frame));
            break;
        case kXR_endsess:
            LOGGER.trace("Decoder {}, channel {}: adding endsess response.", sourceUrn, id);
            out.add(new InboundEndSessionResponse(frame));
            break;
        default:
            LOGGER.trace("Decoder {}, channel {}, received incorrect " + "response of request type {}.",
                    sourceUrn, id, requestId);
            throw new XrootdException(kXR_error, "received incorrect response type.");
        }
    } catch (ParseException | XrootdException e) {
        LOGGER.error("Decoder {}, channel {}: error for request type {}: {}. " + "Closing channel.", requestId,
                id, e.getMessage());
        client.setError(e);
        try {
            client.shutDown(ctx);
        } catch (InterruptedException e1) {
            LOGGER.warn("client shutdown interrupted.");
        }
    }
}

From source file:org.dcache.xrootd.tpc.protocol.messages.AbstractInboundWaitResponse.java

License:Open Source License

public AbstractInboundWaitResponse(ByteBuf buffer, int requestId) {
    super(buffer);
    nextRequest = requestId;// www  .j  a  v a 2 s .  com
    maxWaitInSeconds = buffer.getInt(8);
}

From source file:org.dcache.xrootd.tpc.protocol.messages.InboundAttnResponse.java

License:Open Source License

public InboundAttnResponse(ByteBuf buffer, int requestId) {
    super(buffer);
    nextRequest = requestId;/*  w  w  w  .j a  va2  s.co m*/
    int plen = buffer.getInt(4);
    actnum = buffer.getInt(8);

    if (plen > 4) {
        parseParameters(buffer, plen - 4);
    }
}

From source file:org.dcache.xrootd.tpc.protocol.messages.InboundAttnResponse.java

License:Open Source License

private void parseParameters(ByteBuf buffer, int len) {
    switch (actnum) {
    case kXR_asyncab:
    case kXR_asyncms:
        message = buffer.toString(12, len, US_ASCII);
        break;//  w  w  w .j  av a  2s  .c  o  m
    case kXR_asyncdi:
        wsec = buffer.getInt(12);
        msec = buffer.getInt(16);
        break;
    case kXR_asyncrd:
        port = buffer.getInt(12);
        redirectData = buffer.toString(16, len - 4, US_ASCII);
        break;
    case kXR_asynresp:
        rStreamId = buffer.getUnsignedShort(16);
        rStat = buffer.getUnsignedShort(18);
        int dlen = buffer.getInt(20);
        if (dlen > 0) {
            rData = new byte[dlen];
            buffer.getBytes(24, rData);
        }
        break;
    case kXR_asyncwt:
        wsec = buffer.getInt(12);
        break;
    default:
        break;
    }
}

From source file:org.dcache.xrootd.tpc.protocol.messages.InboundChecksumResponse.java

License:Open Source License

public InboundChecksumResponse(ByteBuf buffer) throws ParseException {
    super(buffer);
    int len = buffer.getInt(4);
    if (len > 0) {
        parse(buffer.toString(8, len, StandardCharsets.US_ASCII));
    }/*from ww  w  .j a  va  2s. c o m*/
}