Package org.vertx.java.core.buffer

Examples of org.vertx.java.core.buffer.Buffer


        JsonObject jsonObject;
        byte[] data;

        // Parse the byte[] message body
        try {
            Buffer body = message.body();
            if (body.length() == 0) {
                chunksStatsBean.incrementWriteErrorCount();
                sendError(message, "message body is empty");
                return;
            }

            // First four bytes indicate the json string length
            int len = body.getInt(0);

            // Decode json
            int from = 4;
            byte[] jsonBytes = body.getBytes(from, from + len);
            jsonObject = new JsonObject(decode(jsonBytes));

            // Remaining bytes are the chunk to be written
            from += len;
            data = body.getBytes(from, body.length());

        } catch (RuntimeException e) {
            chunksStatsBean.incrementWriteErrorCount();
            sendError(message, "error parsing buffer message.  see the documentation for the correct format", e);
            return;
View Full Code Here


        JsonObject jsonObject;
        byte[] data;

        // Parse the byte[] message body
        try {
            Buffer body = message.body();
            if (body.length() == 0) {
                sendError(message, "message body is empty");
                return;
            }

            // First four bytes indicate the json string length
            int len = body.getInt(0);

            // Decode json
            int from = 4;
            byte[] jsonBytes = body.getBytes(from, from + len);
            jsonObject = new JsonObject(decode(jsonBytes));

            // Remaining bytes are the chunk to be written
            from += len;
            data = body.getBytes(from, body.length());

        } catch (RuntimeException e) {
            sendError(message, "error parsing buffer message.  see the documentation for the correct format", e);
            return;
        }
View Full Code Here

            fileHandler.handle(fileInfo);
        }
    }

    public void handleData(byte[] data) {
        handleData(new Buffer(data));
    }
View Full Code Here

    }

    private <T> void innerWrite(final DefaultFileInfo fileInfo, final ReadStream<T> rs, final FutureCallback<FileInfo> callback) {

        final Value<Buffer> buffer = new Value<>(new Buffer());
        final Value<Integer> num = new Value<>(0);

        final List<Promise<Void>> promises = new ArrayList<>();

        // NOTE: There is no throttling on ReadStream data.
View Full Code Here

            // Just append
            buffer.getValue().appendBuffer(data);

        } else {
            // Have at least a full chunk
            Buffer chunk = new Buffer();
            chunk.appendBuffer(buffer.getValue());

            if (newLength == fileInfo.getChunkSize()) {
                // Exactly one chunk
                chunk.appendBuffer(data);
                buffer.setValue(new Buffer());

            } else {
                // Will have some remainder to keep in buffer
                int len = fileInfo.getChunkSize() - buffer.getValue().length();
                chunk.appendBytes(data.getBytes(0, len));

                // Add additional chunk to a new buffer
                Buffer remaining = new Buffer();
                remaining.appendBytes(data.getBytes(len, data.length()));

                buffer.setValue(remaining);
            }

            ChunkInfo chunkInfo = new DefaultChunkInfo()
View Full Code Here

        JsonObject jsonObject;
        byte[] data;

        // Parse the byte[] message body
        try {
            Buffer body = message.body();

            // First four bytes indicate the json string length
            int len = body.getInt(0);

            // Decode json
            int from = 4;
            byte[] jsonBytes = body.getBytes(from, from + len);
            jsonObject = new JsonObject(decode(jsonBytes));

            // Remaining bytes are the chunk to be written
            from += len;
            data = body.getBytes(from, body.length());
        } catch (RuntimeException e) {
            sendError(message, "Error while extracting message", e);
            return;
        }
View Full Code Here

        // Wait for the body for jersey to handle form/json/xml params
        if (shouldReadData(vertxRequest)) {
            if (logger.isDebugEnabled()) {
                logger.debug("DefaultJerseyHandler - handle request and read body: " + vertxRequest.method() + " " + vertxRequest.uri());
            }
            final Buffer body = new Buffer();

            vertxRequest.dataHandler(new Handler<Buffer>() {
                public void handle(Buffer buff) {
                    body.appendBuffer(buff);
                    if (body.length() > maxBodySize) {
                        throw new RuntimeException("The input stream has exceeded the max allowed body size "
                                + maxBodySize + ".");
                    }
                }
            });
            vertxRequest.endHandler(new Handler<Void>() {
                @Override
                public void handle(Void event) {
                    InputStream inputStream = new ByteArrayInputStream(body.getBytes());
                    DefaultJerseyHandler.this.handle(vertxRequest, inputStream);
                }
            });

        } else {
View Full Code Here

        // Wait for the body for jersey to handle form/json/xml params
        if (shouldReadData(vertxRequest)) {
            if (logger.isDebugEnabled()) {
                container.logger().debug("DefaultJerseyHandler - handle request and read body: " + vertxRequest.uri());
            }
            final Buffer body = new Buffer();

            vertxRequest.dataHandler(new Handler<Buffer>() {
                public void handle(Buffer buff) {
                    body.appendBuffer(buff);
                    if (body.length() > maxBodySize) {
                        throw new RuntimeException("The input stream has exceeded the max allowed body size "
                                + maxBodySize + ".");
                    }
                }
            });
            vertxRequest.endHandler(new Handler<Void>() {
                @Override
                public void handle(Void event) {
                    InputStream inputStream = new FastByteArrayInputStream(body.getBytes());
                    DefaultJerseyHandler.this.handle(vertxRequest, inputStream);
                }
            });

        } else {
View Full Code Here

        public void flush() throws IOException {
            checkState();
            // Only flush to underlying very.x response if the content-length has been set
            if (buffer.length() > 0 && response.headers().contains(HttpHeaders.CONTENT_LENGTH)) {
                response.write(buffer);
                buffer = new Buffer();
            }
        }
View Full Code Here

         * {@inheritDoc}
         */
        @Override
        public void write(int b) throws IOException {
            checkState();
            Buffer buffer = new Buffer();
            buffer.appendByte((byte) b);
            response.write(buffer);
        }
View Full Code Here

TOP

Related Classes of org.vertx.java.core.buffer.Buffer

Copyright © 2018 www.massapicom. 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.