1 // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2
3 package org.xbill.DNS;
4
5 import java.io.*;
6
7 /**
8 * ISDN - identifies the ISDN number and subaddress associated with a name.
9 *
10 * @author Brian Wellington
11 */
12
13 public class ISDNRecord extends Record {
14
15 private static final long serialVersionUID = -8730801385178968798L;
16
17 private byte [] address;
18 private byte [] subAddress;
19
ISDNRecord()20 ISDNRecord() {}
21
22 Record
getObject()23 getObject() {
24 return new ISDNRecord();
25 }
26
27 /**
28 * Creates an ISDN Record from the given data
29 * @param address The ISDN number associated with the domain.
30 * @param subAddress The subaddress, if any.
31 * @throws IllegalArgumentException One of the strings is invalid.
32 */
33 public
ISDNRecord(Name name, int dclass, long ttl, String address, String subAddress)34 ISDNRecord(Name name, int dclass, long ttl, String address, String subAddress) {
35 super(name, Type.ISDN, dclass, ttl);
36 try {
37 this.address = byteArrayFromString(address);
38 if (subAddress != null)
39 this.subAddress = byteArrayFromString(subAddress);
40 }
41 catch (TextParseException e) {
42 throw new IllegalArgumentException(e.getMessage());
43 }
44 }
45
46 void
rrFromWire(DNSInput in)47 rrFromWire(DNSInput in) throws IOException {
48 address = in.readCountedString();
49 if (in.remaining() > 0)
50 subAddress = in.readCountedString();
51 }
52
53 void
rdataFromString(Tokenizer st, Name origin)54 rdataFromString(Tokenizer st, Name origin) throws IOException {
55 try {
56 address = byteArrayFromString(st.getString());
57 Tokenizer.Token t = st.get();
58 if (t.isString()) {
59 subAddress = byteArrayFromString(t.value);
60 } else {
61 st.unget();
62 }
63 }
64 catch (TextParseException e) {
65 throw st.exception(e.getMessage());
66 }
67 }
68
69 /**
70 * Returns the ISDN number associated with the domain.
71 */
72 public String
getAddress()73 getAddress() {
74 return byteArrayToString(address, false);
75 }
76
77 /**
78 * Returns the ISDN subaddress, or null if there is none.
79 */
80 public String
getSubAddress()81 getSubAddress() {
82 if (subAddress == null)
83 return null;
84 return byteArrayToString(subAddress, false);
85 }
86
87 void
rrToWire(DNSOutput out, Compression c, boolean canonical)88 rrToWire(DNSOutput out, Compression c, boolean canonical) {
89 out.writeCountedString(address);
90 if (subAddress != null)
91 out.writeCountedString(subAddress);
92 }
93
94 String
rrToString()95 rrToString() {
96 StringBuffer sb = new StringBuffer();
97 sb.append(byteArrayToString(address, true));
98 if (subAddress != null) {
99 sb.append(" ");
100 sb.append(byteArrayToString(subAddress, true));
101 }
102 return sb.toString();
103 }
104
105 }
106