将HTTPResponse保留在缓冲流的块中

时间:2022-10-04 20:22:44

I have an API which takes a request and returns a HTTP response but the response content is very huge.I want the response to be chunked into small pieces and return the response in the buffered stream kind of like in cases of videos and images(sample example).

我有一个API,它接受请求并返回HTTP响应,但响应内容非常庞大。我希望将响应分成小块并在缓冲流中返回响应类似于视频和图像的情况(样本例)。

How to give back the response in this way?Can someone give me a sample code of implementing it in HttpServlet responses.

如何以这种方式回复响应?有人可以给我一个在HttpServlet响应中实现它的示例代码。

1 个解决方案

#1


1  

You don't need to. The Servlet container will take care of this for you. Just write to the OutputStream obtained from the response and let the container do the hard work.

你不需要。 Servlet容器将为您处理此问题。只需写入从响应中获取的OutputStream,让容器完成繁重的工作。

#1


1  

You don't need to. The Servlet container will take care of this for you. Just write to the OutputStream obtained from the response and let the container do the hard work.

你不需要。 Servlet容器将为您处理此问题。只需写入从响应中获取的OutputStream,让容器完成繁重的工作。