List of usage examples for io.netty.buffer ByteBuf duplicate
public abstract ByteBuf duplicate();
From source file:de.unipassau.isl.evs.ssh.core.network.handler.SignerTest.java
License:Open Source License
public void testModify() { ByteBuf buf = channel.alloc().buffer(); buf.capacity(1000);//from ww w . j ava2 s. c o m while (buf.writableBytes() > 0) { buf.writeByte(buf.writableBytes()); } try { channel.writeOutbound(buf.duplicate().retain()); for (ByteBuf msg; (msg = channel.readOutbound()) != null;) { msg.setByte(500, ~msg.getByte(500)); channel.writeInbound(msg); } channel.checkException(); if (false) throw new SignatureException(); fail("Missing exception"); } catch (SignatureException e) { } if (channel.isOpen()) { fail("Channel not closed"); } }
From source file:divconq.http.multipart.DiskAttribute.java
License:Apache License
@Override public Attribute duplicate() { DiskAttribute attr = new DiskAttribute(getName()); attr.setCharset(getCharset());/*from w ww . j a v a 2s . c om*/ ByteBuf content = content(); if (content != null) { try { attr.setContent(content.duplicate()); } catch (IOException e) { throw new ChannelException(e); } } return attr; }
From source file:divconq.http.multipart.DiskFileUpload.java
License:Apache License
@Override public FileUpload duplicate() { DiskFileUpload upload = new DiskFileUpload(getName(), getFilename(), getContentType(), getContentTransferEncoding(), getCharset(), size); ByteBuf buf = content(); if (buf != null) { try {/*from w w w .ja va 2 s . co m*/ upload.setContent(buf.duplicate()); } catch (IOException e) { throw new ChannelException(e); } } return upload; }
From source file:divconq.http.multipart.MemoryAttribute.java
License:Apache License
@Override public Attribute duplicate() { MemoryAttribute attr = new MemoryAttribute(getName()); attr.setCharset(getCharset());/*ww w.j av a 2s . com*/ ByteBuf content = content(); if (content != null) { try { attr.setContent(content.duplicate()); } catch (IOException e) { throw new ChannelException(e); } } return attr; }
From source file:divconq.http.multipart.MemoryFileUpload.java
License:Apache License
@Override public FileUpload duplicate() { MemoryFileUpload upload = new MemoryFileUpload(getName(), getFilename(), getContentType(), getContentTransferEncoding(), getCharset(), size); ByteBuf buf = content(); if (buf != null) { try {//w w w . j av a 2 s . c o m upload.setContent(buf.duplicate()); return upload; } catch (IOException e) { throw new ChannelException(e); } } return upload; }
From source file:io.airlift.drift.transport.netty.codec.SimpleFrameCodec.java
License:Apache License
private int extractResponseSequenceId(ByteBuf buffer) throws TTransportException { TChannelBufferInputTransport inputTransport = new TChannelBufferInputTransport(buffer.duplicate()); try {//from w w w. j av a 2s.c o m TMessage message = protocol.createProtocol(inputTransport).readMessageBegin(); return message.getSequenceId(); } catch (Throwable e) { throw new TTransportException("Could not find sequenceId in Thrift message", e); } finally { inputTransport.release(); } }
From source file:io.airlift.drift.transport.netty.SimpleMessageEncoding.java
License:Apache License
@Override public OptionalInt extractResponseSequenceId(ByteBuf buffer) { try {//from w w w. ja v a2 s .com TTransport inputTransport = new TChannelBufferInputTransport(buffer.duplicate()); TMessage message = protocolFactory.getProtocol(inputTransport).readMessageBegin(); return OptionalInt.of(message.getSequenceId()); } catch (Throwable ignored) { } return OptionalInt.empty(); }
From source file:io.datty.spring.converter.DattyConverterTest.java
License:Apache License
@Test public void testCross() { ExampleCrossEntity entity = new ExampleCrossEntity(); entity.setId(777L);// w w w . ja va 2 s .c o m entity.setName("Alex"); DattyRecord rec = new DattyRecord(); DattyConverterUtil.write(entity, rec); ByteBuf bb = rec.get("id").asByteBuf(); Assert.assertNotNull(bb); Long id = LongReader.INSTANCE.read(bb.duplicate(), true); Assert.assertNotNull(id); Assert.assertEquals(entity.getId(), id); bb = rec.get("name").asByteBuf(); Assert.assertNotNull(bb); String name = StringReader.INSTANCE.read(bb.duplicate(), true); Assert.assertNotNull(name); Assert.assertEquals(entity.getName(), name); ExampleCrossEntity actual = DattyConverterUtil.read(ExampleCrossEntity.class, rec); Assert.assertEquals(entity, actual); }
From source file:io.datty.spring.converter.embedded.ArrayEntityTest.java
License:Apache License
@Test public void testNull() { ArrayEntity entity = new ArrayEntity(); entity.setId(123L);//from w ww . j a v a 2s .com DattyRecord rec = new DattyRecord(); DattyConverterUtil.write(entity, rec); ByteBuf bb = rec.get("id").asByteBuf(); Assert.assertNotNull(bb); Long id = LongReader.INSTANCE.read(bb.duplicate(), true); Assert.assertNotNull(id); Assert.assertEquals(123L, id.longValue()); Assert.assertNull(rec.get("embedded")); ArrayEntity actual = DattyConverterUtil.read(ArrayEntity.class, rec); Assert.assertEquals(entity.getId(), actual.getId()); Assert.assertNull(actual.getEmbedded()); }
From source file:io.datty.spring.converter.embedded.ArrayEntityTest.java
License:Apache License
@Test public void testEmbeddedEmpty() { ArrayEntity entity = new ArrayEntity(); entity.setId(123L);/*w ww . j a va 2s .com*/ entity.setEmbedded(new EmbeddedEntity[] {}); DattyRecord rec = new DattyRecord(); DattyConverterUtil.write(entity, rec); ByteBuf bb = rec.get("id").asByteBuf(); Assert.assertNotNull(bb); Long id = LongReader.INSTANCE.read(bb.duplicate(), true); Assert.assertNotNull(id); Assert.assertEquals(123L, id.longValue()); bb = rec.get("embedded").asByteBuf(); Assert.assertNotNull(bb); Object value = MessageIO.readValue(bb.duplicate(), true); Assert.assertNotNull(value); Assert.assertTrue(value instanceof List); List<Map> list = (List<Map>) value; Assert.assertEquals(0, list.size()); ArrayEntity actual = DattyConverterUtil.read(ArrayEntity.class, rec); Assert.assertEquals(entity.getId(), actual.getId()); Assert.assertNotNull(actual.getEmbedded()); Assert.assertEquals(0, actual.getEmbedded().length); }