Hi,
I am reading a large file of 25 MiB and sending it over the websocket. Just after a few seconds I get OutofMemoryError exception. Below is my code for reference
byte[] chunk = new byte[CHUNK_SIZE];
int read;
while ((read = fis.read(chunk)) != -1) {
data.sendBinaryMessage(chunk);
// Can't reuse chunk as it's used by socket
chunk = new byte[CHUNK_SIZE];
}
I suspect the file read is faster than socket write. Is there any design pattern I can follow to overcome this situation.
Thanks
Vishal