Debian Codegraph @

minidns-core/src/main/java/org/minidns/dnsname/InvalidDnsNameException.java

raw
1 /*
2 * Copyright 2015-2020 the original author or authors
3 *
4 * This software is licensed under the Apache License, Version 2.0,
5 * the GNU Lesser General Public License version 2 or later ("LGPL")
6 * and the WTFPL.
7 * You may choose either license to govern your use of this software only
8 * upon the condition that you accept all of the terms of either
9 * the Apache License 2.0, the LGPL 2.1+ or the WTFPL.
10 */
11 package org.minidns.dnsname;
12
13 import org.minidns.dnslabel.DnsLabel;
14
15 public abstract class InvalidDnsNameException extends IllegalStateException {
16
17 private static final long serialVersionUID = 1L;
18
19 protected final String ace;
20
21 protected InvalidDnsNameException(String ace) {
22 this.ace = ace;
23 }
24
25 public static class LabelTooLongException extends InvalidDnsNameException {
26 /**
27 *
28 */
29 private static final long serialVersionUID = 1L;
30
31 private final String label;
32
33 public LabelTooLongException(String ace, String label) {
34 super(ace);
35 this.label = label;
36 }
37
38 @Override
39 public String getMessage() {
40 return "The DNS name '" + ace + "' contains the label '" + label
41 + "' which exceeds the maximum label length of " + DnsLabel.MAX_LABEL_LENGTH_IN_OCTETS + " octets by "
42 + (label.length() - DnsLabel.MAX_LABEL_LENGTH_IN_OCTETS) + " octets.";
43 }
44 }
45
46 public static class DNSNameTooLongException extends InvalidDnsNameException {
47 /**
48 *
49 */
50 private static final long serialVersionUID = 1L;
51
52 private final byte[] bytes;
53
54 public DNSNameTooLongException(String ace, byte[] bytes) {
55 super(ace);
56 this.bytes = bytes;
57 }
58
59 @Override
60 public String getMessage() {
61 return "The DNS name '" + ace + "' exceeds the maximum name length of "
62 + DnsName.MAX_DNSNAME_LENGTH_IN_OCTETS + " octets by "
63 + (bytes.length - DnsName.MAX_DNSNAME_LENGTH_IN_OCTETS) + " octets.";
64 }
65 }
66 }