Package io.netty.buffer

Examples of io.netty.buffer.ByteBuf.readBytes()


            try {
                if (buf.hasArray()) {
                    return buf.array();
                } else {
                    byte[] result = new byte[buf.readableBytes()];
                    buf.readBytes(result);
                    return result;
                }
            } finally {
                buf.release();
            }
View Full Code Here


        ByteBuf finalPayloadWrapped = Unpooled.wrappedBuffer(uncompressedFrame1.content(),
                uncompressedFrame2.content(), uncompressedFrame3.content());
        assertEquals(300, finalPayloadWrapped.readableBytes());

        byte[] finalPayload = new byte[300];
        finalPayloadWrapped.readBytes(finalPayload);
        assertTrue(Arrays.equals(finalPayload, payload));
        finalPayloadWrapped.release();
    }

    @Test
View Full Code Here

        final ByteArrayOutputStream out = new ByteArrayOutputStream(length);
        doAnswer(new Answer<Void>() {
            @Override
            public Void answer(InvocationOnMock in) throws Throwable {
                ByteBuf buf = (ByteBuf) in.getArguments()[2];
                buf.readBytes(out, buf.readableBytes());
                return null;
            }
        }).when(serverListener).onDataRead(any(ChannelHandlerContext.class), eq(3),
                any(ByteBuf.class), eq(0), Mockito.anyBoolean());
        try {
View Full Code Here

        boolean result = channel.writeOutbound(request);
        assertThat(result, is(true));

        ByteBuf written = channel.readOutbound();
        assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE + extrasLength));
        written.readBytes(DEFAULT_HEADER_SIZE);
        assertThat(written.readBytes(extrasLength).toString(CharsetUtil.UTF_8), equalTo(extrasContent));
        written.release();
    }

    @Test
View Full Code Here

        assertThat(result, is(true));

        ByteBuf written = channel.readOutbound();
        assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE + extrasLength));
        written.readBytes(DEFAULT_HEADER_SIZE);
        assertThat(written.readBytes(extrasLength).toString(CharsetUtil.UTF_8), equalTo(extrasContent));
        written.release();
    }

    @Test
    public void shouldEncodeKey() {
View Full Code Here

        boolean result = channel.writeOutbound(request);
        assertThat(result, is(true));

        ByteBuf written = channel.readOutbound();
        assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE + keyLength));
        written.readBytes(DEFAULT_HEADER_SIZE);
        assertThat(written.readBytes(keyLength).toString(CharsetUtil.UTF_8), equalTo(key));
        written.release();
    }

    @Test
View Full Code Here

        assertThat(result, is(true));

        ByteBuf written = channel.readOutbound();
        assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE + keyLength));
        written.readBytes(DEFAULT_HEADER_SIZE);
        assertThat(written.readBytes(keyLength).toString(CharsetUtil.UTF_8), equalTo(key));
        written.release();
    }

    @Test
    public void shouldEncodeContent() {
View Full Code Here

        ByteBuf written = channel.readOutbound();
        assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE));
        written = channel.readOutbound();
        assertThat(written.readableBytes(), is(content1.content().readableBytes()));
        assertThat(
                written.readBytes(content1.content().readableBytes()).toString(CharsetUtil.UTF_8),
                is("Netty")
        );
        written.release();

        written = channel.readOutbound();
View Full Code Here

        written.release();

        written = channel.readOutbound();
        assertThat(written.readableBytes(), is(content2.content().readableBytes()));
        assertThat(
                written.readBytes(content2.content().readableBytes()).toString(CharsetUtil.UTF_8),
                is(" Rocks!")
        );
        written.release();
    }
View Full Code Here

        KeyFactory rsaKF = KeyFactory.getInstance("RSA");
        KeyFactory dsaKF = KeyFactory.getInstance("DSA");

        ByteBuf encodedKeyBuf = PemReader.readPrivateKey(keyFile);
        byte[] encodedKey = new byte[encodedKeyBuf.readableBytes()];
        encodedKeyBuf.readBytes(encodedKey).release();

        char[] keyPasswordChars = keyPassword == null ? EmptyArrays.EMPTY_CHARS : keyPassword.toCharArray();
        PKCS8EncodedKeySpec encodedKeySpec = generateKeySpec(keyPasswordChars, encodedKey);

        PrivateKey key;
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.