1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.model.message.header;
17
18 import org.fourthline.cling.model.Constants;
19 import org.fourthline.cling.model.types.HostPort;
20
21
22
23
24 public class HostHeader extends UpnpHeader<HostPort> {
25
26 int port = Constants.UPNP_MULTICAST_PORT;
27 String group = Constants.IPV4_UPNP_MULTICAST_GROUP;
28
29 public HostHeader() {
30 setValue(new HostPort(group, port));
31 }
32
33 public HostHeader(int port) {
34 setValue(new HostPort(group, port));
35 }
36
37 public HostHeader(String host, int port) {
38 setValue(new HostPort(host, port));
39 }
40
41 public void setString(String s) throws InvalidHeaderException {
42
43 if (s.contains(":")) {
44
45 try {
46 this.port = Integer.valueOf(s.substring(s.indexOf(":")+1));
47 this.group = s.substring(0, s.indexOf(":"));
48 setValue(new HostPort(group, port));
49 } catch (NumberFormatException ex) {
50 throw new InvalidHeaderException("Invalid HOST header value, can't parse port: " + s + " - " + ex.getMessage());
51 }
52 } else {
53 this.group = s;
54 setValue(new HostPort(group, port));
55 }
56 }
57
58 public String getString() {
59 return getValue().toString();
60 }
61 }