Java Code Examples for org.apache.cxf.helpers.IOUtils#newStringFromBytes()
The following examples show how to use
org.apache.cxf.helpers.IOUtils#newStringFromBytes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlugInClassLoaderTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testLoadSlashResourceWithPluginClassLoader() throws Exception { Class<?> resultClass = plugInClassLoader.loadClass( "org.apache.cxf.jca.dummy.Dummy"); URL url = resultClass.getResource("/META-INF/MANIFEST.MF"); LOG.info("URL: " + url); assertTrue("bad url: " + url, url.toString().startsWith("classloader:")); InputStream configStream = url.openStream(); assertNotNull("stream must not be null. ", configStream); assertTrue("unexpected stream class: " + configStream.getClass(), configStream instanceof java.io.ByteArrayInputStream); byte[] bytes = new byte[21]; configStream.read(bytes, 0, bytes.length); String result = IOUtils.newStringFromBytes(bytes); LOG.fine("dummy.txt contents: " + result); assertTrue("unexpected dummy.txt contents:" + result, result.indexOf("Manifest-Version: 1.0") != -1); }
Example 2
Source File: PlugInClassLoaderTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testLoadResourceWithPluginClassLoader() throws Exception { Class<?> resultClass = plugInClassLoader.loadClass( "org.apache.cxf.jca.dummy.Dummy"); URL url = resultClass.getResource("dummy.txt"); LOG.info("URL: " + url); assertTrue("bad url: " + url, url.toString().startsWith("classloader:")); InputStream configStream = url.openStream(); assertNotNull("stream must not be null. ", configStream); assertTrue("unexpected stream class: " + configStream.getClass(), configStream instanceof java.io.ByteArrayInputStream); byte[] bytes = new byte[10]; configStream.read(bytes, 0, bytes.length); String result = IOUtils.newStringFromBytes(bytes); LOG.fine("dummy.txt contents: " + result); assertEquals("unexpected dummy.txt contents.", "blah,blah.", result); }
Example 3
Source File: AttachmentDeserializer.java From cxf with Apache License 2.0 | 6 votes |
private String findBoundaryFromInputStream() throws IOException { InputStream is = message.getContent(InputStream.class); //boundary should definitely be in the first 2K; PushbackInputStream in = new PushbackInputStream(is, 4096); byte[] buf = new byte[2048]; int i = in.read(buf); int len = i; while (i > 0 && len < buf.length) { i = in.read(buf, len, buf.length - len); if (i > 0) { len += i; } } String msg = IOUtils.newStringFromBytes(buf, 0, len); in.unread(buf, 0, len); // Reset the input stream since we'll need it again later message.setContent(InputStream.class, in); // Use regex to get the boundary and return null if it's not found Matcher m = INPUT_STREAM_BOUNDARY_PATTERN.matcher(msg); return m.find() ? "--" + m.group(1) : null; }
Example 4
Source File: SwAServiceImpl.java From cxf with Apache License 2.0 | 6 votes |
public void echoData(Holder<String> text, Holder<DataHandler> data) { try { InputStream bis = null; bis = data.value.getDataSource().getInputStream(); byte[] b = new byte[6]; bis.read(b, 0, 6); String string = IOUtils.newStringFromBytes(b); ByteArrayDataSource source = new ByteArrayDataSource(("test" + string).getBytes(), "application/octet-stream"); data.value = new DataHandler(source); } catch (IOException e) { e.printStackTrace(); } }
Example 5
Source File: SwAServiceImpl.java From cxf with Apache License 2.0 | 6 votes |
public void echoDataWithHeader(Holder<String> text, Holder<DataHandler> data, Holder<String> headerText) { try { InputStream bis = null; bis = data.value.getDataSource().getInputStream(); byte[] b = new byte[6]; bis.read(b, 0, 6); String string = IOUtils.newStringFromBytes(b); ByteArrayDataSource source = new ByteArrayDataSource(("test" + string).getBytes(), "application/octet-stream"); data.value = new DataHandler(source); } catch (IOException e) { e.printStackTrace(); } }
Example 6
Source File: AbstractJMSTester.java From cxf with Apache License 2.0 | 6 votes |
protected static void verifyReceivedMessage(Message message) { String response = "<not found>"; InputStream bis = message.getContent(InputStream.class); if (bis != null) { try { byte[] bytes = new byte[bis.available()]; bis.read(bytes); response = IOUtils.newStringFromBytes(bytes); } catch (IOException ex) { fail("Read the Destination recieved Message error: " + ex.getMessage()); } } else { Reader reader = message.getContent(Reader.class); char[] buffer = new char[5000]; try { int i = reader.read(buffer); response = new String(buffer, 0, i); } catch (IOException e) { fail("Read the Destination recieved Message error: " + e.getMessage()); } } assertEquals("The response content should be equal", MESSAGE_CONTENT, response); }
Example 7
Source File: ClientServerSwaTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testSwa() throws Exception { SwAService service = new SwAService(); SwAServiceInterface port = service.getSwAServiceHttpPort(); setAddress(port, "http://localhost:" + serverPort + "/swa"); Holder<String> textHolder = new Holder<>(); Holder<DataHandler> data = new Holder<>(); ByteArrayDataSource source = new ByteArrayDataSource("foobar".getBytes(), "application/octet-stream"); DataHandler handler = new DataHandler(source); data.value = handler; textHolder.value = "Hi"; port.echoData(textHolder, data); InputStream bis = null; bis = data.value.getDataSource().getInputStream(); byte[] b = new byte[10]; bis.read(b, 0, 10); String string = IOUtils.newStringFromBytes(b); assertEquals("testfoobar", string); assertEquals("Hi", textHolder.value); }
Example 8
Source File: MtoMTest.java From cxf with Apache License 2.0 | 6 votes |
private Void acceptMtoMString(Context context) throws IOException { Notifier notifier = testUtilities.rhinoCallConvert("testMtoMString", Notifier.class, testUtilities.javaToJS(getAddress())); boolean notified = notifier.waitForJavascript(1000 * 10); assertTrue(notified); Integer errorStatus = testUtilities.rhinoEvaluateConvert("globalErrorStatus", Integer.class); assertNull(errorStatus); String errorText = testUtilities.rhinoEvaluateConvert("globalErrorStatusText", String.class); assertNull(errorText); assertEquals("disorganized<organized", implementor.getLastDHBean().getOrdinary()); InputStream dis = implementor.getLastDHBean().getNotXml10().getInputStream(); byte[] bytes = new byte[2048]; int byteCount = dis.read(bytes, 0, 2048); String stuff = IOUtils.newStringFromBytes(bytes, 0, byteCount); assertEquals("<html>\u0027</html>", stuff); return null; }
Example 9
Source File: ClientServerSwaTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testSwaDataStruct() throws Exception { SwAService service = new SwAService(); SwAServiceInterface port = service.getSwAServiceHttpPort(); setAddress(port, "http://localhost:" + serverPort + "/swa"); Holder<DataStruct> structHolder = new Holder<>(); ByteArrayDataSource source = new ByteArrayDataSource("foobar".getBytes(), "application/octet-stream"); DataHandler handler = new DataHandler(source); DataStruct struct = new DataStruct(); struct.setDataRef(handler); structHolder.value = struct; port.echoDataRef(structHolder); handler = structHolder.value.getDataRef(); InputStream bis = handler.getDataSource().getInputStream(); byte[] b = new byte[10]; bis.read(b, 0, 10); String string = IOUtils.newStringFromBytes(b); assertEquals("testfoobar", string); bis.close(); }
Example 10
Source File: SwAServiceImpl.java From cxf with Apache License 2.0 | 6 votes |
public void echoDataWithHeader(Holder<String> text, Holder<DataHandler> data, Holder<String> headerText) { try { InputStream bis = null; bis = data.value.getDataSource().getInputStream(); byte[] b = new byte[6]; bis.read(b, 0, 6); String string = IOUtils.newStringFromBytes(b); ByteArrayDataSource source = new ByteArrayDataSource(("test" + string).getBytes(), "application/octet-stream"); data.value = new DataHandler(source); } catch (IOException e) { e.printStackTrace(); } }
Example 11
Source File: SwAServiceImpl.java From cxf with Apache License 2.0 | 6 votes |
public void echoData(Holder<String> text, Holder<DataHandler> data) { try { InputStream bis = null; bis = data.value.getDataSource().getInputStream(); byte[] b = new byte[6]; bis.read(b, 0, 6); String string = IOUtils.newStringFromBytes(b); ByteArrayDataSource source = new ByteArrayDataSource(("test" + string).getBytes(), "application/octet-stream"); data.value = new DataHandler(source); } catch (IOException e) { e.printStackTrace(); } }
Example 12
Source File: Base64UtilityTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testEncodeDecodeStreams() throws Exception { byte[] bytes = new byte[100]; for (int x = 0; x < bytes.length; x++) { bytes[x] = (byte)x; } ByteArrayOutputStream bout = new ByteArrayOutputStream(); ByteArrayOutputStream bout2 = new ByteArrayOutputStream(); Base64Utility.encodeChunk(bytes, 0, bytes.length, bout); String encodedString = IOUtils.newStringFromBytes(bout.toByteArray()); Base64Utility.decode(encodedString.toCharArray(), 0, encodedString.length(), bout2); assertArrayEquals(bytes, bout2.toByteArray()); String in = "QWxhZGRpbjpvcGVuIHNlc2FtZQ=="; bout.reset(); bout2.reset(); Base64Utility.decode(in, bout); bytes = bout.toByteArray(); assertEquals("Aladdin:open sesame", IOUtils.newStringFromBytes(bytes)); StringWriter writer = new StringWriter(); Base64Utility.encode(bytes, 0, bytes.length, writer); assertEquals(in, writer.toString()); }
Example 13
Source File: ClientServerSwaTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testSwa() throws Exception { JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setWsdlLocation("classpath:/swa-mime_jms.wsdl"); factory.setTransportId(SoapJMSConstants.SOAP_JMS_SPECIFICIATION_TRANSPORTID); factory.setServiceName(new QName("http://cxf.apache.org/swa", "SwAService")); factory.setEndpointName(new QName("http://cxf.apache.org/swa", "SwAServiceJMSPort")); factory.setAddress(ADDRESS + broker.getEncodedBrokerURL()); factory.getOutInterceptors().add(new LoggingOutInterceptor()); SwAService port = factory.create(SwAService.class); Holder<String> textHolder = new Holder<>(); Holder<DataHandler> data = new Holder<>(); ByteArrayDataSource source = new ByteArrayDataSource("foobar".getBytes(), "application/octet-stream"); DataHandler handler = new DataHandler(source); data.value = handler; textHolder.value = "Hi"; port.echoData(textHolder, data); InputStream bis = null; bis = data.value.getDataSource().getInputStream(); byte[] b = new byte[10]; bis.read(b, 0, 10); String string = IOUtils.newStringFromBytes(b); assertEquals("testfoobar", string); assertEquals("Hi", textHolder.value); if (port instanceof Closeable) { ((Closeable)port).close(); } }
Example 14
Source File: SwAServiceImpl.java From cxf with Apache License 2.0 | 5 votes |
public void echoDataRef(Holder<DataStruct> data) { try { InputStream bis = null; bis = data.value.getDataRef().getDataSource().getInputStream(); byte[] b = new byte[6]; bis.read(b, 0, 6); String string = IOUtils.newStringFromBytes(b); ByteArrayDataSource source = new ByteArrayDataSource(("test" + string).getBytes(), "application/octet-stream"); data.value.setDataRef(new DataHandler(source)); } catch (IOException e) { e.printStackTrace(); } }
Example 15
Source File: PushBack401.java From cxf with Apache License 2.0 | 5 votes |
/** * This function extracts the user:pass token from * the Authorization:Basic header. It returns a two element * String array, the first being the userid, the second * being the password. It returns null, if it cannot parse. */ private String[] extractUserPass(String token) { try { byte[] userpass = Base64Utility.decode(token); String up = IOUtils.newStringFromBytes(userpass); String user = up.substring(0, up.indexOf(':')); String pass = up.substring(up.indexOf(':') + 1); return new String[] {user, pass}; } catch (Exception e) { return null; } }
Example 16
Source File: SwANoMimeServiceImpl.java From cxf with Apache License 2.0 | 5 votes |
public void echoDataRef(Holder<DataStruct> data) { try { InputStream bis = null; bis = data.value.getDataRef().getDataSource().getInputStream(); byte[] b = new byte[6]; bis.read(b, 0, 6); String string = IOUtils.newStringFromBytes(b); ByteArrayDataSource source = new ByteArrayDataSource(("test" + string).getBytes(), "application/octet-stream"); data.value.setDataRef(new DataHandler(source)); } catch (IOException e) { e.printStackTrace(); } }
Example 17
Source File: ClientServerSwaTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testSwaWithHeaders() throws Exception { SwAService service = new SwAService(); SwAServiceInterface port = service.getSwAServiceHttpPort(); setAddress(port, "http://localhost:" + serverPort + "/swa"); Holder<String> textHolder = new Holder<>(); Holder<String> headerHolder = new Holder<>(); Holder<DataHandler> data = new Holder<>(); ByteArrayDataSource source = new ByteArrayDataSource("foobar".getBytes(), "application/octet-stream"); DataHandler handler = new DataHandler(source); data.value = handler; textHolder.value = "Hi"; headerHolder.value = "Header"; port.echoDataWithHeader(textHolder, data, headerHolder); InputStream bis = null; bis = data.value.getDataSource().getInputStream(); byte[] b = new byte[10]; bis.read(b, 0, 10); String string = IOUtils.newStringFromBytes(b); assertEquals("testfoobar", string); assertEquals("Hi", textHolder.value); assertEquals("Header", headerHolder.value); }
Example 18
Source File: ClientServerSwaTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testSwaNoMimeCodeGen() throws Exception { org.apache.cxf.swa_nomime.SwAService service = new org.apache.cxf.swa_nomime.SwAService(); org.apache.cxf.swa_nomime.SwAServiceInterface port = service.getSwAServiceHttpPort(); setAddress(port, "http://localhost:" + serverPort + "/swa-nomime"); Holder<String> textHolder = new Holder<>("Hi"); Holder<byte[]> data = new Holder<>("foobar".getBytes()); port.echoData(textHolder, data); String string = IOUtils.newStringFromBytes(data.value); assertEquals("testfoobar", string); assertEquals("Hi", textHolder.value); URL url1 = this.getClass().getResource("resources/attach.text"); URL url2 = this.getClass().getResource("resources/attach.html"); URL url3 = this.getClass().getResource("resources/attach.xml"); URL url4 = this.getClass().getResource("resources/attach.jpeg1"); URL url5 = this.getClass().getResource("resources/attach.jpeg2"); Holder<String> attach1 = new Holder<>(IOUtils.toString(url1.openStream())); Holder<String> attach2 = new Holder<>(IOUtils.toString(url2.openStream())); Holder<String> attach3 = new Holder<>(IOUtils.toString(url3.openStream())); Holder<byte[]> attach4 = new Holder<>(IOUtils.readBytesFromStream(url4.openStream())); Holder<byte[]> attach5 = new Holder<>(IOUtils.readBytesFromStream(url5.openStream())); org.apache.cxf.swa_nomime.types.VoidRequest request = new org.apache.cxf.swa_nomime.types.VoidRequest(); org.apache.cxf.swa_nomime.types.OutputResponseAll response = port.echoAllAttachmentTypes(request, attach1, attach2, attach3, attach4, attach5); assertNotNull(response); }
Example 19
Source File: SwAServiceImpl.java From cxf with Apache License 2.0 | 5 votes |
public void echoDataRef(Holder<DataStruct> data) { try { InputStream bis = null; bis = data.value.getDataRef().getDataSource().getInputStream(); byte[] b = new byte[6]; bis.read(b, 0, 6); String string = IOUtils.newStringFromBytes(b); ByteArrayDataSource source = new ByteArrayDataSource(("test" + string).getBytes(), "application/octet-stream"); data.value.setDataRef(new DataHandler(source)); } catch (IOException e) { e.printStackTrace(); } }
Example 20
Source File: AbstractTypeTestClient.java From cxf with Apache License 2.0 | 4 votes |
protected boolean equals(byte[] x, byte[] y) { String xx = IOUtils.newStringFromBytes(x); String yy = IOUtils.newStringFromBytes(y); return xx.equals(yy); }