ich Streaming-Ausgabe in meiner Jersey Ressource Klasse implementiert hatte.Trikot - StreamingOutput als Antwort Einheit
@GET
@Path("xxxxx")
@Produces(BulkConstants.TEXT_XML_MEDIA_TYPE})
public Response getFile() {
FeedReturnStreamingOutput sout = new FeedReturnStreamingOutput();
response = Response.ok(sout).build();
return response;
}
class FeedReturnStreamingOutput implements StreamingOutput {
public FeedReturnStreamingOutput()
@Override
public void write(OutputStream outputStream) {
//write into Output Stream
}
}
Das Problem ist, obwohl eine Antwort von der Ressource zurückgesendet wird, bevor FeedReturnStreamingOutput heißt Jersey Client wartet, bis FeedReturnStreamingOutput Ausführung abgeschlossen ist.
Client-Code:
Client client = Client.create();
ClientResponse response = webResource
//headers
.get(ClientResponse.class);
//The codes underneath executes after FeedReturnStreamingOutput is executed which undermines the necessity of streaming
OutputStream os = new FileOutputStream("c:\\test\\feedoutput5.txt");
System.out.println(new Date() + " : Reached point A");
if (response.getStatus() == 200) {
System.out.println(new Date() + " : Reached point B");
InputStream io = response.getEntityInputStream();
byte[] buff = new byte[1024000];
int count = 0;
while ((count = io.read(buff, 0, buff.length)) != -1) {
os.write(buff, 0, count);
}
os.close();
io.close();
} else {
System.out.println("Response code :" + response.getStatus());
}
System.out.println("Time taken -->> "+(System.currentTimeMillis()-startTime)+" ms");
Dies ist eine großartige Lösung. Eine Sache, die ich gerade gefunden habe - das funktioniert nur, wenn Sie am Ende Ihrer Eingabe einen Zeilenumbruch haben :) – pandaadb