Mmm. I cant seem to find the class StringUtils and the method bytesToHex in the JDK docs.
If I look at your code I think you're converting a byte/char array into a hexadecimal string minus
the last 4 bytes/chars. One byte/char would correspond to 2 digits in the resulting string.
So limiting the length to 8 would only work if the original userId would be exactly 8 bytes
-> abcdefgh minus 4 -> abcd -> 61626364
If it would be, lets say 6 bytes the result would be :
-> abcdef minus 4 -> ab -> 6162
If you would want to limit the length of an array why not use System.arraycopy :
char src="42:life universe everything".toCharArray();
char dst=new char;
Good luck !