@Override public void write(int b) throws IOException { if (PercentEncoding.isUnreserved(b)) { this.out.write(b); } else { this.writePercentEncoded(b); } }
/** * Transforms a {@code List<Entry<String, String>>} into {@code "a=b&c=d"}. * * @return {@code null} iff the <var>parameterList</var> is empty */ @Nullable private static String encodeParameters(List<Entry<String, String>> parameterList) { Iterator<Entry<String, String>> it = parameterList.iterator(); if (!it.hasNext()) return null; ByteArrayOutputStream baos; try { baos = new ByteArrayOutputStream(); PercentEncodingOutputStream peos = new PercentEncodingOutputStream(baos); for (;;) { Entry<String, String> e = it.next(); new OutputStreamWriter(peos, CHARSET_UTF_8).write(e.getKey()); peos.writeUnencoded('='); new OutputStreamWriter(peos, CHARSET_UTF_8).write(e.getValue()); if (!it.hasNext()) break; peos.writeUnencoded('&'); } } catch (IOException ioe) { if (LOGGER.isLoggable(FINE)) LOGGER.log(FINE, "Decoding parameters", ioe); return null; } @SuppressWarnings("deprecation") String result = new String(baos.toByteArray(), 0); return result; }
/** * Transforms a {@code List<Entry<String, String>>} into {@code "a=b&c=d"}. * * @return {@code null} iff the <var>parameterList</var> is empty */ @Nullable private static String encodeParameters(List<Entry<String, String>> parameterList) { Iterator<Entry<String, String>> it = parameterList.iterator(); if (!it.hasNext()) return null; ByteArrayOutputStream baos; try { baos = new ByteArrayOutputStream(); PercentEncodingOutputStream peos = new PercentEncodingOutputStream(baos); for (;;) { Entry<String, String> e = it.next(); new OutputStreamWriter(peos, CHARSET_UTF_8).write(e.getKey()); peos.writeUnencoded('='); new OutputStreamWriter(peos, CHARSET_UTF_8).write(e.getValue()); if (!it.hasNext()) break; peos.writeUnencoded('&'); } } catch (IOException ioe) { if (LOGGER.isLoggable(FINE)) LOGGER.log(FINE, "Decoding parameters", ioe); return null; } @SuppressWarnings("deprecation") String result = new String(baos.toByteArray(), 0); return result; }
@Override public void write(int b) throws IOException { if (PercentEncoding.isUnreserved(b)) { this.out.write(b); } else { this.writePercentEncoded(b); } }