class AccountController implements AccountApi {

    @GetMapping(value = "/v1/accounts/{account-id}/transactions/download/{download-id}")
    public void downloadTransactions(@RequestHeader("Consent-ID") String consentId,
                                     @PathVariable("account-id") String accountId,
                                     @PathVariable("download-id") String downloadId) {
        ResponseObject<Xs2aTransactionsDownloadResponse> downloadTransactionsResponse = transactionService.downloadTransactions(consentId, accountId, downloadId);

        if (downloadTransactionsResponse.hasError()) {
            flushResponseError(downloadTransactionsResponse.getError());
            return;
        }

        Xs2aTransactionsDownloadResponse responseBody = downloadTransactionsResponse.getBody();
        Integer dataSizeBytes = responseBody.getDataSizeBytes();
        String dataFileName = responseBody.getDataFileName();

        try (InputStream transactions = responseBody.getTransactionStream()) {
            IOUtils.copy(transactions, response.getOutputStream(), 4096);
            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
            response.addHeader("Content-Disposition", resolveContentDisposition(dataFileName));
            if (dataSizeBytes != null) {
                response.setContentLength(dataSizeBytes);
            }
            response.flushBuffer();
        } catch (IOException e) {
            log.info("Consent-ID: [{}], Account-ID: [{}]. Download-ID [{}]. Download transactions failed: IOException occurred in downloadTransactions controller.",
                     consentId, accountId, downloadId);
            flushResponseError(new TppErrorMessage(ERROR, MessageErrorCode.INTERNAL_SERVER_ERROR));
        }
    }

}