mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-08 16:56:07 +00:00
rework loaders to allow traversing filenames
This commit is contained in:
@@ -31,7 +31,7 @@ public class FolderLoader extends Loader {
|
||||
try(Stream<Path> paths = Files.walk(newPath.toPath())) {
|
||||
paths.filter(Files::isRegularFile).filter(file -> file.toString().toLowerCase().endsWith(".yml")).forEach(file -> {
|
||||
try {
|
||||
streams.add(new FileInputStream(file.toFile()));
|
||||
streams.put(newPath.toURI().relativize(file.toUri()).getPath(), new FileInputStream(file.toFile()));
|
||||
} catch(FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package com.dfsek.terra.config.files;
|
||||
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.terra.api.util.GlueList;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class Loader {
|
||||
protected final List<InputStream> streams = new ArrayList<>();
|
||||
protected final Map<String, InputStream> streams = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Do something with the InputStreams.
|
||||
@@ -16,7 +19,12 @@ public abstract class Loader {
|
||||
* @param consumer Something to do with the streams.
|
||||
*/
|
||||
public Loader then(ExceptionalConsumer<List<InputStream>> consumer) throws ConfigException {
|
||||
consumer.accept(streams);
|
||||
consumer.accept(new GlueList<>(streams.values()));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Loader thenNames(Consumer<List<String>> consumer) throws ConfigException {
|
||||
consumer.accept(new GlueList<>(streams.keySet()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -45,7 +53,7 @@ public abstract class Loader {
|
||||
* Close all InputStreams opened.
|
||||
*/
|
||||
public Loader close() {
|
||||
streams.forEach(input -> {
|
||||
streams.forEach((name, input) -> {
|
||||
try {
|
||||
input.close();
|
||||
} catch(IOException e) {
|
||||
|
||||
@@ -30,7 +30,7 @@ public class ZIPLoader extends Loader {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
if(!entry.isDirectory() && entry.getName().startsWith(directory) && entry.getName().endsWith(".yml")) {
|
||||
try {
|
||||
streams.add(file.getInputStream(entry));
|
||||
streams.put(entry.getName(), file.getInputStream(entry));
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user