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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations