-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConnect.java
More file actions
74 lines (63 loc) · 2.2 KB
/
Connect.java
File metadata and controls
74 lines (63 loc) · 2.2 KB
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
package Code;
import android.util.JsonReader;
import android.util.JsonToken;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
/**
* Created by NikoBenick on 3/12/2016.
*/
public class Connect {
private InputStream json;
public ArrayList<yOject> yOject;
public Connect(InputStream json) throws IOException {
this.json = json;
readJsonStream(json);
}
public void readJsonStream(InputStream in) throws IOException {
long i = 0;
//JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
BufferedReader stdout = new BufferedReader(new InputStreamReader(in, "UTF-8"));
String line;
boolean done = false;
try {
while((line = stdout.readLine()) != null || !done){
if(line.indexOf("\"businesses\"") != -1){
readMessage(stdout);
done = true;
}
}
//return readMessagesArray(reader);
} finally {
stdout.close();
}
}
public void readMessage(BufferedReader stdout) throws IOException {
String id = null;
String address = "", lat = "", lon = "";
String line;
long i = 0;
while((line = stdout.readLine()) != null ){
if(line.indexOf("\"id\":") != -1){
if(id != null){
yOject.add(new yOject(i,id,address.trim(),lat+";"+lon));
i++;
}
id = line.replace("\"id\": ","");
id = id.trim();
}else if(line.indexOf("\"coordinate\"") != -1){
lat = stdout.readLine().replace("\"latitude\":","");
lat=lat.trim();
lon = stdout.readLine().replace("\"longitude\":", "");
lon=lon.trim();
}else if (line.indexOf("\"display_address\"") != -1){
address = stdout.readLine()+stdout.readLine();
}
}
}
public ArrayList<yOject> getyOject() {
return yOject;
}
}