Add getFilePath() to AsyncFileWriter Interface

This commit is contained in:
Alva Swanson 2024-02-07 14:53:16 +01:00
parent 6707af5f7c
commit f483badd2e
No known key found for this signature in database
GPG Key ID: 004760E77F753090
3 changed files with 12 additions and 2 deletions

View File

@ -20,13 +20,19 @@ package bisq.persistence;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousFileChannel;
import java.nio.channels.CompletionHandler;
import java.nio.file.Path;
import java.util.concurrent.CompletableFuture;
import lombok.Getter;
public class AsyncFileChannelWriter implements AsyncFileWriter {
@Getter
private final Path filePath;
private final AsynchronousFileChannel fileChannel;
public AsyncFileChannelWriter(AsynchronousFileChannel fileChannel) {
public AsyncFileChannelWriter(Path filePath, AsynchronousFileChannel fileChannel) {
this.filePath = filePath;
this.fileChannel = fileChannel;
}

View File

@ -17,8 +17,12 @@
package bisq.persistence;
import java.nio.file.Path;
import java.util.concurrent.CompletableFuture;
public interface AsyncFileWriter {
CompletableFuture<Integer> write(byte[] data, int offset);
Path getFilePath();
}

View File

@ -47,7 +47,7 @@ public class AsyncFileChannelWriterTests {
void setup(@TempDir Path tempDir) throws IOException {
filePath = tempDir.resolve("file");
fileChannel = AsynchronousFileChannel.open(filePath, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
asyncFileChannelWriter = new AsyncFileChannelWriter(fileChannel);
asyncFileChannelWriter = new AsyncFileChannelWriter(filePath, fileChannel);
}
@Test