Here you can find the source of convertObjectGUIToByteString(byte[] objectGUID)
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.
Parameter | Description |
---|---|
objectGUID | A raw byte array representing the value of the <code>objectGUID</code> attribute retrieved from Active Directory. |
public static String convertObjectGUIToByteString(byte[] objectGUID)
//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); } } }