My current application requires to read data and enable user to download it as a file. Server side code is similar to this : https://stackoverflow.com/a/55788/3192744 I need data inside InputStream, my current method to get InputStream is:
InputStream getIStream(){
StringBuilder sb = new StringBuilder();
String temp = “”;
while(//there is data to be read from database//){
temp = //partial data or one entry from database
//some other modification in temp
sb.append(temp).append(“\n”);
}
exampleString = sb.toString();
InputStream stream = new ByteArrayInputStream(exampleString.getBytes());
}
This method works for now since my data is very small, about 1000 String, each of about 100 chars, hence 100000 chars. Still, before I start download, I need to wait for entire data to be written in one string. Also as my data size increases it won't fit in one string. So Is it possible to keep updating InputStream inside the while loop.
And to read this data on server side, I am waiting the method to return InputStream, so is it possible to send InputStream as method argument, and keep reading from it while it is being updated.
Basically I want to implement something like a pipe, where modified strings from database output are being sent, and on the receiving end data is being put in the file for user to download, and download process for user can start while data is being read from database.