MCPcopy Create free account
hub / github.com/faceless2/zeroconf / Packet

Method Packet

src/main/com/bfo/zeroconf/Packet.java:27–75  ·  view source on GitHub ↗

Create a Packet from its String representation @param tostring the packets string-format, in the same format as #toString @throws IllegalArgumentException if the format is incorrec5 @since 1.0.1

(String tostring)

Source from the content-addressed store, hash-verified

25 * @since 1.0.1
26 */
27 @SuppressWarnings("unchecked") public Packet(String tostring) {
28 Map<String,Object> map = (Map<String,Object>)Stringify.parse(tostring);
29 this.id = ((Integer)map.get("id")).intValue();
30 this.flags = ((Integer)map.get("flags")).intValue();
31 this.timestamp = ((Number)map.get("timestamp")).longValue();
32 NetworkInterface nic = null;
33 if (map.get("nic") instanceof String) {
34 try {
35 nic = NetworkInterface.getByName((String)map.get("nic"));
36 } catch (Exception e) { }
37 }
38 this.nic = nic;
39 if (map.get("questions") instanceof List) {
40 List<Record> l = new ArrayList<Record>();
41 for (Object o : (List<Object>)map.get("questions")) {
42 l.add(Record.parse((Map<String,Object>)o));
43 }
44 this.questions = Collections.<Record>unmodifiableList(l);
45 } else {
46 this.questions = Collections.<Record>emptyList();
47 }
48 if (map.get("answers") instanceof List) {
49 List<Record> l = new ArrayList<Record>();
50 for (Object o : (List<Object>)map.get("answers")) {
51 l.add(Record.parse((Map<String,Object>)o));
52 }
53 this.answers = Collections.<Record>unmodifiableList(l);
54 } else {
55 this.answers = Collections.<Record>emptyList();
56 }
57 if (map.get("additionals") instanceof List) {
58 List<Record> l = new ArrayList<Record>();
59 for (Object o : (List<Object>)map.get("additionals")) {
60 l.add(Record.parse((Map<String,Object>)o));
61 }
62 this.additionals = Collections.<Record>unmodifiableList(l);
63 } else {
64 this.additionals = Collections.<Record>emptyList();
65 }
66 if (map.get("authorities") instanceof List) {
67 List<Record> l = new ArrayList<Record>();
68 for (Object o : (List<Object>)map.get("authorities")) {
69 l.add(Record.parse((Map<String,Object>)o));
70 }
71 this.authorities = Collections.<Record>unmodifiableList(l);
72 } else {
73 this.authorities = Collections.<Record>emptyList();
74 }
75 }
76
77 private Packet(int id, int flags, NetworkInterface nic, List<Record> questions, List<Record> answers, List<Record> authorities, List<Record> additionals) {
78 this.timestamp = System.currentTimeMillis();

Callers

nothing calls this directly

Calls 15

parseMethod · 0.95
parseMethod · 0.95
newQuestionMethod · 0.95
newPtrMethod · 0.95
newSrvMethod · 0.95
newTxtMethod · 0.95
newAddressMethod · 0.95
readQuestionMethod · 0.95
readAnswerMethod · 0.95
dumpMethod · 0.95
addMethod · 0.80
getFQDNMethod · 0.80

Tested by

no test coverage detected