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();

            // 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 byte[] message.  see the documentation for the correct format", e);
            return;
        }
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 ByteArrayInputStream(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

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

         * {@inheritDoc}
         */
        @Override
        public void write(byte[] b, int off, int len) throws IOException {
            checkState();
            Buffer buffer = new Buffer();
            if (off == 0 && len == b.length) {
                buffer.appendBytes(b);
            } else {
                buffer.appendBytes(Arrays.copyOfRange(b, off, off + len));
            }
            response.write(buffer);
        }
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 ByteArrayInputStream(body.getBytes());
                    DefaultJerseyHandler.this.handle(vertxRequest, inputStream);
                }
            });

        } else {
View Full Code Here

                // real compile
                template = handlebars.compile(filename);
                putTemplateToCache(resolve(filename), template);
            }

            next.handle(new YokeAsyncResult<>(new Buffer(template.apply(context))));
        } catch (Exception ex) {
            ex.printStackTrace();
            next.handle(new YokeAsyncResult<Buffer>(ex));
        }
    }
View Full Code Here

                assertEquals(((JsonObject) request.body()).encode(), json.encode());
                request.response().end();
            }
        });

        Buffer body = new Buffer(json.encode());

        MultiMap headers = new CaseInsensitiveMultiMap();
        headers.add("content-type", "application/json");
        headers.add("content-length", Integer.toString(body.length()));

        new YokeTester(yoke).request("POST", "/upload", headers, body, new Handler<Response>() {
            @Override
            public void handle(Response resp) {
                assertEquals(200, resp.getStatusCode());
View Full Code Here

                assertEquals("value", body.get("param"));
                request.response().end();
            }
        });

        Buffer body = new Buffer("param=value");

        MultiMap headers = new CaseInsensitiveMultiMap();
        headers.add("content-type", "application/x-www-form-urlencoded");
        headers.add("content-length", Integer.toString(body.length()));

        new YokeTester(yoke).request("POST", "/upload", headers, body, new Handler<Response>() {
            @Override
            public void handle(Response resp) {
                assertEquals(200, resp.getStatusCode());
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.