Source:
<code>public Void uploadFile(final File localTempFile, final String remotePath) { try { return retryExecutor() .withRetryLimit(maxConnectionRetry) .withInitialRetryWait(500) .withMaxRetryWait(30 * 1000) .runInterruptible(new Retryable<Void>() { @Override public Void call() throws IOException { <START> FileObject remoteFile = newSftpFile(getSftpFileUri(remotePath)); <END> logger.info("new sftp file: {}", remoteFile.getPublicURIString()); try (BufferedOutputStream outputStream = new BufferedOutputStream(remoteFile.getContent().getOutputStream())) { try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(localTempFile))) { IOUtils.copy(inputStream, outputStream); } } remoteFile.close(); return null; } @Override public boolean isRetryableException(Exception exception) { return true; } @Override public void onRetry(Exception exception, int retryCount, int retryLimit, int retryWait) throws RetryGiveupException { String message = String.format("SFTP output failed. Retrying %d/%d after %d seconds. Message: %s", retryCount, retryLimit, retryWait / 1000, exception.getMessage()); if (retryCount % 3 == 0) { logger.warn(message, exception); } else { logger.warn(message); } } @Override public void onGiveup(Exception firstException, Exception lastException) throws RetryGiveupException { } }); } catch (RetryGiveupException ex) { throw Throwables.propagate(ex.getCause()); } catch (InterruptedException ex) { throw Throwables.propagate(ex); } }</code><technical_language>Minor (optional): multiple resources in try (...): java try (FileObject remoteFile = newSftpFile(getSftpFileUri(remotePath)); BufferedOutputStream outputStream = new BufferedOutputStream(remoteFile.getContent().getOutputStream()); BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(localTempFile)) ) { logger.info("new sftp file: {}", remoteFile.getPublicURIString()); IOUtils.copy(inputStream, outputStream); } ensure resources closed properly :)</technical_language>

Target:
public Void uploadFile(final File localTempFile, final String remotePath) { try { return retryExecutor() .withRetryLimit(maxConnectionRetry) .withInitialRetryWait(500) .withMaxRetryWait(30 * 1000) .runInterruptible(new Retryable<Void>() { @Override public Void call() throws IOException { try (FileObject remoteFile = newSftpFile(getSftpFileUri(remotePath)); BufferedOutputStream outputStream = new BufferedOutputStream(remoteFile.getContent().getOutputStream()); BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(localTempFile)) ) { logger.info("new sftp file: {}", remoteFile.getPublicURIString()); IOUtils.copy(inputStream, outputStream); } return null; } @Override public boolean isRetryableException(Exception exception) { return true; } @Override public void onRetry(Exception exception, int retryCount, int retryLimit, int retryWait) throws RetryGiveupException { String message = String.format("SFTP output failed. Retrying %d/%d after %d seconds. Message: %s", retryCount, retryLimit, retryWait / 1000, exception.getMessage()); if (retryCount % 3 == 0) { logger.warn(message, exception); } else { logger.warn(message); } } @Override public void onGiveup(Exception firstException, Exception lastException) throws RetryGiveupException { } }); } catch (RetryGiveupException ex) { throw Throwables.propagate(ex.getCause()); } catch (InterruptedException ex) { throw Throwables.propagate(ex); } }