Search in sources :

Example 31 with ByteBufInputStream

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()));
}
Also used : ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) ByteBuf(io.netty.buffer.ByteBuf) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.jupiter.api.Test)

Example 32 with ByteBufInputStream

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();
    }
}
Also used : ByteBufInputStream(io.netty.buffer.ByteBufInputStream) ByteBuf(io.netty.buffer.ByteBuf) ObjectInputStream(java.io.ObjectInputStream)

Example 33 with ByteBufInputStream

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));
}
Also used : ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) ChannelId(io.netty.channel.ChannelId) ByteBuf(io.netty.buffer.ByteBuf) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.jupiter.api.Test)

Example 34 with ByteBufInputStream

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()));
}
Also used : DefaultSocketResponse(com.github.dreamhead.moco.model.DefaultSocketResponse) Response(com.github.dreamhead.moco.Response) MessageContent(com.github.dreamhead.moco.model.MessageContent) DefaultSocketRequest(com.github.dreamhead.moco.model.DefaultSocketRequest) SocketRequest(com.github.dreamhead.moco.SocketRequest) DefaultSocketRequest(com.github.dreamhead.moco.model.DefaultSocketRequest) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) MocoException(com.github.dreamhead.moco.MocoException) DefaultSocketResponse(com.github.dreamhead.moco.model.DefaultSocketResponse)

Example 35 with ByteBufInputStream

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);
        }
    }
}
Also used : NBTSizeTracker(net.minecraft.nbt.NBTSizeTracker) EncoderException(io.netty.handler.codec.EncoderException) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Aggregations

ByteBufInputStream (io.netty.buffer.ByteBufInputStream)69 ByteBuf (io.netty.buffer.ByteBuf)22 IOException (java.io.IOException)22 InputStreamReader (java.io.InputStreamReader)18 BadRequestException (co.cask.cdap.common.BadRequestException)16 Reader (java.io.Reader)16 JsonSyntaxException (com.google.gson.JsonSyntaxException)11 InputStream (java.io.InputStream)10 Path (javax.ws.rs.Path)9 ObjectInputStream (java.io.ObjectInputStream)8 NamespaceId (co.cask.cdap.proto.id.NamespaceId)6 POST (javax.ws.rs.POST)6 Test (org.junit.jupiter.api.Test)5 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)4 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)4 ByteBufOutputStream (io.netty.buffer.ByteBufOutputStream)4 RpcException (org.apache.drill.exec.rpc.RpcException)4 UnsupportedTypeException (co.cask.cdap.api.data.schema.UnsupportedTypeException)3 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)3 ObjectOutputStream (java.io.ObjectOutputStream)3