Reputation: 41
I have a method which returns StreamingOutput Object. And i want to write this StreamingOutput object into excel file. And i have written the following code, which is giving me the java.lang.ClassCastException
Exception.
StreamingOutput stream = getStreamObject();
SXSSFWorkbook workBook = (SXSSFWorkbook) stream; //Exception occurs here
FileOutputStream fileOut = new FileOutputStream("/save/excel/file/here");
workBook.write(fileOut);
fileOut.flush();
fileOut.close();
So, Please help me out with this. Thank You in Advance.
Upvotes: 0
Views: 1469
Reputation: 149
StreamingOutput write method must be overridden to return the output object. Here is an example :
public Response streamExample(){
StreamingOutput stream = new StreamingOutput() {
@Override
public void write(OutputStream out) throws IOException, WebApplicationException {
Writer writer = new BufferedWriter(new OutputStreamWriter(out));
for (int i = 0; i < 10000000 ; i++){
writer.write(i + " ");
}
writer.flush();
}
};
return Response.ok(stream).build();
}
Please check the Docs of Streaming output and here for more information
Upvotes: 2