Search in sources :

Example 1 with IORuntimeException

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;
}
Also used : Path(java.nio.file.Path) Files(java.nio.file.Files) FessSystemException(org.codelibs.fess.exception.FessSystemException) Date(java.util.Date) StringUtil(org.codelibs.core.lang.StringUtil) IOException(java.io.IOException) HashMap(java.util.HashMap) IORuntimeException(org.lastaflute.di.exception.IORuntimeException) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) StandardCharsets(java.nio.charset.StandardCharsets) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) ArrayList(java.util.ArrayList) ActionResponse(org.lastaflute.web.response.ActionResponse) Base64(java.util.Base64) List(java.util.List) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) SystemHelper(org.codelibs.fess.helper.SystemHelper) Map(java.util.Map) Execute(org.lastaflute.web.Execute) HtmlResponse(org.lastaflute.web.response.HtmlResponse) Path(java.nio.file.Path) InputStream(java.io.InputStream) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Date(java.util.Date) FessSystemException(org.codelibs.fess.exception.FessSystemException) IOException(java.io.IOException) IORuntimeException(org.lastaflute.di.exception.IORuntimeException) FessSystemException(org.codelibs.fess.exception.FessSystemException) SystemHelper(org.codelibs.fess.helper.SystemHelper) IORuntimeException(org.lastaflute.di.exception.IORuntimeException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Base64 (java.util.Base64)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Stream (java.util.stream.Stream)1 StringUtil (org.codelibs.core.lang.StringUtil)1 FessAdminAction (org.codelibs.fess.app.web.base.FessAdminAction)1 FessSystemException (org.codelibs.fess.exception.FessSystemException)1 SystemHelper (org.codelibs.fess.helper.SystemHelper)1 ComponentUtil (org.codelibs.fess.util.ComponentUtil)1 RenderDataUtil (org.codelibs.fess.util.RenderDataUtil)1 IORuntimeException (org.lastaflute.di.exception.IORuntimeException)1