Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/main/java/org/xbill/DNS/CAARecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.xbill.DNS;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
* Certification Authority Authorization
Expand Down Expand Up @@ -79,12 +80,32 @@ public int getFlags() {

/** Returns the tag. */
public String getTag() {
return byteArrayToString(tag, false);
return new String(tag, StandardCharsets.US_ASCII);
}

/** Returns the value */
/**
* Returns the value as a string.
*
* @param escape if true, returns the RR textual representation of the underlying bytes. If false,
* returns just the simple string using the UTF-8 charset with no additional escaping.
* @since 3.6.5
*/
public String getValue(boolean escape) {
return escape ? byteArrayToString(value, false) : new String(value, StandardCharsets.UTF_8);
}

/** Returns the value as a string, escaped for RR textual representation */
public String getValue() {
return byteArrayToString(value, false);
return getValue(true);
}

/**
* Returns the value as a raw byte-array
*
* @since 3.6.5
*/
public byte[] getValueAsByteArray() {
return value;
}

@Override
Expand Down
49 changes: 45 additions & 4 deletions src/main/java/org/xbill/DNS/HINFORecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.xbill.DNS;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
* Host Information - describes the CPU and OS of a host
Expand Down Expand Up @@ -51,14 +52,54 @@ protected void rdataFromString(Tokenizer st, Name origin) throws IOException {
}
}

/** Returns the host's CPU */
/**
* Returns the host's CPU as a string.
*
* @param escape if true, returns the RR textual representation of the underlying bytes. If false,
* returns just the simple string using the UTF-8 charset with no additional escaping.
* @since 3.6.5
*/
public String getCPU(boolean escape) {
return escape ? byteArrayToString(cpu, false) : new String(cpu, StandardCharsets.UTF_8);
}

/** Returns the host's CPU as a string, escaped for RR textual representation */
public String getCPU() {
return byteArrayToString(cpu, false);
return getCPU(true);
}

/**
* Returns the host's CPU as a raw byte-array
*
* @since 3.6.5
*/
public byte[] getCPUAsByteArray() {
return cpu;
}

/** Returns the host's OS */
/**
* Returns the host's OS as a string.
*
* @param escape if true, returns the RR textual representation of the underlying bytes. If false,
* returns just the simple string using the UTF-8 charset with no additional escaping.
* @since 3.6.5
*/
public String getOS(boolean escape) {
return escape ? byteArrayToString(os, false) : new String(os, StandardCharsets.UTF_8);
}

/** Returns the host's OS as a string, escaped for RR textual representation */
public String getOS() {
return byteArrayToString(os, false);
return getOS(true);
}

/**
* Returns the host's OS as a raw byte-array
*
* @since 3.6.5
*/
public byte[] getOSAsByteArray() {
return os;
}

@Override
Expand Down
59 changes: 54 additions & 5 deletions src/main/java/org/xbill/DNS/ISDNRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.xbill.DNS;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
* ISDN - identifies the ISDN number and subaddress associated with a name.
Expand Down Expand Up @@ -59,17 +60,65 @@ protected void rdataFromString(Tokenizer st, Name origin) throws IOException {
}
}

/** Returns the ISDN number associated with the domain. */
/**
* Returns the ISDN number associated with the domain as a string.
*
* @param escape if true, returns the RR textual representation of the underlying bytes. If false,
* returns just the simple string using the UTF-8 charset with no additional escaping.
* @since 3.6.5
*/
public String getAddress(boolean escape) {
return escape ? byteArrayToString(address, false) : new String(address, StandardCharsets.UTF_8);
}

/**
* Returns the ISDN number associated with the domain as a string, escaped for RR textual
* representation
*/
public String getAddress() {
return byteArrayToString(address, false);
return getAddress(true);
}

/** Returns the ISDN subaddress, or null if there is none. */
public String getSubAddress() {
/**
* Returns the ISDN number associated with the domain as a raw byte-array
*
* @since 3.6.5
*/
public byte[] getAddressAsByteArray() {
return address;
}

/**
* Returns the ISDN subaddress as a string, or null if there is none.
*
* @param escape if true, returns the RR textual representation of the underlying bytes. If false,
* returns just the simple string using the UTF-8 charset with no additional escaping.
* @since 3.6.5
*/
public String getSubAddress(boolean escape) {
if (subAddress == null) {
return null;
}
return byteArrayToString(subAddress, false);
return escape
? byteArrayToString(subAddress, false)
: new String(subAddress, StandardCharsets.UTF_8);
}

/**
* Returns the ISDN subaddress as a string, escaped for RR textual representation, or null if
* there is none.
*/
public String getSubAddress() {
return getSubAddress(true);
}

/**
* Returns the ISDN subaddress as a raw byte-array, or null if there is none.
*
* @since 3.6.5
*/
public byte[] getSubAddressAsByteArray() {
return subAddress;
}

@Override
Expand Down
51 changes: 46 additions & 5 deletions src/main/java/org/xbill/DNS/NAPTRRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.xbill.DNS;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
* Name Authority Pointer Record - specifies rewrite rule, that when applied to an existing string
Expand Down Expand Up @@ -112,17 +113,57 @@ public int getPreference() {

/** Returns flags */
public String getFlags() {
return byteArrayToString(flags, false);
return new String(flags, StandardCharsets.US_ASCII);
}

/** Returns service */
/**
* Returns the service as a string.
*
* @param escape if true, returns the RR textual representation of the underlying bytes. If false,
* returns just the simple string using the UTF-8 charset with no additional escaping.
* @since 3.6.5
*/
public String getService(boolean escape) {
return escape ? byteArrayToString(service, false) : new String(service, StandardCharsets.UTF_8);
}

/** Returns the service as a string, escaped for RR textual representation */
public String getService() {
return byteArrayToString(service, false);
return getService(true);
}

/**
* Returns the service as a raw byte-array
*
* @since 3.6.5
*/
public byte[] getServiceAsByteArray() {
return service;
}

/** Returns regexp */
/**
* Returns regexp as a string.
*
* @param escape if true, returns the RR textual representation of the underlying bytes. If false,
* returns just the simple string using the UTF-8 charset with no additional escaping.
* @since 3.6.5
*/
public String getRegexp(boolean escape) {
return escape ? byteArrayToString(regexp, false) : new String(regexp, StandardCharsets.UTF_8);
}

/** Returns regexp as a string, escaped for RR textual representation */
public String getRegexp() {
return byteArrayToString(regexp, false);
return getRegexp(true);
}

/**
* Returns regexp as a raw byte-array
*
* @since 3.6.5
*/
public byte[] getRegexpAsByteArray() {
return regexp;
}

/** Returns the replacement domain-name */
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/org/xbill/DNS/NSAPRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,27 @@ protected void rdataFromString(Tokenizer st, Name origin) throws IOException {
}
}

/** Returns the NSAP address. */
/**
* Returns the NSAP address as a string, escaped for RR textual representation.
*
* <p>Obsolete, use {@link NSAPRecord#getAddressAsByteArray} instead.
*
* @deprecated
*/
@Deprecated
public String getAddress() {
return byteArrayToString(address, false);
}

/**
* Returns the NSAP address.
*
* @since 3.6.5
*/
public byte[] getAddressAsByteArray() {
return address;
}

@Override
protected void rrToWire(DNSOutput out, Compression c, boolean canonical) {
out.writeByteArray(address);
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/org/xbill/DNS/TXTBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.xbill.DNS;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
Expand Down Expand Up @@ -90,22 +91,31 @@ protected String rrToString() {
}

/**
* Returns the text strings
* Returns the text strings as a list of strings.
*
* @return A list of Strings corresponding to the text strings.
* @param escape if true, returns the RR textual representation of the underlying bytes for each
* string. If false, returns just the simple strings using the UTF-8 charset with no
* additional escaping.
* @since 3.6.5
*/
public List<String> getStrings() {
public List<String> getStrings(boolean escape) {
List<String> list = new ArrayList<>(strings.size());
for (byte[] string : strings) {
list.add(byteArrayToString(string, false));
list.add(
escape ? byteArrayToString(string, false) : new String(string, StandardCharsets.UTF_8));
}
return list;
}

/** Returns the text strings as a list of strings, escaped for RR textual representation */
public List<String> getStrings() {
return getStrings(true);
}

/**
* Returns the text strings
* Returns the text strings as a list of raw byte-arrays
*
* @return A list of byte arrays corresponding to the text strings.
* @since 3.6.5
*/
public List<byte[]> getStringsAsByteArrays() {
return strings;
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/org/xbill/DNS/URIRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
package org.xbill.DNS;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;

/**
* Uniform Resource Identifier (URI) DNS Resource Record
Expand Down Expand Up @@ -78,11 +81,27 @@ public int getWeight() {
return weight;
}

/** Returns the target URI */
/**
* Returns the target URI as a string, escaped for RR textual representation.
*
* <p>Obsolete, use {@link URIRecord#getTargetAsURI()} instead.
*
* @deprecated
*/
@Deprecated
public String getTarget() {
return byteArrayToString(target, false);
}

/**
* Returns the target URI as a {@link URI}
*
* @since 3.6.5
*/
public URI getTargetAsURI() throws URISyntaxException {
return new URI(new String(target, StandardCharsets.UTF_8));
}

@Override
protected void rrToWire(DNSOutput out, Compression c, boolean canonical) {
out.writeU16(priority);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/xbill/DNS/X25Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.xbill.DNS;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
* X25 - identifies the PSDN (Public Switched Data Network) address in the X.121 numbering plan
Expand Down Expand Up @@ -60,7 +61,7 @@ protected void rdataFromString(Tokenizer st, Name origin) throws IOException {

/** Returns the X.25 PSDN address. */
public String getAddress() {
return byteArrayToString(address, false);
return new String(address, StandardCharsets.US_ASCII);
}

@Override
Expand Down
Loading
Loading