com.addc.commons.slp.OpaqueAttributeValue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of addc-slp Show documentation
Show all versions of addc-slp Show documentation
The addc-slp library supplies client classes for registering objects with a Service Location Protocol Daemon and
for looking theses objects up later.
package com.addc.commons.slp;
import java.util.Arrays;
import com.addc.commons.string.ByteArrayFormatter;
/**
* The OpaqueAttributeValue supplies an attribute value containing an array of bytes
*/
public class OpaqueAttributeValue implements AttributeValue {
private final byte[] value;
/**
* Create a new OpaqueAttributeValue
*
* @param value
* The byte array value
*/
public OpaqueAttributeValue(byte[] value) {
this.value= Arrays.copyOf(value, value.length);
}
@Override
public byte[] getValue() {
return Arrays.copyOf(value, value.length);
}
@Override
public String getClassName() {
return byte[].class.getSimpleName();
}
@Override
public String getEscapedString() throws IllegalArgumentException {
StringBuffer buf= new StringBuffer();
buf.append("\\ff");
for (byte b : value) {
buf.append('\\').append(ByteArrayFormatter.getByteHex(b));
}
return buf.toString();
}
@Override
public int hashCode() {
final int prime= 31;
int result= 1;
result= prime * result + Arrays.hashCode(value);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof OpaqueAttributeValue)) {
return false;
}
OpaqueAttributeValue other= (OpaqueAttributeValue) obj;
if (!Arrays.equals(value, other.value)) {
return false;
}
return true;
}
@Override
public String toString() {
return ByteArrayFormatter.displayByteArray(value);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy