LdapUtils { static byte[] numberToBytes(String number, int length, boolean bigEndian) { BigInteger bi = new BigInteger(number); byte[] bytes = bi.toByteArray(); int remaining = length - bytes.length; if (remaining < 0) { bytes = Arrays.copyOfRange(bytes, -remaining, bytes.length); } else { byte[] fill = new byte[remaining]; bytes = addAll(fill, bytes); } if (!bigEndian) { reverse(bytes); } return bytes; } private  LdapUtils(); static void closeContext(DirContext context); static NamingException convertLdapException(javax.naming.NamingException ex); static Class getActualTargetClass(DirContext context); static void collectAttributeValues(Attributes attributes, String name, Collection<Object> collection); static void collectAttributeValues(
            Attributes attributes, String name, Collection<T> collection, Class<T> clazz); static void iterateAttributeValues(Attribute attribute, AttributeValueCallbackHandler callbackHandler); static String convertCompositeNameToString(
			CompositeName compositeName); static LdapName newLdapName(Name name); static LdapName newLdapName(String distinguishedName); static LdapName removeFirst(Name dn, Name pathToRemove); static LdapName prepend(Name dn, Name pathToPrepend); static LdapName emptyLdapName(); static Rdn getRdn(Name name, String key); static Object getValue(Name name, String key); static Object getValue(Name name, int index); static String getStringValue(Name name, int index); static String getStringValue(Name name, String key); static String convertBinarySidToString(byte[] sid); static byte[] convertStringSidToBinary(String string);  }
@Test public void testSmallNumberToBytesBigEndian() throws Exception { byte[] result = LdapUtils.numberToBytes("5", 6, true); assertThat(result.length).isEqualTo(6); assertThat(result[0]).isEqualTo((byte)0); assertThat(result[1]).isEqualTo((byte)0); assertThat(result[2]).isEqualTo((byte)0); assertThat(result[3]).isEqualTo((byte)0); assertThat(result[4]).isEqualTo((byte)0); assertThat(result[5]).isEqualTo((byte)5); }
@Test public void testLargeNumberToBytesBigEndian() throws Exception { byte[] result = LdapUtils.numberToBytes("1183728", 6, true); assertThat(result.length).isEqualTo(6); assertThat(result[0]).isEqualTo((byte)0); assertThat(result[1]).isEqualTo((byte)0); assertThat(result[2]).isEqualTo((byte)0); assertThat(result[3]).isEqualTo((byte)18); assertThat(result[4]).isEqualTo((byte)15); assertThat(result[5]).isEqualTo((byte)-16); }
@Test public void testSmallNumberToBytesLittleEndian() throws Exception { byte[] result = LdapUtils.numberToBytes("21", 4, false); assertThat(result.length).isEqualTo(4); assertThat(result[0]).isEqualTo((byte)21); assertThat(result[1]).isEqualTo((byte)0); assertThat(result[2]).isEqualTo((byte)0); assertThat(result[3]).isEqualTo((byte)0); }
@Test public void testLargeNumberToBytesLittleEndian() throws Exception { byte[] result = LdapUtils.numberToBytes("2127521184", 4, false); assertThat(result.length).isEqualTo(4); assertThat(result[0]).isEqualTo((byte)-96); assertThat(result[1]).isEqualTo((byte)101); assertThat(result[2]).isEqualTo((byte)-49); assertThat(result[3]).isEqualTo((byte)126); }