'Netty send large byte array

How can I send a large array of bytes (700mb) to a client via Netty?
I've tried these methods (buf is ByteBuf) but they don't work with large arrays of bytes (they work with 50 megabytes in size)

public void writeBytes(byte[] bytes) {
    buf.writeInt(bytes.length);
    buf.writeBytes(bytes);
}

public byte[] readBytes() {
    byte[] bytes = new byte[buf.readInt()];
    buf.readBytes(bytes);

    return bytes;
}

I also tried adding this to the pipeline (client and server), but it had no effect

pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
pipeline.addLast(new LengthFieldPrepender(4));


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source