I am trying to implement a servlet for streaming large objects:
oracle.sql.BLOB blob = rs.getBLOB('obj');
InputStream in = blob.getBinaryStream();
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
ServletOutputStream out = response.getOutputStream();
int counter=0
while((length=in.read(buffer)) != -1){
out.write(buffer,0,length);
counter++;
if(counter % 10 == 0){
counter=0;
response.flushBuffer();
}
This code suppose to send data to client chunk by chunck. Now what's happening is that when I stream large object (100 MB), memory goes up, and server dies sometimes if there are more than one parallel downloads/stream.
Why this flushBuffer()
is not sending data to client? The client get popup for open/save file only after response closes.