blob: 1349a1e767496b35e6c822c47974833ce1ff6382 [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 * X25 - identifies the PSDN (Public Switched Data Network) address in the
9 * X.121 numbering plan associated with a name.
10 *
11 * @author Brian Wellington
12 */
13
14public class X25Record extends Record {
15
16private static final long serialVersionUID = 4267576252335579764L;
17
18private byte [] address;
19
20X25Record() {}
21
22Record
23getObject() {
24 return new X25Record();
25}
26
27private static final byte []
28checkAndConvertAddress(String address) {
29 int length = address.length();
30 byte [] out = new byte [length];
31 for (int i = 0; i < length; i++) {
32 char c = address.charAt(i);
33 if (!Character.isDigit(c))
34 return null;
35 out[i] = (byte) c;
36 }
37 return out;
38}
39
40/**
41 * Creates an X25 Record from the given data
42 * @param address The X.25 PSDN address.
43 * @throws IllegalArgumentException The address is not a valid PSDN address.
44 */
45public
46X25Record(Name name, int dclass, long ttl, String address) {
47 super(name, Type.X25, dclass, ttl);
48 this.address = checkAndConvertAddress(address);
49 if (this.address == null) {
50 throw new IllegalArgumentException("invalid PSDN address " +
51 address);
52 }
53}
54
55void
56rrFromWire(DNSInput in) throws IOException {
57 address = in.readCountedString();
58}
59
60void
61rdataFromString(Tokenizer st, Name origin) throws IOException {
62 String addr = st.getString();
63 this.address = checkAndConvertAddress(addr);
64 if (this.address == null)
65 throw st.exception("invalid PSDN address " + addr);
66}
67
68/**
69 * Returns the X.25 PSDN address.
70 */
71public String
72getAddress() {
73 return byteArrayToString(address, false);
74}
75
76void
77rrToWire(DNSOutput out, Compression c, boolean canonical) {
78 out.writeCountedString(address);
79}
80
81String
82rrToString() {
83 return byteArrayToString(address, true);
84}
85
86}