This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Truncate a Java string so that its UTF-8 representation will not | |
* exceed the specified number of bytes. | |
* | |
* For discussion of why you might want to do this, see | |
* http://lpar.ath0.com/2011/06/07/unicode-alchemy-with-db2/ | |
*/ | |
public static String utf8truncate(String input, int length) { | |
StringBuffer result = new StringBuffer(length); | |
int resultlen = 0; |