How to return multiple InputStream objects in rest API response?

830 Views Asked by At

I have one rest API developed in Java SpringBoot in which I am able to single InputStream object in a response using following code.

public ResponseEntity<StreamingResponseBody> export(request) throws FileNotFoundException { 
InputStream inputStream = service.getDocumentObject();
StreamingResponseBody responseBody = outputStream -> {
    int numberOfBytesToWrite;
    byte[] data = new byte[1024];
    while ((numberOfBytesToWrite = inputStream.read(data, 0, data.length)) != -1) {
        System.out.println("Writing some bytes..");
        outputStream.write(data, 0, numberOfBytesToWrite);
    }
    inputStream.close();
};
return ResponseEntity.ok()
        .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=generic_file_name.bin")
        .contentType(MediaType.APPLICATION_OCTET_STREAM)
        .body(responseBody);}

But now I have requirement where I have to return multiple InputStream Objects in the API response. Is it possible to do the same? if yes then please share sample code snippet for referece.

Thanks in Advance.

0

There are 0 best solutions below