All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.addc.commons.slp.OpaqueAttributeValue Maven / Gradle / Ivy

Go to download

The addc-slp library supplies client classes for registering objects with a Service Location Protocol Daemon and for looking theses objects up later.

There is a newer version: 2.6
Show newest version
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