use of org.lastaflute.di.exception.IORuntimeException in project fess by codelibs.
the class AdminLogAction method getLogFileItems.
public static List<Map<String, Object>> getLogFileItems() {
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final List<Map<String, Object>> logFileItems = new ArrayList<>();
final String logFilePath = systemHelper.getLogFilePath();
if (StringUtil.isNotBlank(logFilePath)) {
final Path logDirPath = Paths.get(logFilePath);
try (Stream<Path> stream = Files.list(logDirPath)) {
stream.filter(entry -> entry.getFileName().toString().endsWith(".log")).forEach(filePath -> {
final Map<String, Object> map = new HashMap<>();
final String name = filePath.getFileName().toString();
map.put("id", Base64.getUrlEncoder().encodeToString(name.getBytes(StandardCharsets.UTF_8)));
map.put("name", name);
try {
map.put("lastModified", new Date(Files.getLastModifiedTime(filePath).toMillis()));
} catch (final IOException e) {
throw new IORuntimeException(e);
}
logFileItems.add(map);
});
} catch (final Exception e) {
throw new FessSystemException("Failed to access log files.", e);
}
}
return logFileItems;
}
Aggregations