From cc35d8a5ea0490328b543c1af8b40c43f17a9224 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 11:55:24 +0900 Subject: [PATCH] Impl WIP --- .../source/file/impl/FileManagerImpl.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index a4e91fd7..0a8561dd 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -7,6 +7,7 @@ import org.w3c.dom.Document; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.nio.file.DirectoryIteratorException; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; @@ -28,13 +29,90 @@ import one.nem.lacerta.utils.LacertaLogger; public class FileManagerImpl implements FileManager { + // variables + private Path rootDir; + private Path path; + + // Injection private LacertaLogger logger; @AssistedInject public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) { this.logger = logger; + this.rootDir = rootDir; + } + + // Internal + private Path resolveStringPath(String path) throws IOException{ + String[] pathArray = path.split("/"); + Path resolvedPath = this.rootDir; + for (String pathPart : pathArray) { + if (pathPart.equals("..")) { + resolvedPath = resolvedPath.getParent(); + continue; + } + + try { + resolvedPath = resolvedPath.resolve(pathPart); + } catch (Exception e) { + throw new IOException("Invalid path: " + path); + return null; + } + } + logger.debug("resolveStringPath", "resolvedPath: " + resolvedPath); + return resolvedPath; } + @Override + public File getFileRef() { + return null; + } + + @Override + public boolean isExist() { + return false; + } + + @Override + public boolean isDirectory() { + return false; + } + + @Override + public boolean isFile() { + return false; + } + + @Override + public boolean isWritable() { + return false; + } + + @Override + public boolean isReadable() { + return false; + } + + @Override + public Document readXml() { + return null; + } + + @Override + public FileManager setRootDir(Path rootDir) { + this.rootDir = rootDir; + return this; + } + + @Override + public FileManager setPath(Path path) { + return null; + } + + @Override + public FileManager setPath(String path) { + return null; + } }