SRV.java

  1package de.measite.minidns.record;
  2
  3import java.io.DataInputStream;
  4import java.io.IOException;
  5
  6import de.measite.minidns.Record.TYPE;
  7import de.measite.minidns.util.NameUtil;
  8
  9/**
 10 * SRV record payload (service pointer).
 11 */
 12public class SRV implements Data {
 13
 14    /**
 15     * The priority of this service.
 16     */
 17    protected int priority;
 18
 19    /**
 20     * The weight of this service.
 21     */
 22    protected int weight;
 23
 24    /**
 25     * The target port.
 26     */
 27    protected int port;
 28
 29    /**
 30     * The target server.
 31     */
 32    protected String name;
 33
 34    /**
 35     * The priority of this service. Lower values mean higher priority.
 36     * @return The priority.
 37     */
 38    public int getPriority() {
 39        return priority;
 40    }
 41
 42    /**
 43     * Set the priority of this service entry. Lower values have higher priority.
 44     * @param priority The new priority.
 45     */
 46    public void setPriority(int priority) {
 47        this.priority = priority;
 48    }
 49
 50    /**
 51     * The weight of this service. Services with the same priority should be
 52     * balanced based on weight.
 53     * @return The weight of this service.
 54     */
 55    public int getWeight() {
 56        return weight;
 57    }
 58
 59    /**
 60     * Set the weight of this service.
 61     * @param weight The new weight of this service.
 62     */
 63    public void setWeight(int weight) {
 64        this.weight = weight;
 65    }
 66
 67    /**
 68     * The target port of this service.
 69     * @return The target port of this service.
 70     */
 71    public int getPort() {
 72        return port;
 73    }
 74
 75    /**
 76     * Set the target port of this service.
 77     * @param port The new target port.
 78     */
 79    public void setPort(int port) {
 80        this.port = port;
 81    }
 82
 83    /**
 84     * The name of the target server.
 85     * @return The target servers name.
 86     */
 87    public String getName() {
 88        return name;
 89    }
 90
 91    /**
 92     * Set the name of the target server.
 93     * @param name The new target servers name. 
 94     */
 95    public void setName(String name) {
 96        this.name = name;
 97    }
 98
 99    @Override
100    public byte[] toByteArray() {
101        throw new UnsupportedOperationException("Not implemented yet");
102    }
103
104    @Override
105    public void parse(DataInputStream dis, byte[] data, int length)
106        throws IOException
107    {
108        this.priority = dis.readUnsignedShort();
109        this.weight = dis.readUnsignedShort();
110        this.port = dis.readUnsignedShort();
111        this.name = NameUtil.parse(dis, data);
112    }
113
114    @Override
115    public String toString() {
116        return "SRV " + name + ":" + port + " p:" + priority + " w:" + weight;
117    }
118
119    @Override
120    public TYPE getType() {
121        return TYPE.SRV;
122    }
123
124}