Package org.xbill.DNS

Class Record

java.lang.Object
org.xbill.DNS.Record
All Implemented Interfaces:
Serializable, Cloneable, Comparable<Record>
Direct Known Subclasses:
A6Record, AAAARecord, APLRecord, ARecord, CAARecord, CERTRecord, DHCIDRecord, DLVRecord, DSRecord, EmptyRecord, GPOSRecord, HINFORecord, HIPRecord, IPSECKEYRecord, ISDNRecord, KEYBase, LOCRecord, MINFORecord, NAPTRRecord, NSAPRecord, NSEC3PARAMRecord, NSEC3Record, NSECRecord, NULLRecord, NXTRecord, OPENPGPKEYRecord, OPTRecord, PXRecord, RPRecord, SIGBase, SingleNameBase, SOARecord, SRVRecord, SSHFPRecord, SVCBBase, TKEYRecord, TLSARecord, TSIGRecord, TXTBase, U16NameBase, UNKRecord, URIRecord, WKSRecord, X25Record, ZoneMDRecord

public abstract class Record extends Object implements Cloneable, Comparable<Record>, Serializable
A generic DNS resource record. The specific record types extend this class. A record contains a name, type, class, ttl, and rdata.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final DecimalFormat
     
    protected int
     
    protected Name
     
    protected long
     
    protected int
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
    protected
    Record(Name name, int type, int dclass, long ttl)
    Initialize the basic fields of a record.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static byte[]
    Converts a String into a byte array.
    protected static String
    byteArrayToString(byte[] array, boolean quote)
    Converts a byte array into a String.
    (package private) static byte[]
    checkByteArrayLength(String field, byte[] array, int maxLength)
     
    (package private) static Name
    checkName(String field, Name name)
     
    (package private) static int
    checkU16(String field, int val)
     
    (package private) static long
    checkU32(String field, long val)
     
    (package private) static int
    checkU8(String field, int val)
     
    (package private) Record
     
    int
    Compares this Record to another Object.
    boolean
    Determines if two Records are identical.
    static Record
    fromString(Name name, int type, int dclass, long ttl, String s, Name origin)
    Builds a new Record from its textual representation
    static Record
    fromString(Name name, int type, int dclass, long ttl, Tokenizer st, Name origin)
    Builds a new Record from its textual representation
    static Record
    fromWire(byte[] b, int section)
    Builds a Record from DNS uncompressed wire format.
    (package private) static Record
    fromWire(DNSInput in, int section)
     
    (package private) static Record
    fromWire(DNSInput in, int section, boolean isUpdate)
     
    Returns the name for which additional data processing should be done for this record.
    int
    Returns the record's class
    private static Record
    getEmptyRecord(Name name, int type, int dclass, long ttl, boolean hasData)
     
    Returns the record's name
    int
    Returns the type of RRset that this record would belong to.
    long
    Returns the record's TTL
    int
    Returns the record's type
    int
    Generates a hash code based on the Record's data.
    static Record
    newRecord(Name name, int type, int dclass)
    Creates a new empty record, with the given parameters.
    static Record
    newRecord(Name name, int type, int dclass, long ttl)
    Creates a new empty record, with the given parameters.
    static Record
    newRecord(Name name, int type, int dclass, long ttl, byte[] data)
    Creates a new record, with the given parameters.
    static Record
    newRecord(Name name, int type, int dclass, long ttl, int length, byte[] data)
    Creates a new record, with the given parameters.
    private static Record
    newRecord(Name name, int type, int dclass, long ttl, int length, DNSInput in)
     
    protected abstract void
    Converts the text format of an RR to the internal format - must be overriden
    Converts the rdata portion of a Record into a String representation
    byte[]
    Converts the rdata in a Record into canonical DNS uncompressed wire format (all names are converted to lowercase).
    private void
     
    protected abstract void
    Converts the type-specific RR to wire format - must be overridden
    protected abstract String
    Converts the type-specific RR to text format - must be overridden.
    protected abstract void
    rrToWire(DNSOutput out, Compression c, boolean canonical)
    Converts the type-specific RR to wire format - must be overridden.
    boolean
    Determines if two Records could be part of the same RRset.
    boolean
    Determines if this Record could be part of the passed RRset.
    (package private) void
    setTTL(long ttl)
     
    Converts a Record into a String representation
    byte[]
    toWire(int section)
    Converts a Record into DNS uncompressed wire format.
    (package private) void
    toWire(DNSOutput out, int section, Compression c)
     
    byte[]
    Converts a Record into canonical DNS uncompressed wire format (all names are converted to lowercase).
    private byte[]
    toWireCanonical(boolean noTTL)
     
    private void
    toWireCanonical(DNSOutput out, boolean noTTL)
     
    protected static String
    unknownToString(byte[] data)
    Converts a byte array into the unknown RR format.
    (package private) Record
    withDClass(int dclass, long ttl)
    Creates a new record identical to the current record, but with a different class and ttl.
    withName(Name name)
    Creates a new record identical to the current record, but with a different name.
    (package private) Object
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • name

      protected Name name
    • type

      protected int type
    • dclass

      protected int dclass
    • ttl

      protected long ttl
    • byteFormat

      private static final DecimalFormat byteFormat
  • Constructor Details

    • Record

      protected Record()
    • Record

      protected Record(Name name, int type, int dclass, long ttl)
      Initialize the basic fields of a record.
      Since:
      3.1
  • Method Details

    • writeReplace

      Object writeReplace()
    • readObject

      private void readObject(ObjectInputStream ois) throws InvalidObjectException
      Throws:
      InvalidObjectException
    • getEmptyRecord

      private static Record getEmptyRecord(Name name, int type, int dclass, long ttl, boolean hasData)
    • rrFromWire

      protected abstract void rrFromWire(DNSInput in) throws IOException
      Converts the type-specific RR to wire format - must be overridden
      Throws:
      IOException
      Since:
      3.1
    • newRecord

      private static Record newRecord(Name name, int type, int dclass, long ttl, int length, DNSInput in) throws IOException
      Throws:
      IOException
    • newRecord

      public static Record newRecord(Name name, int type, int dclass, long ttl, int length, byte[] data)
      Creates a new record, with the given parameters.
      Parameters:
      name - The owner name of the record.
      type - The record's type.
      dclass - The record's class.
      ttl - The record's time to live.
      length - The length of the record's data.
      data - The rdata of the record, in uncompressed DNS wire format. Only the first length bytes are used.
    • newRecord

      public static Record newRecord(Name name, int type, int dclass, long ttl, byte[] data)
      Creates a new record, with the given parameters.
      Parameters:
      name - The owner name of the record.
      type - The record's type.
      dclass - The record's class.
      ttl - The record's time to live.
      data - The complete rdata of the record, in uncompressed DNS wire format.
    • newRecord

      public static Record newRecord(Name name, int type, int dclass, long ttl)
      Creates a new empty record, with the given parameters.
      Parameters:
      name - The owner name of the record.
      type - The record's type.
      dclass - The record's class.
      ttl - The record's time to live.
      Returns:
      An object of a subclass of Record
    • newRecord

      public static Record newRecord(Name name, int type, int dclass)
      Creates a new empty record, with the given parameters. This method is designed to create records that will be added to the QUERY section of a message.
      Parameters:
      name - The owner name of the record.
      type - The record's type.
      dclass - The record's class.
      Returns:
      An object of a subclass of Record
    • fromWire

      static Record fromWire(DNSInput in, int section, boolean isUpdate) throws IOException
      Throws:
      IOException
    • fromWire

      static Record fromWire(DNSInput in, int section) throws IOException
      Throws:
      IOException
    • fromWire

      public static Record fromWire(byte[] b, int section) throws IOException
      Builds a Record from DNS uncompressed wire format.
      Throws:
      IOException
    • toWire

      void toWire(DNSOutput out, int section, Compression c)
    • toWire

      public byte[] toWire(int section)
      Converts a Record into DNS uncompressed wire format.
    • toWireCanonical

      private void toWireCanonical(DNSOutput out, boolean noTTL)
    • toWireCanonical

      private byte[] toWireCanonical(boolean noTTL)
    • toWireCanonical

      public byte[] toWireCanonical()
      Converts a Record into canonical DNS uncompressed wire format (all names are converted to lowercase).
    • rdataToWireCanonical

      public byte[] rdataToWireCanonical()
      Converts the rdata in a Record into canonical DNS uncompressed wire format (all names are converted to lowercase).
    • rrToString

      protected abstract String rrToString()
      Converts the type-specific RR to text format - must be overridden.
      Since:
      3.1
    • rdataToString

      public String rdataToString()
      Converts the rdata portion of a Record into a String representation
    • toString

      public String toString()
      Converts a Record into a String representation
      Overrides:
      toString in class Object
    • rdataFromString

      protected abstract void rdataFromString(Tokenizer st, Name origin) throws IOException
      Converts the text format of an RR to the internal format - must be overriden
      Throws:
      IOException
      Since:
      3.1
    • byteArrayFromString

      protected static byte[] byteArrayFromString(String s) throws TextParseException
      Converts a String into a byte array.
      Throws:
      TextParseException
    • byteArrayToString

      protected static String byteArrayToString(byte[] array, boolean quote)
      Converts a byte array into a String.
    • unknownToString

      protected static String unknownToString(byte[] data)
      Converts a byte array into the unknown RR format.
    • fromString

      public static Record fromString(Name name, int type, int dclass, long ttl, Tokenizer st, Name origin) throws IOException
      Builds a new Record from its textual representation
      Parameters:
      name - The owner name of the record.
      type - The record's type.
      dclass - The record's class.
      ttl - The record's time to live.
      st - A tokenizer containing the textual representation of the rdata.
      origin - The default origin to be appended to relative domain names.
      Returns:
      The new record
      Throws:
      IOException - The text format was invalid.
    • fromString

      public static Record fromString(Name name, int type, int dclass, long ttl, String s, Name origin) throws IOException
      Builds a new Record from its textual representation
      Parameters:
      name - The owner name of the record.
      type - The record's type.
      dclass - The record's class.
      ttl - The record's time to live.
      s - The textual representation of the rdata.
      origin - The default origin to be appended to relative domain names.
      Returns:
      The new record
      Throws:
      IOException - The text format was invalid.
    • getName

      public Name getName()
      Returns the record's name
      See Also:
    • getType

      public int getType()
      Returns the record's type
      See Also:
    • getRRsetType

      public int getRRsetType()
      Returns the type of RRset that this record would belong to. For all types except SIG/RRSIG, this is equivalent to getType().
      Returns:
      The type of record
      See Also:
    • getDClass

      public int getDClass()
      Returns the record's class
    • getTTL

      public long getTTL()
      Returns the record's TTL
    • rrToWire

      protected abstract void rrToWire(DNSOutput out, Compression c, boolean canonical)
      Converts the type-specific RR to wire format - must be overridden.
      Since:
      3.1
    • sameRRset

      public boolean sameRRset(Record rec)
      Determines if two Records could be part of the same RRset. This compares the name, type, and class of the Records; the ttl and rdata are not compared.
    • sameRRset

      public boolean sameRRset(RRset set)
      Determines if this Record could be part of the passed RRset. This compares the name, type, and class of the Record and the set.
      Since:
      3.6
    • equals

      public boolean equals(Object arg)
      Determines if two Records are identical. This compares the name, type, class, and rdata (with names canonicalized). The TTLs are not compared.
      Overrides:
      equals in class Object
      Parameters:
      arg - The record to compare to
      Returns:
      true if the records are equal, false otherwise.
    • hashCode

      public int hashCode()
      Generates a hash code based on the Record's data.
      Overrides:
      hashCode in class Object
    • cloneRecord

      Record cloneRecord()
    • withName

      public Record withName(Name name)
      Creates a new record identical to the current record, but with a different name. This is most useful for replacing the name of a wildcard record.
    • withDClass

      Record withDClass(int dclass, long ttl)
      Creates a new record identical to the current record, but with a different class and ttl. This is most useful for dynamic update.
    • setTTL

      void setTTL(long ttl)
    • compareTo

      public int compareTo(Record arg)
      Compares this Record to another Object.
      Specified by:
      compareTo in interface Comparable<Record>
      Parameters:
      arg - The Object to be compared.
      Returns:
      The value 0 if the argument is a record equivalent to this record; a value less than 0 if the argument is less than this record in the canonical ordering, and a value greater than 0 if the argument is greater than this record in the canonical ordering. The canonical ordering is defined to compare by name, class, type, and rdata.
      Throws:
      ClassCastException - if the argument is not a Record.
    • getAdditionalName

      public Name getAdditionalName()
      Returns the name for which additional data processing should be done for this record. This can be used both for building responses and parsing responses.
      Returns:
      The name to used for additional data processing, or null if this record type does not require additional data processing.
    • checkU8

      static int checkU8(String field, int val)
    • checkU16

      static int checkU16(String field, int val)
    • checkU32

      static long checkU32(String field, long val)
    • checkName

      static Name checkName(String field, Name name)
    • checkByteArrayLength

      static byte[] checkByteArrayLength(String field, byte[] array, int maxLength)