Java Object Array Convert To convertObjectGUIToByteString(byte[] objectGUID)

Here you can find the source of convertObjectGUIToByteString(byte[] objectGUID)

Description

Creates a byte-based String representation of a raw byte array representing the value of the objectGUID attribute retrieved from Active Directory.

The returned string is useful to perform queries on AD based on the objectGUID value.

License

Apache License

Parameter

Parameter Description
objectGUID A raw byte array representing the value of the <code>objectGUID</code> attribute retrieved from Active Directory.

Return

A byte-based String representation in the form of \[0]\[1]\[2]\[3]\[4]\[5]\[6]\[7]\[8]\[9]\[10]\[11]\[12]\[13]\[14]\[15]

Declaration

public static String convertObjectGUIToByteString(byte[] objectGUID) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//w w  w  .j  a  va2s .  com
     * <p>Creates a byte-based {@link String} representation of a raw byte array representing the value of the
     * <code>objectGUID</code> attribute retrieved from Active Directory.</p>
     *
     * <p>The returned string is useful to perform queries on AD based on the <code>objectGUID</code> value. Eg.:</p>
     *
     * <p>
     * String filter = "(&(objectClass=*)(objectGUID" + EQUAL + convertObjectGUIToByteString(objectGUID) + "))";
     * </p>
     *
     * @param objectGUID A raw byte array representing the value of the <code>objectGUID</code> attribute retrieved from
     * Active Directory.
     *
     * @return A byte-based String representation in the form of \[0]\[1]\[2]\[3]\[4]\[5]\[6]\[7]\[8]\[9]\[10]\[11]\[12]\[13]\[14]\[15]
     */
    public static String convertObjectGUIToByteString(byte[] objectGUID) {
        StringBuilder result = new StringBuilder();

        for (int i = 0; i < objectGUID.length; i++) {
            String transformed = prefixZeros((int) objectGUID[i] & 0xFF);
            result.append("\\");
            result.append(transformed);
        }

        return result.toString();
    }

    private static String prefixZeros(int value) {
        if (value <= 0xF) {
            StringBuilder sb = new StringBuilder("0");
            sb.append(Integer.toHexString(value));
            return sb.toString();
        } else {
            return Integer.toHexString(value);
        }
    }
}

Related

  1. convertObject(final Object obj, final Class clazz)
  2. convertObjectArrayToByte(Object[] array)
  3. convertObjectToBean(Object obj, Class clazz)
  4. convertObjectToBoolean(Object value)
  5. convertObjectToInt(Object value)
  6. convertObjectToIntegerIfNecessary(final Object configValue)