You could try something like the below:
public void writeData(FileDocument outputDocument, XSSFWorkbook wb) throws Exception
{
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
wb.write(out);
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray())) {
Core.storeFileDocumentContent(context, outputDocument.getMendixObject(), inputStream);
}
}
}
FYI; this has been done numerous times before, please check the Excel Exporter module code as well on how this is done.