Initial implementations
This commit is contained in:
@@ -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 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user