Search in sources :

Example 1 with ByteBufOutputStream

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufOutputStream in project hbase by apache.

the class FanOutOneBlockAsyncDFSOutputHelper method requestWriteBlock.

private static void requestWriteBlock(Channel channel, Enum<?> storageType, OpWriteBlockProto.Builder writeBlockProtoBuilder) throws IOException {
    OpWriteBlockProto proto = STORAGE_TYPE_SETTER.set(writeBlockProtoBuilder, storageType).build();
    int protoLen = proto.getSerializedSize();
    ByteBuf buffer = channel.alloc().buffer(3 + CodedOutputStream.computeRawVarint32Size(protoLen) + protoLen);
    buffer.writeShort(DataTransferProtocol.DATA_TRANSFER_VERSION);
    buffer.writeByte(Op.WRITE_BLOCK.code);
    proto.writeDelimitedTo(new ByteBufOutputStream(buffer));
    channel.writeAndFlush(buffer);
}
Also used : ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) OpWriteBlockProto(org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.OpWriteBlockProto) ByteBuf(io.netty.buffer.ByteBuf)

Example 2 with ByteBufOutputStream

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufOutputStream in project flink by apache.

the class KvStateRequestSerializer method serializeKvStateRequestFailure.

/**
	 * Allocates a buffer and serializes the KvState request failure into it.
	 *
	 * @param alloc ByteBuf allocator for the buffer to serialize message into
	 * @param requestId ID of the request responding to
	 * @param cause Failure cause
	 * @return Serialized KvState request failure message
	 * @throws IOException Serialization failures are forwarded
	 */
public static ByteBuf serializeKvStateRequestFailure(ByteBufAllocator alloc, long requestId, Throwable cause) throws IOException {
    ByteBuf buf = alloc.ioBuffer();
    // Frame length is set at the end
    buf.writeInt(0);
    writeHeader(buf, KvStateRequestType.REQUEST_FAILURE);
    // Message
    buf.writeLong(requestId);
    try (ByteBufOutputStream bbos = new ByteBufOutputStream(buf);
        ObjectOutputStream out = new ObjectOutputStream(bbos)) {
        out.writeObject(cause);
    }
    // Set frame length
    int frameLength = buf.readableBytes() - 4;
    buf.setInt(0, frameLength);
    return buf;
}
Also used : ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) ByteBuf(io.netty.buffer.ByteBuf) ObjectOutputStream(java.io.ObjectOutputStream)

Example 3 with ByteBufOutputStream

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufOutputStream in project flink by apache.

the class KvStateRequestSerializer method serializeServerFailure.

/**
	 * Allocates a buffer and serializes the server failure into it.
	 *
	 * <p>The cause must not be or contain any user types as causes.
	 *
	 * @param alloc ByteBuf allocator for the buffer to serialize message into
	 * @param cause Failure cause
	 * @return Serialized server failure message
	 * @throws IOException Serialization failures are forwarded
	 */
public static ByteBuf serializeServerFailure(ByteBufAllocator alloc, Throwable cause) throws IOException {
    ByteBuf buf = alloc.ioBuffer();
    // Frame length is set at end
    buf.writeInt(0);
    writeHeader(buf, KvStateRequestType.SERVER_FAILURE);
    try (ByteBufOutputStream bbos = new ByteBufOutputStream(buf);
        ObjectOutputStream out = new ObjectOutputStream(bbos)) {
        out.writeObject(cause);
    }
    // Set frame length
    int frameLength = buf.readableBytes() - 4;
    buf.setInt(0, frameLength);
    return buf;
}
Also used : ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) ByteBuf(io.netty.buffer.ByteBuf) ObjectOutputStream(java.io.ObjectOutputStream)

Example 4 with ByteBufOutputStream

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufOutputStream in project Railcraft by Railcraft.

the class RailcraftTileEntity method getUpdateTag.

@Override
public final NBTTagCompound getUpdateTag() {
    NBTTagCompound nbt = super.getUpdateTag();
    ByteBuf byteBuf = Unpooled.buffer();
    try (ByteBufOutputStream out = new ByteBufOutputStream(byteBuf);
        RailcraftOutputStream data = new RailcraftOutputStream(out)) {
        writePacketData(data);
    } catch (IOException e) {
        Game.logThrowable("Error constructing tile packet: {0}", e, getClass());
        if (Game.DEVELOPMENT_ENVIRONMENT)
            throw new RuntimeException(e);
    }
    nbt.setByteArray("sync", byteBuf.array());
    return nbt;
}
Also used : ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) RailcraftOutputStream(mods.railcraft.common.util.network.RailcraftOutputStream) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf)

Example 5 with ByteBufOutputStream

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufOutputStream in project ratpack by ratpack.

the class JsonRenderer method render.

@Override
public void render(Context ctx, JsonRender object) throws Exception {
    ObjectWriter writer = object.getObjectWriter();
    if (writer == null) {
        writer = ctx.maybeGet(ObjectWriter.class).orElseGet(() -> ctx.get(ObjectMapper.class).writer());
    }
    Class<?> viewClass = object.getViewClass();
    if (viewClass != null) {
        writer = writer.withView(viewClass);
    }
    ByteBuf buffer = ctx.get(ByteBufAllocator.class).buffer();
    OutputStream outputStream = new ByteBufOutputStream(buffer);
    try {
        writer.writeValue(outputStream, object.getObject());
    } catch (JsonProcessingException e) {
        buffer.release();
        ctx.error(e);
        return;
    }
    ctx.getResponse().contentTypeIfNotSet(HttpHeaderConstants.JSON).send(buffer);
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) OutputStream(java.io.OutputStream) ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ByteBuf(io.netty.buffer.ByteBuf) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ByteBufOutputStream (io.netty.buffer.ByteBufOutputStream)52 ByteBuf (io.netty.buffer.ByteBuf)37 IOException (java.io.IOException)18 ObjectOutputStream (java.io.ObjectOutputStream)11 OutputStreamWriter (java.io.OutputStreamWriter)6 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)5 OutputStream (java.io.OutputStream)5 Test (org.junit.jupiter.api.Test)5 ObjectInputStream (java.io.ObjectInputStream)4 SneakyThrows (lombok.SneakyThrows)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)3 Writer (java.io.Writer)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 CodedOutputStream (com.google.protobuf.CodedOutputStream)2 Bootstrap (io.netty.bootstrap.Bootstrap)2 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)2