I am working on a Java function which is expected to return a protected Excel file (xlsx) in byte array. I found a solution which used the Encryption support of Apache POI: How to Protect Excel Workbook Via SXSSF? However, OutputStream cannot be cast into ByteArrayOutputStream. I tried to find a way to convert the OutputStream into ByteArray but all