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 2016/06/01 13:30:54 UTC
[2/2] camel git commit: CAMEL-10007: camel-tarfile -
TarAggregationStrategy should ignore zero byte files. Also close resources so
works better on windows.
CAMEL-10007: camel-tarfile - TarAggregationStrategy should ignore zero byte files. Also close resources so works better on windows.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f8974498
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f8974498
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f8974498
Branch: refs/heads/master
Commit: f897449856584f64c1ce19cfb38e130ffc1edb4a
Parents: 6d1d3aa
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jun 1 15:30:43 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jun 1 15:30:43 2016 +0200
----------------------------------------------------------------------
.../tarfile/TarAggregationStrategy.java | 36 ++++++++++++--------
1 file changed, 22 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f8974498/components/camel-tarfile/src/main/java/org/apache/camel/processor/aggregate/tarfile/TarAggregationStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-tarfile/src/main/java/org/apache/camel/processor/aggregate/tarfile/TarAggregationStrategy.java b/components/camel-tarfile/src/main/java/org/apache/camel/processor/aggregate/tarfile/TarAggregationStrategy.java
index e70bec4..c11be84 100644
--- a/components/camel-tarfile/src/main/java/org/apache/camel/processor/aggregate/tarfile/TarAggregationStrategy.java
+++ b/components/camel-tarfile/src/main/java/org/apache/camel/processor/aggregate/tarfile/TarAggregationStrategy.java
@@ -21,8 +21,10 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.Charset;
import org.apache.camel.Exchange;
+import org.apache.camel.WrappedFile;
import org.apache.camel.component.file.FileConsumer;
import org.apache.camel.component.file.GenericFile;
import org.apache.camel.component.file.GenericFileMessage;
@@ -151,18 +153,21 @@ public class TarAggregationStrategy implements AggregationStrategy {
tarFile = oldExchange.getIn().getBody(File.class);
}
- // Handle GenericFileMessages
- if (GenericFileMessage.class.isAssignableFrom(newExchange.getIn().getClass())) {
+ Object body = newExchange.getIn().getBody();
+ if (body instanceof WrappedFile) {
+ body = ((WrappedFile) body).getFile();
+ }
+
+ if (body instanceof File) {
try {
- File appendFile = newExchange.getIn().getMandatoryBody(File.class);
- if (appendFile != null) {
- addFileToTar(tarFile, appendFile, this.preserveFolderStructure ? newExchange.getIn().toString() : null);
+ File appendFile = (File) body;
+ // do not try to append empty files
+ if (appendFile.length() > 0) {
+ String entryName = preserveFolderStructure ? newExchange.getIn().getHeader(Exchange.FILE_NAME, String.class) : newExchange.getIn().getMessageId();
+ addFileToTar(tarFile, appendFile, this.preserveFolderStructure ? entryName : null);
GenericFile<File> genericFile =
FileConsumer.asGenericFile(
- tarFile.getParent(),
- tarFile,
- null, // Do not set charset here, that will cause the tar file to be handled as ASCII later which breaks it..
- false);
+ tarFile.getParent(), tarFile, Charset.defaultCharset().toString(), false);
genericFile.bindToExchange(answer);
}
} catch (Exception e) {
@@ -172,15 +177,18 @@ public class TarAggregationStrategy implements AggregationStrategy {
// Handle all other messages
try {
byte[] buffer = newExchange.getIn().getMandatoryBody(byte[].class);
- String entryName = useFilenameHeader ? newExchange.getIn().getHeader(Exchange.FILE_NAME, String.class) : newExchange.getIn().getMessageId();
- addEntryToTar(tarFile, entryName, buffer, buffer.length);
- GenericFile<File> genericFile = FileConsumer.asGenericFile(tarFile.getParent(), tarFile, null, false);
- genericFile.bindToExchange(answer);
+ // do not try to append empty data
+ if (buffer.length > 0) {
+ String entryName = useFilenameHeader ? newExchange.getIn().getHeader(Exchange.FILE_NAME, String.class) : newExchange.getIn().getMessageId();
+ addEntryToTar(tarFile, entryName, buffer, buffer.length);
+ GenericFile<File> genericFile = FileConsumer.asGenericFile(
+ tarFile.getParent(), tarFile, Charset.defaultCharset().toString(), false);
+ genericFile.bindToExchange(answer);
+ }
} catch (Exception e) {
throw new GenericFileOperationFailedException(e.getMessage(), e);
}
}
-
return answer;
}