-
Notifications
You must be signed in to change notification settings - Fork 2
/
WebSearchService.java
46 lines (43 loc) · 1.62 KB
/
WebSearchService.java
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
import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Vector;
/**
* Created by IntelliJ IDEA.
* User: basti
* Date: 04.03.12
* Time: 19:47
* this retrieves file information from the web file indexer
*/
class WebSearchService {
public Vector<FileInformation> Search4Files(String webServiceURL, String fileNamePart) {
Vector<FileInformation> ret = new Vector<FileInformation>();
try {
URL updateURL = new URL(webServiceURL + fileNamePart);
if (webServiceURL == null || webServiceURL.length() == 0) {
new URL("http://localhost:82/json/syncreply/FileInformations?SearchPattern=" + fileNamePart);
}
Gson gson = new Gson();
JsonReader reader = new JsonReader(new InputStreamReader(updateURL.openStream()));
reader.beginObject(); // {
reader.nextName(); // Responsestatus
reader.beginObject(); // {
reader.nextName(); // Errors
reader.skipValue(); // usually [
reader.endObject(); // {
reader.nextName(); // Files
reader.beginArray();
while (reader.hasNext()) {
FileInformation fi = gson.fromJson(reader, FileInformation.class);
ret.add(fi);
}
reader.endArray();
reader.close();
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
return ret;
}
}