+ /**
+ * Convert a query line of the form: <qname> <qtype> <flags> to a request
+ * message.
+ *
+ * @param query_line
+ * @return A query message
+ * @throws TextParseException
+ * @throws NameTooLongException
+ */
+ private Message queryFromString(String query_line)
+ throws TextParseException, NameTooLongException {
+
+ String[] tokens = query_line.split("[ \t]+");
+
+ Name qname = null;
+ int qtype = -1;
+ int qclass = -1;
+
+ if (tokens.length < 1)
+ return null;
+ qname = Name.fromString(tokens[0]);
+ if (!qname.isAbsolute()) {
+ qname = Name.concatenate(qname, Name.root);
+ }
+
+ for (int i = 1; i < tokens.length; i++) {
+ if (tokens[i].startsWith("+")) {
+ // For now, we ignore flags as uninteresting
+ continue;
+ }
+
+ int type = Type.value(tokens[i]);
+ if (type > 0) {
+ qtype = type;
+ continue;
+ }
+ int cls = DClass.value(tokens[i]);
+ if (cls > 0) {
+ qclass = cls;
+ continue;
+ }
+ }
+ if (qtype < 0) {
+ qtype = Type.A;
+ }
+ if (qclass < 0) {
+ qclass = DClass.IN;
+ }
+
+ Message query = Message.newQuery(Record.newRecord(qname, qtype, qclass));