Examples of ByteBuf


Examples of io.netty.buffer.ByteBuf

        buf.writeBytes(str.getBytes("utf8"));
        write(buf);
    }

    public void writeAsciiString(String str) throws IOException {
        ByteBuf buf = this.channelFuture.channel().alloc().buffer();
        buf.writeBytes(str.getBytes("us-ascii"));
        write(buf);
    }
View Full Code Here

Examples of io.netty.buffer.ByteBuf

                    }
                    buffer.position( position );
                }
                int fd = -1;
                buffer.limit(numRead);
                ByteBuf nettyBuf = alloc().buffer(numRead);
                nettyBuf.writeBytes(buffer);
                if (control.getType() == 0x01 && control.getLevel() == SocketLevel.SOL_SOCKET.intValue()) {
                    fd = control.getData().order(ByteOrder.nativeOrder()).getInt();
                }
                IPCRecord record = new IPCRecord(nettyBuf, fd);
                writeInbound(record);
View Full Code Here

Examples of io.netty.buffer.ByteBuf

        }
    }

    protected void doWriteOutbound(Object outbound) {
        int fd = -1;
        ByteBuf buf = null;

        if (outbound instanceof IPCRecord) {
            buf = ((IPCRecord) outbound).getBuffer();
            fd = ((IPCRecord) outbound).getFd();
        } else if (outbound instanceof ByteBuf) {
            buf = (ByteBuf) outbound;
        } else {
            return;
        }

        ByteBuffer nioBuf = ByteBuffer.allocateDirect(buf.readableBytes());
        buf.readBytes(nioBuf);
        nioBuf.flip();

        MsgHdr message = posix.allocateMsgHdr();
        message.setIov(new ByteBuffer[]{nioBuf});
View Full Code Here

Examples of io.netty.buffer.ByteBuf

                case BODY:
                    if (this.chunked) {
                        this.state = State.CHUNK_START;
                        continue LOOP;
                    }
                    ByteBuf body = readBody();
                    emit("body", CallbackResult.createSuccess(body));
                    if ( this.length == 0 ) {
                        finish();
                        break LOOP;
                    }
                    continue LOOP;
                case CHUNK_START:
                    if (!readChunkStart()) {
                        break LOOP;
                    }
                    if (this.length == 0) {
                        this.state = State.TRAILERS;
                    } else {
                        this.state = State.CHUNK_BODY;
                    }
                    continue LOOP;
                case CHUNK_BODY:
                    ByteBuf chunkBody = readBody();
                    emit("body", CallbackResult.createSuccess(chunkBody));
                    if (this.length == 0) {
                        this.state = State.CHUNK_END;
                    }
                    continue LOOP;
View Full Code Here

Examples of io.netty.buffer.ByteBuf

            return null;
        }

        int len = (cr + 2) - readerIndex();

        ByteBuf line = buf.readSlice(len);
        return line;
    }
View Full Code Here

Examples of io.netty.buffer.ByteBuf

        ByteBuf line = buf.readSlice(len);
        return line;
    }

    protected boolean readRequestLine() {
        ByteBuf line = readLine();
        if (line == null) {
            return false;
        }

        int space = line.indexOf(line.readerIndex(), line.readerIndex() + line.readableBytes(), (byte) ' ');
        if (space < 0) {
            setError(Error.INVALID_METHOD);
            return false;
        }

        int len = space - line.readerIndex();

        ByteBuf methodBuf = line.readSlice(len);

        String methodName = methodBuf.toString(UTF8);
        for (int i = 0; i < METHODS.length; ++i) {
            if (METHODS[i].equals(methodName)) {
                this.method = i;
                break;
            }
        }

        if (this.method == null) {
            setError(Error.INVALID_METHOD);
            return false;
        }

        if ( "CONNECT".equals( methodName ) ) {
            this.upgrade = true;
        }

        // skip the space
        line.readByte();

        space = line.indexOf(line.readerIndex(), line.readerIndex() + line.readableBytes(), (byte) ' ');

        ByteBuf urlBuf = null;
        ByteBuf versionBuf = null;
        if (space < 0) {
            // HTTP/1.0
            urlBuf = line.readSlice(line.readableBytes());
        } else {
            len = space - line.readerIndex();
View Full Code Here

Examples of io.netty.buffer.ByteBuf

        }
        return true;
    }

    protected boolean readStatusLine() {
        ByteBuf line = readLine();

        if (line == null) {
            return false;
        }

        int space = line.indexOf(line.readerIndex(), line.readerIndex() + line.readableBytes(), (byte) ' ');

        if (space < 0) {
            setError(Error.INVALID_VERSION);
            return false;
        }

        int len = space - line.readerIndex();

        ByteBuf versionBuf = line.readSlice(len);

        if (!readVersion(versionBuf)) {
            setError(Error.INVALID_VERSION);
            return false;
        }

        // skip space
        line.readByte();

        space = line.indexOf(line.readerIndex(), line.readerIndex() + line.readableBytes(), (byte) ' ');

        if (space < 0) {
            setError(Error.INVALID_STATUS);
            return false;
        }

        len = space - line.readerIndex();

        ByteBuf statusBuf = line.readSlice(len);

        int status = -1;

        try {
            status = Integer.parseInt(statusBuf.toString(UTF8));
        } catch (NumberFormatException e) {
            setError(Error.INVALID_STATUS);
            return false;
        }

        if (status > 999 || status < 100) {
            setError(Error.INVALID_STATUS);
            return false;
        }

        this.statusCode = status;

        // skip space
        line.readByte();

        ByteBuf messageBuf = line.readSlice(line.readableBytes());

        this.statusMessage = messageBuf.toString(UTF8).trim();

        return true;
    }
View Full Code Here

Examples of io.netty.buffer.ByteBuf

        return readHeaders(this.trailers, false);
    }

    protected int readHeaders(List<String> target, boolean analyze) {
        while (true) {
            ByteBuf line = readLine();
            if (line == null) {
                // try again next time
                return 1;
            }

            if (line.readableBytes() == 2) {
                // end-of-headers
                return 0;
            }

            if (!readHeader(line, target, analyze)) {
View Full Code Here

Examples of io.netty.buffer.ByteBuf

            }
            return false;
        }

        int len = colonLoc - line.readerIndex();
        ByteBuf keyBuf = line.readSlice(len);

        // skip colon
        line.readByte();

        ByteBuf valueBuf = line.readSlice(line.readableBytes());

        String key = keyBuf.toString(UTF8).trim();
        String value = valueBuf.toString(UTF8).trim();

        target.add(key);
        target.add(value);

        if (analyze) {
View Full Code Here

Examples of io.netty.buffer.ByteBuf

        return true;
    }

    protected boolean readChunkStart() {
        ByteBuf line = readLine();
        if (line == null) {
            return false;
        }

        try {
            int len = Integer.parseInt(line.toString(UTF8).trim(), 16);
            this.length = len;
        } catch (NumberFormatException e) {
            setError(Error.INVALID_CHUNK_SIZE);
            return false;
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.