This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_list.groovy
executable file
·92 lines (78 loc) · 2.88 KB
/
server_list.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import static com.google.common.base.Preconditions.checkNotNull;
import org.apache.commons.io.FileUtils;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.file.Paths;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.jdkhttp.JdkHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;
import org.json.JSONException;
import org.json.JSONObject;
import com.google.common.io.Files;
public class Md5RoList {
private static final String QUEUE_DIR = System.getProperty("user.home") + "/sarnobat.git/db/md5ro/";
private static final String QUEUE_FILE_TXT_DELETE = QUEUE_DIR + "/md5_files.txt";
// This only gets invoked when it receives the first request
// Multiple instances get created
@Path("md5ro")
public static class YurlResource { // Must be public
@GET
@Path("uncategorized")
@Produces("application/json")
public Response getUrls(@QueryParam("rootId") Integer iRootId)
throws JSONException, IOException {
System.out.println("" + QUEUE_FILE_TXT_DELETE);
checkNotNull(iRootId);
try {
//JSONObject retVal1 = new JSONObject();
return Response.ok().header("Access-Control-Allow-Origin", "*")
.entity(FileUtils.readFileToString(Paths.get(QUEUE_FILE_TXT_DELETE).toFile(), "UTF-8")).type("text/plain")
.build();
} catch (Exception e) {
e.printStackTrace();
return Response.serverError()
.header("Access-Control-Allow-Origin", "*")
.entity(e.getStackTrace()).type("application/text")
.build();
}
}
}
public static void main(String[] args) throws URISyntaxException,
JSONException, IOException {
// Turn off that stupid Jersey logger.
// This works in Java but not in Groovy.
// java.util.Logger.getLogger("org.glassfish.jersey").setLevel(java.util.Level.SEVERE);
try {
List lines = Files
.readLines(Paths.get(QUEUE_FILE_TXT_DELETE).toFile(),
Charset.defaultCharset()).stream()
.filter(new Predicate<String> (){
public boolean test(String t) {
return t.contains("2016");
}})
.limit(6)
.collect(Collectors.toList());
System.out.println("Md5RoList.main() " + lines);
JdkHttpServerFactory.createHttpServer(new URI(
"http://localhost:4485/"), new ResourceConfig(
YurlResource.class));
// Do not allow this in multiple processes otherwise your hard disk
// will fill up
// or overload the database
// Problem - this won't get executed until the server ends
// YurlWorldResource.downloadUndownloadedVideosInSeparateThread() ;
} catch (Exception e) {
e.printStackTrace();
System.out.println("Not creating server instance");
}
}
}