}
@Override
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public ExportReport exportAllSubsystems(Subject subject) {
ExportWrapper localExport = exportAllSubsystemsLocally(subject);
byte[] buffer = new byte[65536];
ByteArrayOutputStream out = new ByteArrayOutputStream(10240); //10KB is a reasonable minimum size of an export
try {
int cnt = 0;
while ((cnt = localExport.getExportFile().read(buffer)) != -1) {
out.write(buffer, 0, cnt);
}
return new ExportReport(localExport.getMessagesPerExporter(), out.toByteArray());
} catch (Exception e) {
return new ExportReport(e.getMessage());
} finally {
try {
out.close();
} catch (Exception e) {
//this doesn't happen - out is backed by just an array
LOG.error("Closing a byte array output stream failed. This should never happen.");
}
try {
localExport.getExportFile().close();
} catch (Exception e) {
LOG.warn("Failed to close the export file stream.", e);
}
}
}