You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2018/08/10 07:48:19 UTC
[camel] branch camel-2.21.x updated: CAMEL-12724: camel-ftp -
SftpOperations should set byte[] instead of OutputStream for exchange file
body (#2463)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-2.21.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.21.x by this push:
new 72c158a CAMEL-12724: camel-ftp - SftpOperations should set byte[] instead of OutputStream for exchange file body (#2463)
72c158a is described below
commit 72c158aaf7ab4f8f79b54f75547cf8d7342e2eaf
Author: Tadayoshi Sato <sa...@gmail.com>
AuthorDate: Fri Aug 10 09:31:55 2018 +0200
CAMEL-12724: camel-ftp - SftpOperations should set byte[] instead of OutputStream for exchange file body (#2463)
---
.../camel/component/file/remote/SftpOperations.java | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
index e6178a9..4f9e2c2 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
@@ -686,7 +686,6 @@ public class SftpOperations implements RemoteFileOperations<SftpRemoteFile> {
@SuppressWarnings("unchecked")
private boolean retrieveFileToStreamInBody(String name, Exchange exchange) throws GenericFileOperationFailedException {
- OutputStream os = null;
String currentDir = null;
try {
GenericFile<ChannelSftp.LsEntry> target =
@@ -715,18 +714,19 @@ public class SftpOperations implements RemoteFileOperations<SftpRemoteFile> {
target.setBody(is);
exchange.getIn().setHeader(RemoteFileComponent.REMOTE_FILE_INPUT_STREAM, is);
} else {
- os = new ByteArrayOutputStream();
- target.setBody(os);
- IOHelper.copyAndCloseInput(is, os);
+ // read the entire file into memory in the byte array
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ IOHelper.copyAndCloseInput(is, bos);
+ // close the stream after done
+ IOHelper.close(bos);
+
+ target.setBody(bos.toByteArray());
}
return true;
- } catch (IOException e) {
- throw new GenericFileOperationFailedException("Cannot retrieve file: " + name, e);
- } catch (SftpException e) {
+ } catch (IOException | SftpException e) {
throw new GenericFileOperationFailedException("Cannot retrieve file: " + name, e);
} finally {
- IOHelper.close(os, "retrieve: " + name, LOG);
// change back to current directory if we changed directory
if (currentDir != null) {
changeCurrentDirectory(currentDir);