use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufOutputStream in project SpongeCommon by SpongePowered.
the class SpongeFavicon method encode.
private static String encode(BufferedImage favicon) throws IOException {
checkArgument(favicon.getWidth() == 64, "favicon must be 64 pixels wide");
checkArgument(favicon.getHeight() == 64, "favicon must be 64 pixels high");
ByteBuf buf = Unpooled.buffer();
try {
ImageIO.write(favicon, "PNG", new ByteBufOutputStream(buf));
ByteBuf base64 = Base64.encode(buf);
try {
return SpongeFavicon.FAVICON_PREFIX + base64.toString(Charsets.UTF_8);
} finally {
base64.release();
}
} finally {
buf.release();
}
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufOutputStream in project Fracture by HellFirePvP.
the class PktSyncData method toBytes.
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(data.size());
for (String key : data.keySet()) {
AbstractData dat = data.get(key);
NBTTagCompound cmp = new NBTTagCompound();
if (shouldSyncAll) {
dat.writeAllDataToPacket(cmp);
} else {
dat.writeToPacket(cmp);
}
ByteBufUtils.writeString(buf, key);
byte providerId = dat.getProviderID();
buf.writeByte(providerId);
try {
CompressedStreamTools.write(cmp, new ByteBufOutputStream(buf));
} catch (IOException ignored) {
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufOutputStream in project LanternServer by LanternPowered.
the class LanternFavicon method encode.
/**
* Encodes the buffered image into the encoded favicon string.
*
* @param image the buffered image
* @return the favicon string
*/
private static String encode(BufferedImage image) throws IOException {
checkArgument(image.getWidth() == 64, "favicon must be 64 pixels wide");
checkArgument(image.getHeight() == 64, "favicon must be 64 pixels high");
ByteBuf buf = Unpooled.buffer();
try {
ImageIO.write(image, "PNG", new ByteBufOutputStream(buf));
ByteBuf base64 = Base64.encode(buf);
try {
return FAVICON_PREFIX + base64.toString(StandardCharsets.UTF_8);
} finally {
base64.release();
}
} finally {
buf.release();
}
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufOutputStream in project flink by apache.
the class MessageSerializer method serializeRequestFailure.
/**
* Serializes the exception containing the failure message sent to the {@link
* org.apache.flink.queryablestate.network.Client} in case of protocol related errors.
*
* @param alloc The {@link ByteBufAllocator} used to allocate the buffer to serialize the
* message into.
* @param requestId The id of the request to which the message refers to.
* @param cause The exception thrown at the server.
* @return A {@link ByteBuf} containing the serialized message.
*/
public static ByteBuf serializeRequestFailure(final ByteBufAllocator alloc, final long requestId, final Throwable cause) throws IOException {
final ByteBuf buf = alloc.ioBuffer();
// Frame length is set at the end
buf.writeInt(0);
writeHeader(buf, MessageType.REQUEST_FAILURE);
buf.writeLong(requestId);
try (ByteBufOutputStream bbos = new ByteBufOutputStream(buf);
ObjectOutput out = new ObjectOutputStream(bbos)) {
out.writeObject(cause);
}
// Set frame length
int frameLength = buf.readableBytes() - Integer.BYTES;
buf.setInt(0, frameLength);
return buf;
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufOutputStream in project flink by apache.
the class MessageSerializer method serializeServerFailure.
/**
* Serializes the failure message sent to the {@link
* org.apache.flink.queryablestate.network.Client} in case of server related errors.
*
* @param alloc The {@link ByteBufAllocator} used to allocate the buffer to serialize the
* message into.
* @param cause The exception thrown at the server.
* @return The failure message.
*/
public static ByteBuf serializeServerFailure(final ByteBufAllocator alloc, final Throwable cause) throws IOException {
final ByteBuf buf = alloc.ioBuffer();
// Frame length is set at end
buf.writeInt(0);
writeHeader(buf, MessageType.SERVER_FAILURE);
try (ByteBufOutputStream bbos = new ByteBufOutputStream(buf);
ObjectOutput out = new ObjectOutputStream(bbos)) {
out.writeObject(cause);
}
// Set frame length
int frameLength = buf.readableBytes() - Integer.BYTES;
buf.setInt(0, frameLength);
return buf;
}
Aggregations