use of io.netty.buffer.ByteBufInputStream in project netty by netty.
the class DefaultChannelIdTest method testSerialization.
@Test
public void testSerialization() throws Exception {
ChannelId a = DefaultChannelId.newInstance();
ChannelId b;
ByteBuf buf = Unpooled.buffer();
ObjectOutputStream out = new ObjectOutputStream(new ByteBufOutputStream(buf));
try {
out.writeObject(a);
out.flush();
} finally {
out.close();
}
ObjectInputStream in = new ObjectInputStream(new ByteBufInputStream(buf, true));
try {
b = (ChannelId) in.readObject();
} finally {
in.close();
}
assertThat(a, is(b));
assertThat(a, is(not(sameInstance(b))));
assertThat(a.asLongText(), is(b.asLongText()));
}
use of io.netty.buffer.ByteBufInputStream in project netty by netty.
the class CompatibleObjectEncoderTest method testEncode.
private static void testEncode(EmbeddedChannel channel, TestSerializable original) throws IOException, ClassNotFoundException {
channel.writeOutbound(original);
Object o = channel.readOutbound();
ByteBuf buf = (ByteBuf) o;
ObjectInputStream ois = new ObjectInputStream(new ByteBufInputStream(buf));
try {
assertEquals(original, ois.readObject());
} finally {
buf.release();
ois.close();
}
}
use of io.netty.buffer.ByteBufInputStream in project netty by netty.
the class EmbeddedChannelIdTest method testSerialization.
@Test
public void testSerialization() throws IOException, ClassNotFoundException {
// test that a deserialized instance works the same as a normal instance (issue #2869)
ChannelId normalInstance = EmbeddedChannelId.INSTANCE;
ByteBuf buf = Unpooled.buffer();
ObjectOutputStream outStream = new ObjectOutputStream(new ByteBufOutputStream(buf));
try {
outStream.writeObject(normalInstance);
} finally {
outStream.close();
}
ObjectInputStream inStream = new ObjectInputStream(new ByteBufInputStream(buf, true));
final ChannelId deserializedInstance;
try {
deserializedInstance = (ChannelId) inStream.readObject();
} finally {
inStream.close();
}
assertEquals(normalInstance, deserializedInstance);
assertEquals(normalInstance.hashCode(), deserializedInstance.hashCode());
assertEquals(0, normalInstance.compareTo(deserializedInstance));
}
use of io.netty.buffer.ByteBufInputStream in project moco by dreamhead.
the class MocoSocketHandler method channelRead0.
@Override
protected void channelRead0(final ChannelHandlerContext ctx, final ByteBuf msg) {
MessageContent content = content().withContent(new ByteBufInputStream(msg)).build();
SocketRequest request = new DefaultSocketRequest(content);
SessionContext context = new SessionContext(request, new DefaultSocketResponse());
Optional<Response> response = server.getResponse(context);
Response actual = response.orElseThrow(() -> new MocoException(format("No handler found for request: %s", context.getRequest().getContent())));
ctx.write(ByteBufs.toByteBuf(actual.getContent().getContent()));
}
use of io.netty.buffer.ByteBufInputStream in project RecurrentComplex by Ivorforce.
the class RCPacketBuffer method readBigTag.
@Nullable
public NBTTagCompound readBigTag() throws IOException {
int i = this.readerIndex();
byte b0 = this.readByte();
if (b0 == 0) {
return null;
} else {
this.readerIndex(i);
try {
return CompressedStreamTools.read(new ByteBufInputStream(this), new NBTSizeTracker(2097152L * 4));
} catch (IOException ioexception) {
throw new EncoderException(ioexception);
}
}
}
Aggregations