351 domain = dn.domain + (domain.equals(".") ? "" : ".") + domain;
352 } else {
353 domain = null;
354 }
355
356 } else if (n instanceof CompositeName) {
357 n = (DnsName) n; // force ClassCastException
358
359 } else { // "n" is a compound name, but not a DnsName.
360 // Add labels least-significant first: sometimes more efficient.
361 for (int i = n.size() - 1; i >= 0; i--) {
362 add(pos, n.get(i));
363 }
364 }
365 return this;
366 }
367
368
369 boolean hasRootLabel() {
370 return (!isEmpty() &&
371 get(0).equals(""));
372 }
373
374 /*
375 * Helper method for public comparison methods. Lexicographically
376 * compares components of this name in the range [beg,end) with
377 * all components of "n". Indexing is as for the Name interface,
378 * with 0 being the most significant. Returns negative, zero, or
379 * positive as these name components are less than, equal to, or
380 * greater than those of "n".
381 */
382 private int compareRange(int beg, int end, Name n) {
383 if (n instanceof CompositeName) {
384 n = (DnsName) n; // force ClassCastException
385 }
386 // Loop through labels, starting with most significant.
387 int minSize = Math.min(end - beg, n.size());
388 for (int i = 0; i < minSize; i++) {
389 String label1 = get(i + beg);
390 String label2 = n.get(i);
391
425 if (isDigit(name.charAt(i))) { // sequence is \DDD
426 i += 2; // consume remaining digits
427 }
428 label.append(c);
429
430 } else if (c != '.') { // an unescaped octet
431 label.append(c);
432
433 } else { // found '.' separator
434 add(0, label.toString()); // check syntax, then add label
435 // to end of name
436 label.delete(0, i); // clear buffer for next label
437 }
438 }
439
440 // If name is neither "." nor "", the octets (zero or more)
441 // from the rightmost dot onward are now added as the final
442 // label of the name. Those two are special cases in that for
443 // all other domain names, the number of labels is one greater
444 // than the number of dot separators.
445 if (!name.equals("") && !name.equals(".")) {
446 add(0, label.toString());
447 }
448
449 domain = name; // do this last, since add() sets it to null
450 }
451
452 /*
453 * Returns (as a char) the octet indicated by the escape sequence
454 * at a given position within a domain name.
455 * @throws InvalidNameException if a valid escape sequence is not found.
456 */
457 private static char getEscapedOctet(String name, int pos)
458 throws InvalidNameException {
459 try {
460 // assert (name.charAt(pos) == '\\');
461 char c1 = name.charAt(++pos);
462 if (isDigit(c1)) { // sequence is `\DDD'
463 char c2 = name.charAt(++pos);
464 char c3 = name.charAt(++pos);
465 if (isDigit(c2) && isDigit(c3)) {
|
351 domain = dn.domain + (domain.equals(".") ? "" : ".") + domain;
352 } else {
353 domain = null;
354 }
355
356 } else if (n instanceof CompositeName) {
357 n = (DnsName) n; // force ClassCastException
358
359 } else { // "n" is a compound name, but not a DnsName.
360 // Add labels least-significant first: sometimes more efficient.
361 for (int i = n.size() - 1; i >= 0; i--) {
362 add(pos, n.get(i));
363 }
364 }
365 return this;
366 }
367
368
369 boolean hasRootLabel() {
370 return (!isEmpty() &&
371 get(0).isEmpty());
372 }
373
374 /*
375 * Helper method for public comparison methods. Lexicographically
376 * compares components of this name in the range [beg,end) with
377 * all components of "n". Indexing is as for the Name interface,
378 * with 0 being the most significant. Returns negative, zero, or
379 * positive as these name components are less than, equal to, or
380 * greater than those of "n".
381 */
382 private int compareRange(int beg, int end, Name n) {
383 if (n instanceof CompositeName) {
384 n = (DnsName) n; // force ClassCastException
385 }
386 // Loop through labels, starting with most significant.
387 int minSize = Math.min(end - beg, n.size());
388 for (int i = 0; i < minSize; i++) {
389 String label1 = get(i + beg);
390 String label2 = n.get(i);
391
425 if (isDigit(name.charAt(i))) { // sequence is \DDD
426 i += 2; // consume remaining digits
427 }
428 label.append(c);
429
430 } else if (c != '.') { // an unescaped octet
431 label.append(c);
432
433 } else { // found '.' separator
434 add(0, label.toString()); // check syntax, then add label
435 // to end of name
436 label.delete(0, i); // clear buffer for next label
437 }
438 }
439
440 // If name is neither "." nor "", the octets (zero or more)
441 // from the rightmost dot onward are now added as the final
442 // label of the name. Those two are special cases in that for
443 // all other domain names, the number of labels is one greater
444 // than the number of dot separators.
445 if (!name.isEmpty() && !name.equals(".")) {
446 add(0, label.toString());
447 }
448
449 domain = name; // do this last, since add() sets it to null
450 }
451
452 /*
453 * Returns (as a char) the octet indicated by the escape sequence
454 * at a given position within a domain name.
455 * @throws InvalidNameException if a valid escape sequence is not found.
456 */
457 private static char getEscapedOctet(String name, int pos)
458 throws InvalidNameException {
459 try {
460 // assert (name.charAt(pos) == '\\');
461 char c1 = name.charAt(++pos);
462 if (isDigit(c1)) { // sequence is `\DDD'
463 char c2 = name.charAt(++pos);
464 char c3 = name.charAt(++pos);
465 if (isDigit(c2) && isDigit(c3)) {
|