SecurityIdentifier { public static byte[] toBytes(final String sid) { final StringTokenizer st = new StringTokenizer(sid, "-"); st.nextToken(); final int revision = Integer.valueOf(st.nextToken()); final long authority = Long.valueOf(st.nextToken()); final List<String> subAuthorities = new ArrayList<>(); while (st.hasMoreTokens()) { subAuthorities.add(st.nextToken()); } final int size = 8 + (4 * subAuthorities.size()); final ByteBuffer sidBuffer = ByteBuffer.allocate(size); sidBuffer.put((byte) (revision & 0xFF)); sidBuffer.put((byte) (subAuthorities.size() & 0xFF)); sidBuffer.limit(8); putLong(sidBuffer, authority, true); for (String subAuthority : subAuthorities) { sidBuffer.limit(sidBuffer.position() + 4); putLong(sidBuffer, Long.valueOf(subAuthority), false); } return sidBuffer.array(); } private  SecurityIdentifier(); static String toString(final byte[] sid); static byte[] toBytes(final String sid);  }
@Test(groups = "ad", dataProvider = "sids") public void testToBytes(final String sidString, final byte[] sid) throws Exception { Assert.assertEquals(sid, SecurityIdentifier.toBytes(sidString)); }