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