Is there a way to obtain InputStream
of Apache's POI Workbook?
I need it for piping to another OutputStream
, however I'm unable to find such method (If it exists).
If it doesn't, any tips on alternative ways to obtain it?
Here's how to implement #2 of Alexander Tokarev's answer (i.e get Inputstream from a workbook):
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
workbook.write(bos);
byte[] barray = bos.toByteArray();
InputStream is = new ByteArrayInputStream(barray);
} catch (IOException e) {
e.printStackTrace();
}
There's a several ways to solve this:
PipetInputStream
and PipedOutputStream
. But you have to create different thread for using PipedInputStream
(as described in http://docs.oracle.com/javase/7/docs/api/java/io/PipedInputStream.html)ByteArrayOutputStream
, and then you can use resulting byte array via ByteArrayInputStream
. This can be done sequentially in one thread.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With