1 package org.simantics.utils;
4 import java.io.IOException;
7 * @author Tuukka Lehtonen
9 public interface FileService {
11 public static interface DeleteOption {}
13 public static class EffortOption implements DeleteOption {
14 public final int maxTries;
16 private EffortOption(int maxTries) {
17 this.maxTries = maxTries;
20 public static EffortOption maxTries(int maxTries) {
21 return new EffortOption(maxTries);
26 public static interface FileOperation {
27 IOperation<Boolean, IOException> perform(File file);
29 default void perform(File... files) {
35 public static class DeleteOperation implements FileOperation {
36 private final FileService service;
37 private final DeleteOption[] options;
39 public DeleteOperation(FileService service, DeleteOption... options) {
40 this.service = service;
41 this.options = options;
45 public IOperation<Boolean, IOException> perform(File file) {
46 return service.scheduleDeleteIfExists(file, options);
51 * Schedules a file to be deleted at some point in the future when the
52 * system allows it to be deleted if ever.
55 * @return an operation handle for tracking the progress of the deletion or
56 * <code>null</code> if there's a deletion operation scheduled for
57 * the provided file in the queue or the file does not exist.
59 IOperation<Boolean, IOException> scheduleDeleteIfExists(File file, DeleteOption... options);
63 * the deletion options to be used by the returned FileOperation
64 * @return a FileOperation that runs
65 * {@link #scheduleDeleteIfExists(File, DeleteOption...)} for any
69 default FileOperation deleteOperation(DeleteOption... options) {
70 return new DeleteOperation(this, options);