Search in sources :

Example 11 with CurlResponse

use of org.codelibs.elasticsearch.runner.net.CurlResponse in project fess by codelibs.

the class GitBucketDataStoreImpl method crawlFileContents.

protected void crawlFileContents(final String rootURL, final String authToken, final String owner, final String name, final String refStr, final String path, final int depth, final long readInterval, final Consumer<String> consumer) {
    if (MAX_DEPTH <= depth) {
        return;
    }
    final String url = encode(rootURL, "api/v3/repos/" + owner + "/" + name + "/contents/" + path, "ref=" + refStr);
    try (CurlResponse curlResponse = Curl.get(url).header("Authorization", "token " + authToken).execute()) {
        final InputStream iStream = curlResponse.getContentAsStream();
        final List<Object> fileList = parseList(iStream);
        for (int i = 0; i < fileList.size(); ++i) {
            @SuppressWarnings("unchecked") final Map<String, String> file = (Map<String, String>) fileList.get(i);
            final String newPath = path.isEmpty() ? file.get("name") : path + "/" + file.get("name");
            switch(file.get("type")) {
                case "file":
                    consumer.accept(newPath);
                    break;
                case "dir":
                    if (readInterval > 0) {
                        sleep(readInterval);
                    }
                    crawlFileContents(rootURL, authToken, owner, name, refStr, newPath, depth + 1, readInterval, consumer);
                    break;
            }
        }
    } catch (final Exception e) {
        logger.warn("Failed to access to " + url, e);
    }
}
Also used : CurlResponse(org.codelibs.elasticsearch.runner.net.CurlResponse) InputStream(java.io.InputStream) HashMap(java.util.HashMap) Map(java.util.Map) URISyntaxException(java.net.URISyntaxException)

Aggregations

CurlResponse (org.codelibs.elasticsearch.runner.net.CurlResponse)11 HashMap (java.util.HashMap)7 Map (java.util.Map)7 URISyntaxException (java.net.URISyntaxException)6 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Curl (org.codelibs.elasticsearch.runner.net.Curl)4 ResourceUtil (org.codelibs.fess.util.ResourceUtil)4 IOException (java.io.IOException)3 CsvConfig (com.orangesignal.csv.CsvConfig)2 CsvWriter (com.orangesignal.csv.CsvWriter)2 BufferedWriter (java.io.BufferedWriter)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Consumer (java.util.function.Consumer)2 CopyUtil (org.codelibs.core.io.CopyUtil)2 StringUtil (org.codelibs.core.lang.StringUtil)2