Skip to content

Commit

Permalink
Extract filters for protocol features used for specific file attribut…
Browse files Browse the repository at this point in the history
…es in file transfers.
  • Loading branch information
dkocher committed Nov 18, 2024
1 parent 3a7bdf6 commit 1feeacc
Show file tree
Hide file tree
Showing 26 changed files with 1,573 additions and 573 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package ch.cyberduck.core.transfer;

/*
* Copyright (c) 2002-2024 iterate GmbH. All rights reserved.
* https://cyberduck.io/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

import ch.cyberduck.core.Local;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.ProgressListener;
import ch.cyberduck.core.exception.BackgroundException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Optional;

public class ChainedFeatureFilter implements FeatureFilter {
private static final Logger log = LogManager.getLogger(ChainedFeatureFilter.class);

private final FeatureFilter[] filters;

public ChainedFeatureFilter(final FeatureFilter... filters) {
this.filters = filters;
}

@Override
public TransferStatus prepare(final Path file, final Optional<Local> local, final TransferStatus status, final ProgressListener progress) throws BackgroundException {
for(final FeatureFilter filter : filters) {
log.debug("Prepare {} with {}", file, filter);
filter.prepare(file, local, status, progress);
}
return status;
}

@Override
public void complete(final Path file, final Optional<Local> local, final TransferStatus status, final ProgressListener progress) throws BackgroundException {
for(final FeatureFilter filter : filters) {
log.debug("Complete {} with {}", file, filter);
filter.complete(file, local, status, progress);
}
}
}
46 changes: 46 additions & 0 deletions core/src/main/java/ch/cyberduck/core/transfer/FeatureFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package ch.cyberduck.core.transfer;

/*
* Copyright (c) 2002-2024 iterate GmbH. All rights reserved.
* https://cyberduck.io/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

import ch.cyberduck.core.Local;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.ProgressListener;
import ch.cyberduck.core.exception.BackgroundException;

import java.util.Optional;

public interface FeatureFilter {
default TransferStatus prepare(final Path file, final Optional<Local> local, final TransferStatus status, final ProgressListener progress) throws BackgroundException {
// No-op
return status;
}

default void apply(final Path file, final TransferStatus status, final ProgressListener progress) throws BackgroundException {
// No-op
}

default void complete(final Path file, final Optional<Local> local, final TransferStatus status, final ProgressListener progress) throws BackgroundException {
// No-op
}

FeatureFilter noop = new FeatureFilter() {
@Override
public TransferStatus prepare(final Path file, final Optional<Local> local, final TransferStatus status, final ProgressListener progress) {
// No-op
return status;
}
};
}
Loading

0 comments on commit 1feeacc

Please sign in to comment.