IOHelper { public static String readString(InputStream is) throws IOException { return readString(is, DEFAULT_CHARSET); }  static int getConnectionTimeoutMs(); static int getReadTimeoutMs(); static String getMyDomain(); static String readString(InputStream is); static String readString(HttpURLConnection conn); static String readString(HttpURLConnection conn, final String charset); static List<String> readLines(InputStream in); static List<String> readLines(InputStream in, Charset cs); static String readString(InputStream is, String charset); static String readString(InputStream in, Charset cs); static byte[] readBytes(HttpURLConnection conn); static void readBytesTo(HttpURLConnection conn, OutputStream out); static byte[] readBytes(InputStream is); static void copy(InputStream in, OutputStream out); static void copy(InputStream in, OutputStream out, long sizeLimit); static HttpURLConnection getConnectionFromProps(final String propertiesPrefix); static HttpURLConnection getConnectionFromProps(final String url, final String propertiesPrefix); static HttpURLConnection getConnection(final String pUrl); static HttpURLConnection getConnection(final String pUrl,
                                                  final String userName, final String password); static HttpURLConnection getConnection(String pUrl,
            String user, String pass, Map<String, String> query); static HttpURLConnection getConnection(String pUrl,
            String user, String pass, Map<String, String> query, Map<String, String> headers); static HttpURLConnection followRedirect(HttpURLConnection conn, int redirectLatch); static HttpURLConnection followRedirect(HttpURLConnection conn,
            String user, String pass, int redirectLatch); static HttpURLConnection followRedirect(HttpURLConnection conn,
            String user, String pass, Map<String, String> query, int redirectLatch); static HttpURLConnection followRedirect(HttpURLConnection conn,
            String user, String pass, Map<String, String> query,
            Map<String, String> headers, int redirectLatch); static InputStream debugResponse(final InputStream in); static String getCharset(final HttpURLConnection con); static String getCharset(final HttpURLConnection con, final String defaultCharset); static void setupBasicAuth(final HttpURLConnection con,final String userName, final String password); static void writeToConnection(final HttpURLConnection con,
                                         final String postData); static void writeToConnection(final HttpURLConnection con,
                                         final byte[] bytes); static String getURL(final String pUrl); static String getURL(final String pUrl, final String charset); static String getURL(final String pUrl,
                                final Map<String, String> headers); static String getURL(final String pUrl,
                                final Map<String, String> headers, final String charset); static String getURL(final HttpURLConnection con,
                                final Map<String, String> headers, final String charset); static String getURL(final String pUrl, final String userName, final String password ); static String getURL(final String pUrl, final String userName, final String password,
                                final Map<String, String> headers); static String getURL(final String pUrl,final String userName, final String password,
                                final Map<String, String> headers, final String charset); static void writeHeaders(final HttpURLConnection con,
                                    final Map<String, String> headers); static void writeHeader(final HttpURLConnection con,
                                    final String header, final String value); static void setContentType(final HttpURLConnection con,
                                   final String value); static String encode64(String in); static String decode64(String in); static HttpURLConnection postForm(String url, Map<String, String> keyValuePairs); static HttpURLConnection post(String url, String contentType,
            byte[] body); static HttpURLConnection post(String url, String contentType,
            ByteArrayOutputStream baos); static HttpURLConnection post(HttpURLConnection conn, String contentType,
            byte[] body); static HttpURLConnection post(HttpURLConnection conn, String contentType,
                                         String body); static HttpURLConnection post(HttpURLConnection conn, String contentType,
            ByteArrayOutputStream baos); static HttpURLConnection put(String url, String contentType, byte[] body); static HttpURLConnection put(HttpURLConnection conn, String contentType, byte[] body); static void close(final Closeable in); static void trustAllCerts(final HttpURLConnection connection); static void trustAllHosts(final HttpURLConnection connection); static Map<String, List<String>> parseQuerystring(String url); static Map<String, List<String>> parseQuerystring(URL url); static String removeQueryString(String url); static String constructUrl(final String url, Map<String, String> params); static String addQueryString(String url, String queryString); static String fixPath(String url); static String addUrlParam(final String url, String key, String... value); static String createQuerystring(Map<String, List<String>> kvps); static String getParams(Map<String, String> kvps); static String getParamsMultiValue(Map<String, String[]> kvps); static String urlEncodePayload(String s); static String urlEncode(String s); @Deprecated static InputStream getInputStream(HttpURLConnection conn); static void closeSilently(HttpURLConnection c); static void readFullyIgnoring(InputStream in); static ByteArrayOutputStream gzip(byte[] bytes); static ByteArrayOutputStream ungzip(byte[] cached); static final String HEADER_AUTHORIZATION; static final String HEADER_CONTENTTYPE; static final String HEADER_USERAGENT; static final String HEADER_REFERER; static final String HEADER_ACCEPT; static final String HEADER_ACCEPT_CHARSET; static final String HEADER_ACCEPT_ENCODING; static final String CHARSET_UTF8; static final String DEFAULT_CHARSET; static final Charset DEFAULT_CHARSET_CS; static final String CONTENTTYPE_FORM_URLENCODED; static final String CONTENT_TYPE_JSON; static final String CONTENT_TYPE_XML; static final String ENCODING_GZIP; }
@Test public void testReadString() throws IOException { String expected = "foobar;baz;qux;whatIsThat\r\n\nErrorFoo öäöäöäöäöä"; byte[] in = expected.getBytes(StandardCharsets.UTF_8); String actual = IOHelper.readString(new ByteArrayInputStream(in)); assertEquals(expected, actual); String longString = Collections.nCopies(1000, expected).stream() .collect(Collectors.joining("::")); in = longString.getBytes(StandardCharsets.UTF_8); String actualLongString = IOHelper.readString(new ByteArrayInputStream(in)); assertEquals(longString, actualLongString); }