/** * Write a form-urlencoded document into the given stream, containing the * given sequence of name/parameter pairs. */ private static void percentEncode(Iterable<? extends Map.Entry<String, String[]>> parameters, OutputStream into) throws IOException { if (parameters != null) { boolean first = true; for (Map.Entry<String, String[]> parameter : parameters) { if (first) { first = false; } else { into.write(JwtUtil.QUERY_PARAMS_SEPARATOR); } into.write(JwtUtil.percentEncode(safeToString(parameter.getKey())).getBytes()); into.write('='); List<String> percentEncodedValues = new ArrayList<String>(parameter.getValue().length); for (String value : parameter.getValue()) { percentEncodedValues.add(JwtUtil.percentEncode(value)); } into.write(StringUtils.join(percentEncodedValues, ENCODED_PARAM_VALUE_SEPARATOR).getBytes()); } } }