[
https://issues.apache.org/jira/browse/JENA-979?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14605402#comment-14605402
]
ASF GitHub Bot commented on JENA-979:
-------------------------------------
Github user ajs6f commented on a diff in the pull request:
https://github.com/apache/jena/pull/82#discussion_r33451617
--- Diff:
jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionBackupList.java
---
@@ -0,0 +1,98 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.fuseki.mgt;
+
+import org.apache.jena.atlas.json.JsonBuilder;
+import org.apache.jena.fuseki.Fuseki;
+import org.apache.jena.fuseki.server.FusekiServer;
+import org.apache.jena.fuseki.servlets.ServletOps;
+import org.apache.jena.web.HttpSC;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collections;
+
+import static org.apache.jena.riot.WebContent.charsetUTF8;
+import static org.apache.jena.riot.WebContent.contentTypeTextPlain;
+
+/**
+ * A JSON API to list all the backups in the backup directory
+ * Created by Yang Yuanzhe on 6/26/15.
+ */
+public class ActionBackupList extends HttpServlet {
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
{
+ doCommon(req, resp);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse
resp) {
+ doCommon(req, resp);
+ }
+
+ @Override
+ protected void doHead(HttpServletRequest req, HttpServletResponse
resp) {
+ doCommon(req, resp);
+ }
+
+ protected void doCommon(HttpServletRequest request,
HttpServletResponse response) {
+ JsonBuilder builder = new JsonBuilder() ;
+ builder.startObject("top") ;
+ builder.key("backups") ;
+ builder.startArray() ;
+
+ ArrayList<String> fileNames = new ArrayList<>();
+ if (Files.isDirectory(FusekiServer.dirBackups)) {
+ try (DirectoryStream<Path> stream =
Files.newDirectoryStream(FusekiServer.dirBackups)) {
+ for (Path path : stream) {
+ fileNames.add(path.getFileName().toString());
+ }
+ } catch (IOException ex) {
+ Fuseki.serverLog.warn("backup file list :: IOException ::
"+ex.getMessage());
+ }
+ }
+
+ Collections.sort(fileNames);
+ for (String str : fileNames) {
+ builder.value(str);
+ }
--- End diff --
Given Java 8, this is a little briefer as
`fileNames.forEach(builder::value)`.
> add a fuseki admin service to list all existing backups
> -------------------------------------------------------
>
> Key: JENA-979
> URL: https://issues.apache.org/jira/browse/JENA-979
> Project: Apache Jena
> Issue Type: New Feature
> Components: Fuseki
> Affects Versions: Fuseki 2.0.0, Fuseki 2.0.1, Fuseki 2.3.0
> Reporter: Yang Yuanzhe
> Priority: Minor
>
> Add a fuseki admin service to list all existing backups.
> Service URL: $/backupList
> Response example:
> {
> "backups" : [
> "ds_2015-06-08_04-23-02.nq.gz" ,
> "ds_2015-06-08_07-57-10.nq.gz" ,
> "ds_2015-06-08_07-57-48.nq.gz" ,
> "ds_2015-06-09_03-46-37.nq.gz" ,
> "ds_2015-06-17_12-20-31.nq" ,
> "ds_2015-06-17_12-20-31.nq.gz" ,
> "ds_2015-06-23_10-53-47.nq.gz"
> ]
> }
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)