FileContent is now ByteBuffer

This commit is contained in:
Andrea Cavalli 2021-01-11 14:40:31 +01:00
parent a9824bcef5
commit 3ab66a853a
5 changed files with 32 additions and 35 deletions

View File

@ -18,11 +18,11 @@
package org.warp.filesponge; package org.warp.filesponge;
import java.nio.ByteBuffer;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.warp.filesponge.api.FileAccessor; import org.warp.filesponge.api.FileAccessor;
import org.warp.filesponge.value.FileContent;
import org.warp.filesponge.value.FileStatus; import org.warp.filesponge.value.FileStatus;
import org.warp.filesponge.value.FileURI; import org.warp.filesponge.value.FileURI;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
@ -32,9 +32,9 @@ import reactor.core.publisher.Mono;
*/ */
@AllArgsConstructor @AllArgsConstructor
@EqualsAndHashCode @EqualsAndHashCode
public class SecureFileAccessor<FURI extends FileURI, FC extends FileContent> implements FileAccessor<FURI, FC> { public class SecureFileAccessor<FURI extends FileURI> implements FileAccessor<FURI> {
private final FileAccessor<FURI, FC> fileAccessor; private final FileAccessor<FURI> fileAccessor;
@Override @Override
public Mono<Void> delete(@NotNull FURI fileURI) { public Mono<Void> delete(@NotNull FURI fileURI) {
@ -42,7 +42,7 @@ public class SecureFileAccessor<FURI extends FileURI, FC extends FileContent> im
} }
@Override @Override
public Mono<FC> getContent(@NotNull FURI fileURI, boolean offlineOnly) { public Mono<ByteBuffer> getContent(@NotNull FURI fileURI, boolean offlineOnly) {
return fileAccessor.getContent(fileURI, offlineOnly); return fileAccessor.getContent(fileURI, offlineOnly);
} }

View File

@ -18,8 +18,8 @@
package org.warp.filesponge.api; package org.warp.filesponge.api;
import java.nio.ByteBuffer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.warp.filesponge.value.FileContent;
import org.warp.filesponge.value.FileStatus; import org.warp.filesponge.value.FileStatus;
import org.warp.filesponge.value.FileURI; import org.warp.filesponge.value.FileURI;
import reactor.core.publisher.Mono; 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 * FileAccessor can be used to access files from the client side
*/ */
public interface FileAccessor<FURI extends FileURI, FC extends FileContent> { public interface FileAccessor<FURI extends FileURI> {
/** /**
* Request file deletion * Request file deletion
@ -45,7 +45,7 @@ public interface FileAccessor<FURI extends FileURI, FC extends FileContent> {
* @return content if found. If the request is offline the future will complete instantly. * @return content if found. If the request is offline the future will complete instantly.
* Can be empty * Can be empty
*/ */
Mono<FC> getContent(@NotNull FURI fileURI, boolean offlineOnly); Mono<ByteBuffer> getContent(@NotNull FURI fileURI, boolean offlineOnly);
/** /**
* Get file status * Get file status

View File

@ -19,14 +19,13 @@
package org.warp.filesponge.api; package org.warp.filesponge.api;
import org.warp.filesponge.SecureFileAccessor; import org.warp.filesponge.SecureFileAccessor;
import org.warp.filesponge.value.FileContent;
import org.warp.filesponge.value.FileURI; import org.warp.filesponge.value.FileURI;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
/** /**
* FileAccessor can be used to manage FileSponge and access files from the client side * FileAccessor can be used to manage FileSponge and access files from the client side
*/ */
public interface FileSpongeClient<FURI extends FileURI, FC extends FileContent> extends FileAccessor<FURI, FC> { public interface FileSpongeClient<FURI extends FileURI> extends FileAccessor<FURI> {
Mono<Void> optimizeStorage(); Mono<Void> optimizeStorage();
@ -35,7 +34,7 @@ public interface FileSpongeClient<FURI extends FileURI, FC extends FileContent>
* *
* @return limited instance of itself * @return limited instance of itself
*/ */
default FileAccessor<FURI, FC> asFileAccessor() { default FileAccessor<FURI> asFileAccessor() {
return new SecureFileAccessor<>(this); return new SecureFileAccessor<>(this);
} }
} }

View File

@ -20,19 +20,38 @@ package org.warp.filesponge.api;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import org.jetbrains.annotations.NotNull; 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.FileType;
import org.warp.filesponge.value.FileURI; import org.warp.filesponge.value.FileURI;
import org.warp.filesponge.value.MirrorURI; import org.warp.filesponge.value.MirrorURI;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
public interface FileStorage<FURI extends FileURI, FTYPE extends FileType, MURI extends MirrorURI, FC extends FileContent> { public interface FileStorage<FURI extends FileURI, FTYPE extends FileType, MURI extends MirrorURI> {
Mono<Void> newFile(@NotNull FURI fileURI, @NotNull FTYPE fileType); Mono<Void> newFile(@NotNull FURI fileURI, @NotNull FTYPE fileType);
Mono<FC> readFileData(@NotNull FURI fileURI); Mono<ByteBuffer> readFileData(@NotNull FURI fileURI);
Mono<Void> 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<Void> setFileData(@NotNull FURI fileURI, long offset, long size, @Nullable ByteBuffer bytes, long totalSize);
Mono<Boolean> hasAllData(@NotNull FURI fileURI); Mono<Boolean> hasAllData(@NotNull FURI fileURI);
/**
* Delete a file
* @param fileURI
* @return
*/
default Mono<Void> deleteFile(@NotNull FURI fileURI) {
return setFileData(fileURI, 0, 0, null, 0);
}
} }

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
package org.warp.filesponge.value;
public interface FileContent {}