ds = new ByteDataSource(IOUtils.toString(src.getReader()).getBytes(StandardCharsets.UTF_8), ct);
public static String toString(final InputStream input, String charset) throws IOException { return toString(input, DEFAULT_BUFFER_SIZE, charset); } public static String toString(final InputStream input, int bufferSize)
public static String readStringFromStream(InputStream in) throws IOException { return toString(in); }
public static String toString(final InputStream input, int bufferSize, String charset) throws IOException { int avail = input.available(); if (avail > bufferSize) { bufferSize = avail; } Reader reader = charset == null ? new InputStreamReader(input, UTF8_CHARSET) : new InputStreamReader(input, charset); return toString(reader, bufferSize); }
public static String toString(final InputStream input, int bufferSize, String charset) throws IOException { int avail = input.available(); if (avail > bufferSize) { bufferSize = avail; } Reader reader = charset == null ? new InputStreamReader(input, UTF8_CHARSET) : new InputStreamReader(input, charset); return toString(reader, bufferSize); }
public static String toString(final InputStream input, int bufferSize, String charset) throws IOException { int avail = input.available(); if (avail > bufferSize) { bufferSize = avail; } Reader reader = charset == null ? new InputStreamReader(input, UTF8_CHARSET) : new InputStreamReader(input, charset); return toString(reader, bufferSize); }
private String getStringFromInputStream(InputStream in) throws Exception { return IOUtils.toString(in); } }
public void getPerson(int id) throws Exception{ String url = PERSON_SERVICE_URL + "person/get/" + id; System.out.println("\n### GET PERSON WITH ID " + id + " FROM URL " + url); HttpURLConnection connection = connect(url); connection.setDoInput(true); InputStream stream = connection.getResponseCode() / 100 == 2 ? connection.getInputStream() : connection.getErrorStream(); System.out.println("Status: " + connection.getResponseCode() + " " + connection.getResponseMessage()); System.out.println(IOUtils.toString(stream)); }
private String getStringFromInputStream(InputStream in) throws Exception { return IOUtils.toString(in); } }
@Test public void testSchema() throws Exception { URL url = new URL("http://localhost:" + PORT + "/service/TestService?wsdl"); String s = IOUtils.toString(url.openStream()); Assert.assertTrue(s, s.contains("application/octet-stream")); }
private Document loadWsdl(String serviceName) throws Exception { HttpURLConnection connection = getHttpConnection("http://localhost:" + PORT + "/" + serviceName + "?wsdl"); InputStream is = connection.getInputStream(); String wsdlContents = IOUtils.toString(is); // System.out.println(wsdlContents); return StaxUtils.read(new StringReader(wsdlContents)); }
@Test public void testImportSchema() throws Exception { String schemaURL = "http://localhost:" + PORT + "/schemaimport/sayHi" + "?xsd=sayhi/sayhi/sayhi-schema1.xsd"; URL url = new URL(schemaURL); try (InputStream ins = url.openStream()) { String output = IOUtils.toString(ins); assertTrue(output.indexOf("sayHiArray") > -1); } catch (Exception e) { e.printStackTrace(); fail("Can not access the import schema"); } }
@Test public void testImportWsdl() throws Exception { String wsdlURL = "http://localhost:" + PORT + "/schemaimport/sayHi" + "?wsdl=sayhi/sayhi/a.wsdl"; URL url = new URL(wsdlURL); try (InputStream ins = url.openStream()) { String output = IOUtils.toString(ins); assertTrue(output.indexOf("sayHiArray") > -1); } catch (Exception e) { e.printStackTrace(); fail("Can not access the import wsdl"); } }
@Test public void testImportWsdl2() throws Exception { String wsdlURL = "http://localhost:" + PORT + "/schemaimport/sayHi2" + "?wsdl=../sayhi/sayhi/a.wsdl"; URL url = new URL(wsdlURL); try (InputStream ins = url.openStream()) { String output = IOUtils.toString(ins); assertTrue(output.indexOf("sayHiArray") > -1); } catch (Exception e) { e.printStackTrace(); fail("Can not access the import wsdl"); } }
@Test public void testSchemaInclude() throws Exception { String schemaURL = "http://localhost:" + PORT + "/schemainclude/service?xsd=d1/d1/test.xsd"; URL url = new URL(schemaURL); try (InputStream ins = url.openStream()) { String output = IOUtils.toString(ins); assertTrue(output.indexOf("msg:RequestType") > -1); assertTrue(output.indexOf("msg:SomeFeatureType") > -1); } catch (Exception e) { e.printStackTrace(); fail("Can not access the include schema"); } }
@Test public void testAnotherSchemaImportl() throws Exception { String schemaURL = "http://localhost:" + PORT + "/schemaimport/service" + "?xsd=schema1.xsd"; URL url = new URL(schemaURL); try (InputStream ins = url.openStream()) { String output = IOUtils.toString(ins); assertTrue(output.indexOf("schemaimport/service?xsd=schema2.xsd") > -1); assertTrue(output.indexOf("schemaimport/service?xsd=schema5.xsd") > -1); } catch (Exception e) { e.printStackTrace(); fail("Can not access the import wsdl"); } }
private String readUrl(String address) { String content = null; try { URL url = new URL(address); assertNotNull(url.getContent()); content = IOUtils.toString((InputStream) url.getContent()); } catch (IOException e) { e.printStackTrace(System.err); Assert.fail("Couldn't read URL: " + e.getMessage()); } return content; }
@Test public void testGetBookQueryGZIP() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/"; WebClient wc = WebClient.create(address); wc.acceptEncoding("gzip,deflate"); wc.encoding("gzip"); InputStream r = wc.get(InputStream.class); assertNotNull(r); GZIPInputStream in = new GZIPInputStream(r); String s = IOUtils.toString(in); in.close(); assertTrue(s, s.contains("id>124")); }
@Test public void testJaxWsMtomReply() throws Exception { setupForTest(true); DataHandlerBean dhBean = jaxwsClient.produceDataHandlerBean(); Assert.assertNotNull(dhBean); String result = IOUtils.toString(dhBean.getDataHandler().getInputStream(), "utf-8"); Assert.assertEquals(MtomTestImpl.STRING_DATA, result); }
@Test public void testMtomReply() throws Exception { setupForTest(true); DataHandlerBean dhBean = client.produceDataHandlerBean(); Assert.assertNotNull(dhBean); String result = IOUtils.toString(dhBean.getDataHandler().getInputStream(), "utf-8"); Assert.assertEquals(MtomTestImpl.STRING_DATA, result); }