Example usage for io.netty.buffer ByteBuf slice

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

Introduction

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

Prototype

public abstract ByteBuf slice(int index, int length);

Source Link

Document

Returns a slice of this buffer's sub-region.

Usage

From source file:com.ebay.jetstream.messaging.transport.netty.serializer.StreamMessageDecoder.java

License:MIT License

@Override
protected ByteBuf extractFrame(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length) {
    return buffer.slice(index, length);
}

From source file:com.eightkdata.mongowp.bson.netty.PooledNettyStringReader.java

License:Open Source License

@Override
public String readString(@Loose @ModifiesIndexes ByteBuf byteBuf, boolean likelyCacheable) {
    int stringLength = byteBuf.readInt();

    String str = stringPool.fromPool(likelyCacheable, byteBuf.slice(byteBuf.readerIndex(), stringLength - 1));

    byteBuf.skipBytes(stringLength);/*  ww  w .j  ava  2s  .c om*/

    return str;
}

From source file:com.eightkdata.mongowp.server.decoder.InsertMessageDecoder.java

License:Open Source License

@Override
@SuppressFBWarnings(value = {/*w w w  .  j  ava  2 s . c om*/
        "RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT" }, justification = "Findbugs thinks ByteBuf#readerIndex(...) has no"
                + "side effect")
public InsertMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage)
        throws InvalidNamespaceException, InvalidBsonException {
    try {
        MyBsonContext context = new MyBsonContext(buffer);

        int flags = buffer.readInt();
        String fullCollectionName = stringReader.readCString(buffer, true);

        ByteBuf docBuf = buffer.slice(buffer.readerIndex(), buffer.readableBytes());
        docBuf.retain();

        buffer.readerIndex(buffer.writerIndex());

        ByteBufIterableDocumentProvider documents = new ByteBufIterableDocumentProvider(docBuf, docReader);

        //TODO: improve the way database and cache are pooled
        return new InsertMessage(requestBaseMessage, context, getDatabase(fullCollectionName).intern(),
                getCollection(fullCollectionName).intern(),
                EnumInt32FlagsUtil.isActive(Flag.CONTINUE_ON_ERROR, flags), documents);
    } catch (NettyBsonReaderException ex) {
        throw new InvalidBsonException(ex);
    }
}

From source file:com.friz.audio.network.AudioSessionContext.java

License:Open Source License

/**
 * Processes the file requests.//from  w w  w.  j a v a2  s. c  o  m
 * @throws IOException The exception thrown if an i/o error occurs.
 */
public void processFileQueue() {
    FileRequestEvent request;
    synchronized (fileQueue) {
        request = fileQueue.pop();
        if (fileQueue.isEmpty()) {
            idle = true;
        } else {
            service.addAudioContext(this);
            idle = false;
        }
    }
    if (request != null) {
        int type = request.getType();
        int file = request.getFile();
        int crc = request.getCrc();
        int version = request.getVersion();
        HttpVersion http = request.getHttp();

        ByteBuf buf = Unpooled.buffer();
        if (type == 255 && file == 255) {
            buf = Unpooled.wrappedBuffer(server.getCache().getChecksum());
        } else {
            if (server.getCache().getReferenceTable(type).getEntry(file).getCrc() != crc
                    || server.getCache().getReferenceTable(type).getEntry(file).getVersion() != version) {
                writeResponse(http, buf);
                return;
            }

            try {
                buf = Unpooled.wrappedBuffer(server.getCache().getStore().read(type, file));
                if (type != 255)
                    buf = buf.slice(0, buf.readableBytes() - 2);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        writeResponse(http, buf);
    }
}

From source file:com.friz.update.network.UpdateSessionContext.java

License:Open Source License

/**
 * Processes the file requests.// w ww.j ava 2  s .  com
 * @throws IOException The exception thrown if an i/o error occurs.
 */
public void processFileQueue() {
    FileRequestEvent request;
    synchronized (fileQueue) {
        request = fileQueue.pop();
        if (fileQueue.isEmpty()) {
            idle = true;
        } else {
            service.addUpdateContext(this);
            idle = false;
        }
    }
    if (request != null) {
        int type = request.getType();
        int file = request.getFile();
        ByteBuf buf;
        try {
            if (type == 255 && file == 255) {
                buf = Unpooled.wrappedBuffer(server.getCache().getChecksum());
            } else {
                buf = Unpooled.wrappedBuffer(server.getCache().getStore().read(type, file));
                if (type != 255)
                    buf = buf.slice(0, buf.readableBytes() - 2);
            }
            channel.writeAndFlush(new FileResponseEvent(request.isPriority(), type, file, buf));
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:com.growcontrol.common.netty.JsonObjectDecoder.java

License:Apache License

/**
 * Override this method if you want to filter the json objects/arrays that get passed through the pipeline.
 *///from   w w  w .j a  v a  2s.co  m
protected ByteBuf extractObject(final ChannelHandlerContext ctx, final ByteBuf buffer, final int index,
        final int length) {
    return buffer.slice(index, length).retain();
}

From source file:com.hazelcast.simulator.protocol.core.SimulatorMessageCodec.java

License:Open Source License

public static SimulatorAddress getSourceAddress(ByteBuf in) {
    return decodeSimulatorAddress(in.slice(OFFSET_SRC_ADDRESS, ADDRESS_SIZE));
}

From source file:com.heliosapm.streams.collector.groovy.ByteBufReaderSource.java

License:Apache License

/**
 * {@inheritDoc}//from  w w w  . j  av a2s  . c o m
 * @see org.codehaus.groovy.control.io.ReaderSource#getLine(int, org.codehaus.groovy.control.Janitor)
 */
@Override
public String getLine(int lineNumber, Janitor janitor) {
    int start = 0;
    int eol = 0;
    final ByteBuf b = prejectedBuffer.duplicate().resetReaderIndex();
    for (int i = 0; i < lineNumber; i++) {
        eol = findEndOfLine(b);
        if (eol == -1)
            return null;
        start = eol + 1;
    }
    return b.slice(start, eol).toString(UTF8);
}

From source file:com.ibm.crail.datanode.netty.rpc.RdmaMsgTx.java

License:Apache License

public void referenceTxPayload(ByteBuf src, int position, int length) {
    this.txPayload = src.slice(position, length).retain();
}

From source file:com.jamierf.jsonrpc.util.JsonObjectDecoder.java

License:Apache License

/**
 * Override this method if you want to filter the json objects/arrays that get passed through the pipeline.
 *///from   w  w  w  .  j a va 2 s .c  o  m
@SuppressWarnings("UnusedParameters")
protected ByteBuf extractObject(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length) {
    return buffer.slice(index, length).retain();
}