Repository: commons-compress Updated Branches: refs/heads/master 82f9bfcb9 -> 30a595d0d
COMPRESS-118 add projection operation Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/30a595d0 Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/30a595d0 Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/30a595d0 Branch: refs/heads/master Commit: 30a595d0d7b97a60e9703cb73214248b643c60ba Parents: 82f9bfc Author: Stefan Bodewig <bode...@apache.org> Authored: Sun Apr 29 19:36:26 2018 +0200 Committer: Stefan Bodewig <bode...@apache.org> Committed: Sun Apr 29 19:36:26 2018 +0200 ---------------------------------------------------------------------- .../compress/archivers/examples/Archive.java | 8 ++++ .../archivers/examples/Transformer.java | 41 ++++++++++++++++++++ 2 files changed, 49 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/30a595d0/src/main/java/org/apache/commons/compress/archivers/examples/Archive.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/archivers/examples/Archive.java b/src/main/java/org/apache/commons/compress/archivers/examples/Archive.java index c451170..d360314 100644 --- a/src/main/java/org/apache/commons/compress/archivers/examples/Archive.java +++ b/src/main/java/org/apache/commons/compress/archivers/examples/Archive.java @@ -50,6 +50,10 @@ public class Archive { */ ChainBuilder skipNonFiles(); /** + * Adds a transformer to the chain. + */ + ChainBuilder map(Transformer transformer); + /** * Actually consumes all the files supplied. */ void to(Sink<File> sink) throws IOException, ArchiveException; @@ -100,6 +104,10 @@ public class Archive { } }); } + public ChainBuilder map(Transformer transformer) { + chainDef.add(transformer); + return this; + } public void to(Sink<File> sink) throws IOException, ArchiveException { chainDef.add(sink); chainDef.freeze(); http://git-wip-us.apache.org/repos/asf/commons-compress/blob/30a595d0/src/main/java/org/apache/commons/compress/archivers/examples/Transformer.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/archivers/examples/Transformer.java b/src/main/java/org/apache/commons/compress/archivers/examples/Transformer.java new file mode 100644 index 0000000..b091678 --- /dev/null +++ b/src/main/java/org/apache/commons/compress/archivers/examples/Transformer.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.commons.compress.archivers.examples; + +import java.io.IOException; +import org.apache.commons.compress.archivers.ArchiveException; + +/** + * Transforming stage of a {@link Expand} or {@link Archive} chain. + * @since 1.17 + */ +public abstract class Transformer<T> implements ChainStep<T> { + /** + * Transforms an entry. + * + * @param entry the entry + * @return the transformed entry + */ + public abstract ChainPayload<T> transform(ChainPayload<T> entry); + + @Override + public void process(ChainPayload<T> payload, Chain<T> chain) throws IOException, ArchiveException { + chain.next(transform(payload)); + } +}