From 630e76198eee56ffdb664fc72ca903ef2bca14d8 Mon Sep 17 00:00:00 2001 From: Ilya Date: Fri, 16 Oct 2020 10:11:57 +0300 Subject: [PATCH] Start creating FileSystem class --- .../ru/redguy/tftpserver/IDataSource.java | 5 +++ .../tftpserver/datasource/FileSystem.java | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/main/java/ru/redguy/tftpserver/IDataSource.java create mode 100644 src/main/java/ru/redguy/tftpserver/datasource/FileSystem.java diff --git a/src/main/java/ru/redguy/tftpserver/IDataSource.java b/src/main/java/ru/redguy/tftpserver/IDataSource.java new file mode 100644 index 0000000..e711ac1 --- /dev/null +++ b/src/main/java/ru/redguy/tftpserver/IDataSource.java @@ -0,0 +1,5 @@ +package ru.redguy.tftpserver; + +public interface IDataSource { + public boolean isFileExists(String localPath); +} diff --git a/src/main/java/ru/redguy/tftpserver/datasource/FileSystem.java b/src/main/java/ru/redguy/tftpserver/datasource/FileSystem.java new file mode 100644 index 0000000..04d2d68 --- /dev/null +++ b/src/main/java/ru/redguy/tftpserver/datasource/FileSystem.java @@ -0,0 +1,31 @@ +package ru.redguy.tftpserver.datasource; + +import ru.redguy.tftpserver.IDataSource; + +import java.io.File; +import java.nio.file.Path; + +public class FileSystem implements IDataSource { + + String path; + + public FileSystem(File file) { + path = file.getAbsolutePath()+"/"; + } + + public FileSystem(Path path) { + this.path = path.toAbsolutePath().toString()+"/"; + } + + public FileSystem(String path) { + this.path = path; + if(!this.path.endsWith("/")) { + this.path = this.path+"/"; + } + } + + @Override + public boolean isFileExists(String localPath) { + return new File(this.path,localPath).exists(); + } +}