blob: 8f9b629cdb485b7c097ce81b3be8f8ea7675d4fd [file] [log] [blame]
Shuyi Chend7955ce2013-05-22 14:51:55 -07001// Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2
3package org.xbill.DNS;
4
5import java.io.*;
6
7/**
8 * ISDN - identifies the ISDN number and subaddress associated with a name.
9 *
10 * @author Brian Wellington
11 */
12
13public class ISDNRecord extends Record {
14
15private static final long serialVersionUID = -8730801385178968798L;
16
17private byte [] address;
18private byte [] subAddress;
19
20ISDNRecord() {}
21
22Record
23getObject() {
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 */
33public
34ISDNRecord(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
46void
47rrFromWire(DNSInput in) throws IOException {
48 address = in.readCountedString();
49 if (in.remaining() > 0)
50 subAddress = in.readCountedString();
51}
52
53void
54rdataFromString(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 */
72public String
73getAddress() {
74 return byteArrayToString(address, false);
75}
76
77/**
78 * Returns the ISDN subaddress, or null if there is none.
79 */
80public String
81getSubAddress() {
82 if (subAddress == null)
83 return null;
84 return byteArrayToString(subAddress, false);
85}
86
87void
88rrToWire(DNSOutput out, Compression c, boolean canonical) {
89 out.writeCountedString(address);
90 if (subAddress != null)
91 out.writeCountedString(subAddress);
92}
93
94String
95rrToString() {
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}