I create the following for truncating a string in java to a new string with a given number of bytes.
String truncatedValue = \"\"; String curren
Use the UTF-8 CharsetEncoder, and encode until the output ByteBuffer contains as many bytes as you are willing to take, by looking for CoderResult.OVERFLOW.