-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathBaseStation.java
More file actions
88 lines (68 loc) · 2.2 KB
/
BaseStation.java
File metadata and controls
88 lines (68 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package net.ipip.ipdb;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class BaseStation {
/**
* @var Reader
*/
private Reader reader;
public BaseStation(String name) throws IOException,InvalidDatabaseException {
this.reader = new RandomAccessReader(name);
}
public BaseStation(InputStream in) throws IOException, InvalidDatabaseException {
this.reader = new Reader(in);
}
public boolean reload(String name) {
try {
Reader old = this.reader;
this.reader = new RandomAccessReader(name);
if (old instanceof Closeable) {
((Closeable) old).close();
}
} catch (Exception e) {
return false;
}
return true;
}
public String[] find(String addr, String language) throws IPFormatException, InvalidDatabaseException {
return this.reader.find(addr, language);
}
public Map<String, String> findMap(String addr, String language) throws IPFormatException, InvalidDatabaseException {
String[] data = this.reader.find(addr, language);
if (data == null) {
return null;
}
Map<String, String> m = new HashMap<String, String>();
String[] fields = this.reader.getSupportFields();
for (int i = 0, l = data.length; i < l; i++) {
m.put(fields[i], data[i]);
}
return m;
}
public BaseStationInfo findInfo(String addr, String language) throws IPFormatException, InvalidDatabaseException {
String[] data = this.reader.find(addr, language);
if (data == null) {
return null;
}
return new BaseStationInfo(data);
}
public boolean isIPv4() {
return this.reader.isIPv4();
}
public boolean isIPv6() {
return this.reader.isIPv6();
}
public String fields() {
return Arrays.toString(this.reader.getSupportFields());
}
public int buildTime() {
return this.reader.getBuildUTCTime();
}
public String languages() {
return this.reader.getSupportLanguages();
}
}