List of usage examples for io.netty.buffer Unpooled wrappedBuffer
public static ByteBuf wrappedBuffer(ByteBuffer... buffers)
From source file:io.datty.spring.converter.AllTypesConverterTest.java
License:Apache License
@Test public void testOnes() throws Exception { AllTypesEntity entity = new AllTypesEntity(); entity.setBooleanVal(true);// w w w . ja v a2 s . com entity.setBooleanWal(true); entity.setByteVal((byte) 1); entity.setByteWal((byte) 1); entity.setShortVal((short) 1); entity.setShortWal((short) 1); entity.setIntVal(1); entity.setIntWal(1); entity.setLongVal(1L); entity.setLongWal(1L); entity.setFloatVal(1.0f); entity.setFloatWal(1.0f); entity.setDoubleVal(1.0d); entity.setDoubleWal(1.0d); entity.setStringVal("1"); entity.setBbVal(Unpooled.wrappedBuffer(new byte[] { 1 })); testNotEmpty(entity); }
From source file:io.gatling.http.client.body.bytearray.ByteArrayRequestBody.java
License:Apache License
@Override public WritableContent build(boolean zeroCopy, ByteBufAllocator alloc) { return new WritableContent(Unpooled.wrappedBuffer(content), content.length); }
From source file:io.gatling.http.client.body.bytearrays.ByteArraysRequestBody.java
License:Apache License
@Override public WritableContent build(boolean zeroCopy, ByteBufAllocator alloc) { return new WritableContent(Unpooled.wrappedBuffer(content), contentLength); }
From source file:io.gatling.http.client.body.multipart.impl.ByteArrayPartImpl.java
License:Apache License
public ByteArrayPartImpl(ByteArrayPart part, byte[] boundary) { super(part, boundary); contentBuffer = Unpooled.wrappedBuffer(part.getContent()); }
From source file:io.gatling.http.client.body.multipart.impl.StringPartImpl.java
License:Apache License
public StringPartImpl(StringPart part, byte[] boundary) { super(part, boundary); contentBuffer = Unpooled.wrappedBuffer(part.getContent().getBytes(part.getCharset())); }
From source file:io.gatling.http.client.test.listener.ResponseAsStringListener.java
License:Apache License
protected String responseBody() { if (isNonEmpty(chunks)) { Charset charset = withDefault( extractContentTypeCharsetAttribute(headers.get(HttpHeaderNames.CONTENT_TYPE)), UTF_8); ByteBuf composite = Unpooled.wrappedBuffer(chunks.toArray(ByteBufUtils.EMPTY_BYTEBUF_ARRAY)); try {//from www. ja va 2 s .c om return composite.toString(charset); } finally { composite.release(); } } return null; }
From source file:io.gatling.netty.util.ahc.ByteBufUtils.java
License:Apache License
private static ByteBuf composite(ByteBuf[] bufs) { for (ByteBuf buf : bufs) { buf.retain(); } return Unpooled.wrappedBuffer(bufs); }
From source file:io.gatling.netty.util.ahc.Utf8ByteBufCharsetDecoderTest.java
License:Apache License
@Test void testByteBuf2BytesHasBackingArray() { byte[] inputBytes = "testdata".getBytes(US_ASCII); ByteBuf buf = Unpooled.wrappedBuffer(inputBytes); try {/*from w w w . j av a2s .c o m*/ byte[] output = ByteBufUtils.byteBuf2Bytes(buf); assertArrayEquals(inputBytes, output); } finally { buf.release(); } }
From source file:io.gatling.netty.util.ahc.Utf8ByteBufCharsetDecoderTest.java
License:Apache License
@Test void byteBufs2StringShouldBeAbleToDealWithBrokenCharsTheSameWayAsJavaImpl() { String inputString = "foo bar"; byte[] inputBytes = inputString.getBytes(UTF_8); int droppedBytes = 1; for (int i = 1; i < inputBytes.length - 1 - droppedBytes; i++) { byte[] part1 = Arrays.copyOfRange(inputBytes, 0, i); byte[] part2 = Arrays.copyOfRange(inputBytes, i + droppedBytes, inputBytes.length); byte[] merged = new byte[part1.length + part2.length]; System.arraycopy(part1, 0, merged, 0, part1.length); System.arraycopy(part2, 0, merged, part1.length, part2.length); ByteBuf buf1 = Unpooled.wrappedBuffer(part1); ByteBuf buf2 = Unpooled.wrappedBuffer(part2); try {//from w ww . java 2 s .com String output = ByteBufUtils.byteBuf2String(UTF_8, buf1, buf2); String javaString = new String(merged, UTF_8); assertNotEquals(inputString, output); assertEquals(javaString, output); } finally { buf1.release(); buf2.release(); } } }
From source file:io.github.lordakkarin.nbt.event.TagReader.java
License:Apache License
public TagReader(@NonNull ReadableByteChannel channel) throws IOException { this.buffer = Unpooled.directBuffer(); {/* w ww.j a va 2 s. co m*/ ByteBuffer tmp = ByteBuffer.allocateDirect(128); ByteBuf wrapped = Unpooled.wrappedBuffer(tmp); int length; while ((length = channel.read(tmp)) > 0) { tmp.flip(); this.buffer.writeBytes(wrapped, length); wrapped.resetReaderIndex(); tmp.rewind(); } } }