Create FileSpongeClient
This commit is contained in:
parent
bf62a12ef0
commit
720f35e333
55
src/main/lombok/org/warp/filesponge/SecureFileAccessor.java
Normal file
55
src/main/lombok/org/warp/filesponge/SecureFileAccessor.java
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* FileSponge
|
||||||
|
* Copyright (C) 2020 Andrea Cavalli
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.warp.filesponge;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.warp.filesponge.api.FileAccessor;
|
||||||
|
import org.warp.filesponge.api.FileContent;
|
||||||
|
import org.warp.filesponge.api.FileStatus;
|
||||||
|
import org.warp.filesponge.api.FileURI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prevent access to other methods via casting
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode
|
||||||
|
@ToString
|
||||||
|
public class SecureFileAccessor implements FileAccessor {
|
||||||
|
|
||||||
|
private final FileAccessor fileAccessor;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(@NotNull FileURI fileURI) {
|
||||||
|
fileAccessor.delete(fileURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<FileContent> getContent(@NotNull FileURI fileURI, boolean offlineOnly) {
|
||||||
|
return fileAccessor.getContent(fileURI, offlineOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull FileStatus getStatus(@NotNull FileURI fileURI) {
|
||||||
|
return fileAccessor.getStatus(fileURI);
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,9 @@ package org.warp.filesponge.api;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FileAccessor can be used to access files from the client side
|
||||||
|
*/
|
||||||
public interface FileAccessor {
|
public interface FileAccessor {
|
||||||
|
|
||||||
void delete(@NotNull FileURI fileURI);
|
void delete(@NotNull FileURI fileURI);
|
||||||
|
@ -18,4 +18,60 @@
|
|||||||
|
|
||||||
package org.warp.filesponge.api;
|
package org.warp.filesponge.api;
|
||||||
|
|
||||||
public interface FileActor {}
|
import java.time.Duration;
|
||||||
|
import java.util.Optional;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FileActor sends signals to a mirror
|
||||||
|
*/
|
||||||
|
public interface FileActor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a "delete file" signal
|
||||||
|
*
|
||||||
|
* @param fileURI File URI
|
||||||
|
* @return true if the signal can be sent
|
||||||
|
*/
|
||||||
|
boolean deleteFile(FileURI fileURI);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a "download file" signal
|
||||||
|
*
|
||||||
|
* @param fileURI File URI
|
||||||
|
* @return true if the signal can be sent
|
||||||
|
*/
|
||||||
|
boolean downloadFile(FileURI fileURI);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this actor can handle signals for this file
|
||||||
|
*
|
||||||
|
* @param fileURI File URI
|
||||||
|
* @return true if the actor can send signals related to this file
|
||||||
|
*/
|
||||||
|
boolean canHandleFile(FileURI fileURI);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a "download file" signal
|
||||||
|
*
|
||||||
|
* @param fileURI File URI
|
||||||
|
* @param timeout if it's null the method will return immediately,
|
||||||
|
* if it's set the method will wait until a file <b>download request</b> has been found,
|
||||||
|
* or the timeout time elapsed
|
||||||
|
* @return empty if no pending <b>download requests</b> has been found,
|
||||||
|
* true if the signal can be sent, false otherwise
|
||||||
|
*/
|
||||||
|
Optional<Boolean> downloadNextFile(FileURI fileURI, @Nullable Duration timeout);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a "delete file" signal
|
||||||
|
*
|
||||||
|
* @param fileURI File URI
|
||||||
|
* @param timeout if it's null the method will return immediately,
|
||||||
|
* if it's set the method will wait until a file <b>delete request</b> has been found,
|
||||||
|
* or the timeout time elapsed
|
||||||
|
* @return empty if no pending <b>delete requests</b> has been found,
|
||||||
|
* true if the signal can be sent, false otherwise
|
||||||
|
*/
|
||||||
|
Optional<Boolean> deleteNextFile(FileURI fileURI, @Nullable Duration timeout);
|
||||||
|
}
|
||||||
|
@ -21,6 +21,9 @@ package org.warp.filesponge.api;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FileSource receives requests from a mirror
|
||||||
|
*/
|
||||||
public interface FileSource {
|
public interface FileSource {
|
||||||
|
|
||||||
void onAvailable();
|
void onAvailable();
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* FileSponge
|
||||||
|
* Copyright (C) 2020 Andrea Cavalli
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.warp.filesponge.api;
|
||||||
|
|
||||||
|
import org.warp.filesponge.SecureFileAccessor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FileAccessor can be used to manage FileSponge and access files from the client side
|
||||||
|
*/
|
||||||
|
public interface FileSpongeClient extends FileAccessor {
|
||||||
|
|
||||||
|
void optimizeStorage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get this instance but without special methods
|
||||||
|
* @return a limited instance of itself
|
||||||
|
*/
|
||||||
|
default FileAccessor asFileAccessor() {
|
||||||
|
return new SecureFileAccessor(this);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user