Java Code Examples for io.netty.buffer.ByteBufOutputStream#writeInt()

The following examples show how to use io.netty.buffer.ByteBufOutputStream#writeInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommandEncoder.java    From pravega with Apache License 2.0 5 votes vote down vote up
@SneakyThrows(IOException.class)
private void writeMessage(AppendBlock block, int blockSize, ByteBuf out) {
    int startIdx = out.writerIndex();
    ByteBufOutputStream bout = new ByteBufOutputStream(out);
    bout.writeInt(block.getType().getCode());
    bout.write(LENGTH_PLACEHOLDER);
    block.writeFields(bout);
    bout.flush();
    bout.close();
    int endIdx = out.writerIndex();
    int fieldsSize = endIdx - startIdx - TYPE_PLUS_LENGTH_SIZE;
    out.setInt(startIdx + TYPE_SIZE, fieldsSize + blockSize);
}
 
Example 2
Source File: CommandEncoder.java    From pravega with Apache License 2.0 5 votes vote down vote up
@SneakyThrows(IOException.class)
@VisibleForTesting
static int writeMessage(WireCommand msg, ByteBuf out) {
    int startIdx = out.writerIndex();
    ByteBufOutputStream bout = new ByteBufOutputStream(out);
    bout.writeInt(msg.getType().getCode());
    bout.write(LENGTH_PLACEHOLDER);
    msg.writeFields(bout);
    bout.flush();
    bout.close();
    int endIdx = out.writerIndex();
    int fieldsSize = endIdx - startIdx - TYPE_PLUS_LENGTH_SIZE;
    out.setInt(startIdx + TYPE_SIZE, fieldsSize);
    return endIdx - startIdx;
}
 
Example 3
Source File: TileNBTPacket.java    From NBTEdit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) throws IOException {
	ByteBufOutputStream bos = new ByteBufOutputStream(buffer);
	bos.writeInt(x);
	bos.writeInt(y);
	bos.writeInt(z);
	NBTHelper.nbtWrite(tag, bos);
}
 
Example 4
Source File: EntityNBTPacket.java    From NBTEdit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) throws IOException {
	ByteBufOutputStream bos = new ByteBufOutputStream(buffer);
	bos.writeInt(entityID);
	NBTHelper.nbtWrite(tag, bos);
}
 
Example 5
Source File: MalmoMod.java    From malmo with MIT License 3 votes vote down vote up
/** Write a potentially long string as UTF8<br>
 * The ByteBufInputStream.readUTF() and writeUTF() calls use the first two bytes of the message
 * to encode the length of the string, which limits the string length to 64k.
 * This method gets around that limitation by using a four byte header.
 * @param s The string we are sending
 * @param bbos The ByteBufOutputStream we are writing to
 * @throws IOException
 */
private void writeLargeUTF(String s, ByteBufOutputStream bbos) throws IOException
{
    byte[] data = s.getBytes("utf-8");
    bbos.writeInt(data.length);
    bbos.write(data);
}