Initial implementations

This commit is contained in:
2023-12-20 13:12:52 +00:00
parent 9489e6048c
commit f9ab02c68d
6 changed files with 117 additions and 5 deletions

View File

@@ -1,9 +1,13 @@
package filesystem
import java.nio.file.FileAlreadyExistsException
import java.nio.file.FileSystemException
import java.nio.file.Files
import java.nio.file.Path
class FSCreator {
// Create entry, leaving existing folders' contents, but overwriting existing files.
@Throws(FileSystemException::class)
fun create(entryToCreate: FSEntry, destination: String) {
val queue = ArrayDeque<Pair<FSEntry, Path>>()
queue.add(entryToCreate to Path.of(destination))
@@ -17,8 +21,9 @@ class FSCreator {
is FSFolder -> Files.createDirectory(path)
}
} catch (_: FileAlreadyExistsException) {} // Allow files/folders to already exist.
if (entry is FSFolder) {
queue.addAll(entry.entries.map { it to path })
when (entry) {
is FSFile -> Files.write(path, entry.content.toByteArray())
is FSFolder -> queue.addAll(entry.entries.map { it to path })
}
}
}