diff --git a/src/main/lombok/org/warp/filesponge/SecureFileAccessor.java b/src/main/lombok/org/warp/filesponge/SecureFileAccessor.java index ce7e9eb..8c61337 100644 --- a/src/main/lombok/org/warp/filesponge/SecureFileAccessor.java +++ b/src/main/lombok/org/warp/filesponge/SecureFileAccessor.java @@ -18,11 +18,11 @@ package org.warp.filesponge; +import java.nio.ByteBuffer; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import org.jetbrains.annotations.NotNull; import org.warp.filesponge.api.FileAccessor; -import org.warp.filesponge.value.FileContent; import org.warp.filesponge.value.FileStatus; import org.warp.filesponge.value.FileURI; import reactor.core.publisher.Mono; @@ -32,9 +32,9 @@ import reactor.core.publisher.Mono; */ @AllArgsConstructor @EqualsAndHashCode -public class SecureFileAccessor implements FileAccessor { +public class SecureFileAccessor implements FileAccessor { - private final FileAccessor fileAccessor; + private final FileAccessor fileAccessor; @Override public Mono delete(@NotNull FURI fileURI) { @@ -42,7 +42,7 @@ public class SecureFileAccessor im } @Override - public Mono getContent(@NotNull FURI fileURI, boolean offlineOnly) { + public Mono getContent(@NotNull FURI fileURI, boolean offlineOnly) { return fileAccessor.getContent(fileURI, offlineOnly); } diff --git a/src/main/lombok/org/warp/filesponge/api/FileAccessor.java b/src/main/lombok/org/warp/filesponge/api/FileAccessor.java index 12cbbfe..d2a4b82 100644 --- a/src/main/lombok/org/warp/filesponge/api/FileAccessor.java +++ b/src/main/lombok/org/warp/filesponge/api/FileAccessor.java @@ -18,8 +18,8 @@ package org.warp.filesponge.api; +import java.nio.ByteBuffer; import org.jetbrains.annotations.NotNull; -import org.warp.filesponge.value.FileContent; import org.warp.filesponge.value.FileStatus; import org.warp.filesponge.value.FileURI; import reactor.core.publisher.Mono; @@ -27,7 +27,7 @@ import reactor.core.publisher.Mono; /** * FileAccessor can be used to access files from the client side */ -public interface FileAccessor { +public interface FileAccessor { /** * Request file deletion @@ -45,7 +45,7 @@ public interface FileAccessor { * @return content if found. If the request is offline the future will complete instantly. * Can be empty */ - Mono getContent(@NotNull FURI fileURI, boolean offlineOnly); + Mono getContent(@NotNull FURI fileURI, boolean offlineOnly); /** * Get file status diff --git a/src/main/lombok/org/warp/filesponge/api/FileSpongeClient.java b/src/main/lombok/org/warp/filesponge/api/FileSpongeClient.java index 5c08562..a2d0a53 100644 --- a/src/main/lombok/org/warp/filesponge/api/FileSpongeClient.java +++ b/src/main/lombok/org/warp/filesponge/api/FileSpongeClient.java @@ -19,14 +19,13 @@ package org.warp.filesponge.api; import org.warp.filesponge.SecureFileAccessor; -import org.warp.filesponge.value.FileContent; import org.warp.filesponge.value.FileURI; import reactor.core.publisher.Mono; /** * FileAccessor can be used to manage FileSponge and access files from the client side */ -public interface FileSpongeClient extends FileAccessor { +public interface FileSpongeClient extends FileAccessor { Mono optimizeStorage(); @@ -35,7 +34,7 @@ public interface FileSpongeClient * * @return limited instance of itself */ - default FileAccessor asFileAccessor() { + default FileAccessor asFileAccessor() { return new SecureFileAccessor<>(this); } } diff --git a/src/main/lombok/org/warp/filesponge/api/FileStorage.java b/src/main/lombok/org/warp/filesponge/api/FileStorage.java index e63da88..c09bac0 100644 --- a/src/main/lombok/org/warp/filesponge/api/FileStorage.java +++ b/src/main/lombok/org/warp/filesponge/api/FileStorage.java @@ -20,19 +20,38 @@ package org.warp.filesponge.api; import java.nio.ByteBuffer; import org.jetbrains.annotations.NotNull; -import org.warp.filesponge.value.FileContent; +import org.jetbrains.annotations.Nullable; import org.warp.filesponge.value.FileType; import org.warp.filesponge.value.FileURI; import org.warp.filesponge.value.MirrorURI; import reactor.core.publisher.Mono; -public interface FileStorage { +public interface FileStorage { Mono newFile(@NotNull FURI fileURI, @NotNull FTYPE fileType); - Mono readFileData(@NotNull FURI fileURI); + Mono readFileData(@NotNull FURI fileURI); - Mono setFileData(@NotNull FURI fileURI, long offset, long size, ByteBuffer bytes, long totalSize); + /** + * Set a part of file data. + * If file size is 0, the file will be deleted. + * @param fileURI File URI + * @param offset offset of the current data segment + * @param size current data segment size + * @param bytes data segment, can be null if totalSize is 0 + * @param totalSize total file size + * @return nothing + */ + Mono setFileData(@NotNull FURI fileURI, long offset, long size, @Nullable ByteBuffer bytes, long totalSize); Mono hasAllData(@NotNull FURI fileURI); + + /** + * Delete a file + * @param fileURI + * @return + */ + default Mono deleteFile(@NotNull FURI fileURI) { + return setFileData(fileURI, 0, 0, null, 0); + } } diff --git a/src/main/lombok/org/warp/filesponge/value/FileContent.java b/src/main/lombok/org/warp/filesponge/value/FileContent.java deleted file mode 100644 index ca6d226..0000000 --- a/src/main/lombok/org/warp/filesponge/value/FileContent.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 . - */ - -package org.warp.filesponge.value; - -public interface FileContent {}