my guess is that a decent percentage of the time the string is all isUnreserved chars. How about a quick loop through to check if it is and only do the expensive String.getBytes if its not? (and if its not, you should just to basically jump right to the right part of the String with an not isUnreserved char and start there)