Is there a way for Java outputstream to implement append?

Hello, everyone. I have a problem.

update: in fact, outputstream.write is an additional operation, not a rewrite. For example, after the first write and flush , flush can also be pushed to the client, and it is appended. My problem is that the subsequent appended operations are not written to the excel generated for the first time. In Explorer, you can see that the file size is 28kb, and when it is opened and then closed, it becomes 8kb.

< hr >

original question:

if the client wants to download the excel file, I find it in the database, then use apache poi to generate the byte array, to set the response header, and then send it back to the client, and the client can download it.

The problem with

is that sometimes it takes a long time to generate this excel, and the browser times out when it doesn"t receive a response. I wondered if I could generate a part and send a part so that the connection was established. Until all the content is generated, then close the connection.

I used servlet.getOutputStream () , and did not find a method similar to append. The PrinterWriter class has a similar method, but I tried it. If it is sent back to the client, it cannot be opened, so it can only be sent back in binary, right? I also tried socket , but I also needed the method socket.getOutputStream (); to get the output stream, which came back.

so come here to ask you, is there any other way to achieve my need, or is this requirement unachievable? If there is a better way, please let me know. Thank you!

Sep.16,2021

can be achieved, but it's troublesome, because you can only get an outputstream, with poi, and if you want to provide it to the client in a stream, you need an inputstream, so you need a PipedInputStream, and then convert the outputstream into an inputstream, and then you need to prepare a separate thread to implement the poi operation, otherwise you can't operate on outputstream and inputstream at the same time in the same thread. So it's still troublesome, but it can be done. The code example did not find a suitable one, you can take a look at the relevant documentation of PipedInputStream/PipedOutputStream.


you can return to a page first, just as the download will start in one minute in the data processing of the download file. , save the processed file, time to display the link, or request automatically, and then send the file when the request comes

.

if the processing time is not long, you can also try to set the timeout a little longer

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4622d-44b6a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4622d-44b6a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?