Asynchronous file download

This commit is contained in:
Andrea Cavalli 2020-09-24 11:44:52 +02:00
parent 720f35e333
commit b5105bf083
2 changed files with 18 additions and 2 deletions

View File

@ -19,6 +19,7 @@
package org.warp.filesponge.api; package org.warp.filesponge.api;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/** /**
@ -26,9 +27,24 @@ import org.jetbrains.annotations.NotNull;
*/ */
public interface FileAccessor { public interface FileAccessor {
/**
* Request file deletion
* @param fileURI File URI
*/
void delete(@NotNull FileURI fileURI); void delete(@NotNull FileURI fileURI);
Optional<FileContent> getContent(@NotNull FileURI fileURI, boolean offlineOnly); /**
* Get file content
* @param fileURI File URI
* @param offlineOnly true to get the file from cache
* @return content if found. If the request is offline the future will complete instantly
*/
CompletableFuture<Optional<FileContent>> getContent(@NotNull FileURI fileURI, boolean offlineOnly);
/**
* Get file status
* @param fileURI File URI
* @return status of this file
*/
@NotNull FileStatus getStatus(@NotNull FileURI fileURI); @NotNull FileStatus getStatus(@NotNull FileURI fileURI);
} }

View File

@ -29,7 +29,7 @@ public interface FileSpongeClient extends FileAccessor {
/** /**
* Get this instance but without special methods * Get this instance but without special methods
* @return a limited instance of itself * @return limited instance of itself
*/ */
default FileAccessor asFileAccessor() { default FileAccessor asFileAccessor() {
return new SecureFileAccessor(this); return new SecureFileAccessor(this);