use of org.lanternpowered.api.asset.Asset in project LanternServer by LanternPowered.
the class DirectoryAssetRepository method getAssetsMap.
@Override
public Multimap<String, Asset> getAssetsMap(String path, boolean checkChildDirectories) {
final ImmutableMultimap.Builder<String, Asset> builder = ImmutableMultimap.builder();
final Pattern pattern = Pattern.compile(generateRegex(path));
final int length = this.directory.toString().length() + 1;
try {
Files.walkFileTree(this.directory, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
final String file0 = file.toString().substring(length).replace('\\', '/');
final Matcher matcher = pattern.matcher(file0);
if (matcher.matches()) {
final String id = matcher.group(2).toLowerCase(Locale.ENGLISH);
final int index = id.indexOf('/');
if (index == -1 || (checkChildDirectories && index != id.lastIndexOf('/'))) {
return FileVisitResult.CONTINUE;
}
final String plugin = matcher.group(1).toLowerCase(Locale.ENGLISH);
builder.put(id.substring(0, index), registerAsset(plugin, plugin + ':' + id, file));
}
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
return builder.build();
}
use of org.lanternpowered.api.asset.Asset in project LanternServer by LanternPowered.
the class DirectoryAssetRepository method getAssets.
@Override
public Collection<Asset> getAssets(String path, boolean checkChildDirectories) {
final ImmutableList.Builder<Asset> builder = ImmutableList.builder();
final Pattern pattern = Pattern.compile(generateRegex(path));
final int length = this.directory.toString().length() + 1;
try {
Files.walkFileTree(this.directory, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
final String file0 = file.toString().substring(length).replace('\\', '/');
final Matcher matcher = pattern.matcher(file0);
if (matcher.matches()) {
final String id = matcher.group(2).toLowerCase(Locale.ENGLISH);
int index;
if (!checkChildDirectories && (index = id.indexOf('/')) != -1 && id.lastIndexOf('/') != index) {
return FileVisitResult.CONTINUE;
}
final String plugin = matcher.group(1).toLowerCase(Locale.ENGLISH);
builder.add(registerAsset(plugin, plugin + ':' + id, file));
}
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
return builder.build();
}
Aggregations