예제 #1
0
  /**
   * Builds a new Record from its textual representation
   *
   * @param name The owner name of the record.
   * @param type The record's type.
   * @param dclass The record's class.
   * @param ttl The record's time to live.
   * @param st A tokenizer containing the textual representation of the rdata.
   * @param origin The default origin to be appended to relative domain names.
   * @return The new record
   * @throws IOException The text format was invalid.
   */
  public static Record fromString(
      Name name, int type, int dclass, long ttl, Tokenizer st, Name origin) throws IOException {
    Record rec;

    if (!name.isAbsolute()) throw new RelativeNameException(name);
    Type.check(type);
    DClass.check(dclass);
    TTL.check(ttl);

    Tokenizer.Token t = st.get();
    if (t.type == Tokenizer.IDENTIFIER && t.value.equals("\\#")) {
      int length = st.getUInt16();
      byte[] data = st.getHex();
      if (data == null) {
        data = new byte[0];
      }
      if (length != data.length)
        throw st.exception("invalid unknown RR encoding: " + "length mismatch");
      DNSInput in = new DNSInput(data);
      return newRecord(name, type, dclass, ttl, length, in);
    }
    st.unget();
    rec = getEmptyRecord(name, type, dclass, ttl, true);
    rec.rdataFromString(st, origin);
    t = st.get();
    if (t.type != Tokenizer.EOL && t.type != Tokenizer.EOF) {
      throw st.exception("unexpected tokens at end of record");
    }
    return rec;
  }
예제 #2
0
파일: LOCRecord.java 프로젝트: uppaljs/sef
 private long parseDouble(
     Tokenizer st, String type, boolean required, long min, long max, long defaultValue)
     throws IOException {
   Tokenizer.Token token = st.get();
   if (token.isEOL()) {
     if (required) throw st.exception("Invalid LOC " + type);
     st.unget();
     return defaultValue;
   }
   String s = token.value;
   if (s.length() > 1 && s.charAt(s.length() - 1) == 'm') s = s.substring(0, s.length() - 1);
   try {
     long value = (long) (100 * parseFixedPoint(s));
     if (value < min || value > max) throw st.exception("Invalid LOC " + type);
     return value;
   } catch (NumberFormatException e) {
     throw st.exception("Invalid LOC " + type);
   }
 }