org.apache.cxf.helpers.IOUtils.readBytesFromStream()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(159)

本文整理了Java中org.apache.cxf.helpers.IOUtils.readBytesFromStream()方法的一些代码示例,展示了IOUtils.readBytesFromStream()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.readBytesFromStream()方法的具体详情如下:
包路径:org.apache.cxf.helpers.IOUtils
类名称:IOUtils
方法名:readBytesFromStream

IOUtils.readBytesFromStream介绍

暂无

代码示例

代码示例来源:origin: org.apache.cxf/cxf-rt-transports-http

  1. InputStream ins = ReferencingAuthenticator.class
  2. .getResourceAsStream("ReferencingAuthenticator.class");
  3. byte[] b = IOUtils.readBytesFromStream(ins);
  4. if (JavaUtils.isJava9Compatible()) {
  5. Class<?> methodHandles = Class.forName("java.lang.invoke.MethodHandles");

代码示例来源:origin: org.apache.cxf/cxf-rt-frontend-jaxws

  1. o = IOUtils.readBytesFromStream(dh.getInputStream());
  2. } catch (IOException e) {
  3. throw new Fault(e);

代码示例来源:origin: apache/cxf

  1. public byte[] getBytes() throws IOException {
  2. flush();
  3. if (inmem) {
  4. if (currentStream instanceof ByteArrayOutputStream) {
  5. return ((ByteArrayOutputStream)currentStream).toByteArray();
  6. }
  7. throw new IOException("Unknown format of currentStream");
  8. }
  9. // read the file
  10. try (InputStream fin = createInputStream(tempFile)) {
  11. return IOUtils.readBytesFromStream(fin);
  12. }
  13. }

代码示例来源:origin: org.apache.cxf/cxf-core

  1. public byte[] getBytes() throws IOException {
  2. flush();
  3. if (inmem) {
  4. if (currentStream instanceof ByteArrayOutputStream) {
  5. return ((ByteArrayOutputStream)currentStream).toByteArray();
  6. }
  7. throw new IOException("Unknown format of currentStream");
  8. }
  9. // read the file
  10. try (InputStream fin = createInputStream(tempFile)) {
  11. return IOUtils.readBytesFromStream(fin);
  12. }
  13. }

代码示例来源:origin: org.apache.cxf/cxf-api

  1. public byte[] getBytes() throws IOException {
  2. flush();
  3. if (inmem) {
  4. if (currentStream instanceof ByteArrayOutputStream) {
  5. return ((ByteArrayOutputStream)currentStream).toByteArray();
  6. } else {
  7. throw new IOException("Unknown format of currentStream");
  8. }
  9. } else {
  10. // read the file
  11. InputStream fin = createInputStream(tempFile);
  12. return IOUtils.readBytesFromStream(fin);
  13. }
  14. }

代码示例来源:origin: org.eclipse.dirigible/dirigible-api-tests

  1. private Object runTest(IJavascriptEngineExecutor executor, IRepository repository, String testModule) throws IOException, ScriptingException {
  2. try {
  3. InputStream in = AbstractApiSuiteTest.class.getResourceAsStream(IRepositoryStructure.SEPARATOR + testModule);
  4. if (in == null) {
  5. throw new IOException(IRepositoryStructure.SEPARATOR + testModule + " does not exist");
  6. }
  7. repository.createResource(IRepositoryStructure.PATH_REGISTRY_PUBLIC + IRepositoryStructure.SEPARATOR + testModule,
  8. IOUtils.readBytesFromStream(in));
  9. } catch (RepositoryWriteException e) {
  10. throw new IOException(IRepositoryStructure.SEPARATOR + testModule, e);
  11. }
  12. Object result = executor.executeServiceModule(testModule, null);
  13. return result;
  14. }
  15. }

代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs

  1. public byte[] getBytes() throws IOException {
  2. flush();
  3. if (inmem) {
  4. if (currentStream instanceof ByteArrayOutputStream) {
  5. return ((ByteArrayOutputStream)currentStream).toByteArray();
  6. } else {
  7. throw new IOException("Unknown format of currentStream");
  8. }
  9. } else {
  10. // read the file
  11. InputStream fin = createInputStream(tempFile);
  12. return IOUtils.readBytesFromStream(fin);
  13. }
  14. }

代码示例来源:origin: apache/cxf

  1. private byte[] extractMessageBody(ReaderInterceptorContext context) {
  2. try (InputStream is = context.getInputStream()) {
  3. return IOUtils.readBytesFromStream(is);
  4. } catch (IOException e) {
  5. throw new DigestFailureException("failed to validate the digest", e);
  6. }
  7. }

代码示例来源:origin: org.apache.cxf/cxf-rt-rs-security-http-signature

  1. private byte[] extractMessageBody(ReaderInterceptorContext context) {
  2. try (InputStream is = context.getInputStream()) {
  3. return IOUtils.readBytesFromStream(is);
  4. } catch (IOException e) {
  5. throw new DigestFailureException("failed to validate the digest", e);
  6. }
  7. }

代码示例来源:origin: Talend/tesb-rt-se

  1. private void verifyMultipartResponse(MultipartBody bodyResponse) throws Exception {
  2. Book jaxbBook = bodyResponse.getAttachmentObject("book1", Book.class);
  3. Book jsonBook = bodyResponse.getAttachmentObject("book2", Book.class);
  4. byte[] receivedImageBytes = bodyResponse.getAttachmentObject("image", byte[].class);
  5. InputStream is = getClass().getResourceAsStream("/java.jpg");
  6. byte[] imageBytes = IOUtils.readBytesFromStream(is);
  7. if ("JAXB".equals(jaxbBook.getName()) && 1L == jaxbBook.getId()
  8. && "JSON".equals(jsonBook.getName()) && 2L == jsonBook.getId()
  9. && Arrays.equals(imageBytes, receivedImageBytes)) {
  10. System.out.println();
  11. System.out.println("Book attachments have been successfully received");
  12. } else {
  13. throw new RuntimeException("Received Book attachment is corrupted");
  14. }
  15. }

代码示例来源:origin: org.apache.cxf/cxf-rt-rs-security-oauth2-jwt

  1. protected JweDecryptionOutput decrypt(InputStream is) throws IOException {
  2. JweDecryption theDecryptor = getInitializedDecryption();
  3. JweDecryptionOutput out = theDecryptor.decrypt(new String(IOUtils.readBytesFromStream(is), "UTF-8"));
  4. validateHeaders(out.getHeaders());
  5. return out;
  6. }

代码示例来源:origin: apache/cxf

  1. @WebMethod
  2. public int test(@WebParam(name = "request") @XmlElement(required = true) Request request) throws Exception {
  3. DataHandler dataHandler = request.getContent();
  4. InputStream inputStream = dataHandler.getInputStream();
  5. return IOUtils.readBytesFromStream(inputStream).length;
  6. }
  7. }

代码示例来源:origin: apache/cxf

  1. @Test
  2. public void testPostBookStore() throws IOException {
  3. final Response response = createWebClient("/bookstore", MediaType.TEXT_PLAIN)
  4. .type(MediaType.TEXT_PLAIN)
  5. .post(IOUtils.readBytesFromStream(getClass().getResourceAsStream("/files/books.txt")));
  6. try {
  7. assertEquals(200, response.getStatus());
  8. assertThat(response.readEntity(String.class), equalTo("Book Store uploaded: 10355 bytes"));
  9. } finally {
  10. response.close();
  11. }
  12. }

代码示例来源:origin: apache/cxf

  1. protected JweDecryptionOutput decrypt(InputStream is) throws IOException {
  2. JweCompactConsumer jwe = new JweCompactConsumer(new String(IOUtils.readBytesFromStream(is),
  3. StandardCharsets.UTF_8));
  4. JweDecryptionProvider theDecryptor = getInitializedDecryptionProvider(jwe.getJweHeaders());
  5. JweDecryptionOutput out = new JweDecryptionOutput(jwe.getJweHeaders(), jwe.getDecryptedContent(theDecryptor));
  6. JoseUtils.traceHeaders(out.getHeaders());
  7. validateHeaders(out.getHeaders());
  8. return out;
  9. }

代码示例来源:origin: apache/cxf

  1. protected JweDecryptionOutput decrypt(InputStream is) throws IOException {
  2. JweJsonConsumer c = new JweJsonConsumer(new String(IOUtils.readBytesFromStream(is),
  3. StandardCharsets.UTF_8));
  4. JweDecryptionProvider theProvider = getInitializedDecryptionProvider(c.getProtectedHeader());
  5. JweJsonEncryptionEntry entry = c.getJweDecryptionEntry(theProvider, recipientProperties);
  6. if (entry == null) {
  7. throw new JweException(JweException.Error.INVALID_JSON_JWE);
  8. }
  9. JweDecryptionOutput out = c.decryptWith(theProvider, entry);
  10. JAXRSUtils.getCurrentMessage().put(JweJsonConsumer.class, c);
  11. JAXRSUtils.getCurrentMessage().put(JweJsonEncryptionEntry.class, entry);
  12. return out;
  13. }

代码示例来源:origin: apache/cxf

  1. @Test
  2. public void testAddGetImageWebClient() throws Exception {
  3. InputStream is1 =
  4. getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg");
  5. String address = "http://localhost:" + PORT + "/bookstore/books/image";
  6. WebClient client = WebClient.create(address);
  7. client.type("multipart/mixed").accept("multipart/mixed");
  8. WebClient.getConfig(client).getRequestContext().put("support.type.as.multipart",
  9. "true");
  10. InputStream is2 = client.post(is1, InputStream.class);
  11. byte[] image1 = IOUtils.readBytesFromStream(
  12. getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"));
  13. byte[] image2 = IOUtils.readBytesFromStream(is2);
  14. assertTrue(Arrays.equals(image1, image2));
  15. }

代码示例来源:origin: apache/cxf

  1. @Test
  2. public void testOutMTOM() throws Exception {
  3. QName serviceName = new QName("http://cxf.apache.org/jms_mtom", "JMSMTOMService");
  4. QName portName = new QName("http://cxf.apache.org/jms_mtom", "MTOMPort");
  5. URL wsdl = getWSDLURL("/wsdl/jms_test_mtom.wsdl");
  6. JMSOutMTOMService service = new JMSOutMTOMService(wsdl, serviceName);
  7. JMSMTOMPortType mtom = service.getPort(portName, JMSMTOMPortType.class);
  8. URL fileURL = this.getClass().getResource("/org/apache/cxf/systest/jms/JMSClientServerTest.class");
  9. DataHandler handler1 = new DataHandler(fileURL);
  10. int size = handler1.getInputStream().available();
  11. DataHandler ret = mtom.testOutMtom();
  12. byte[] bytes = IOUtils.readBytesFromStream(ret.getInputStream());
  13. Assert.assertEquals("The response file is not same with the original file.", size, bytes.length);
  14. ((Closeable)mtom).close();
  15. }

代码示例来源:origin: apache/cxf

  1. public void handleMessage(Message message) throws Fault {
  2. InputStream is = message.getContent(InputStream.class);
  3. if (is == null) {
  4. return;
  5. }
  6. byte[] payload;
  7. try {
  8. // input stream will be closed by readBytesFromStream()
  9. payload = IOUtils.readBytesFromStream(is);
  10. assertNotNull("payload was null", payload);
  11. assertTrue("payload was EMPTY", payload.length > 0);
  12. message.setContent(InputStream.class, new ByteArrayInputStream(payload));
  13. } catch (Exception e) {
  14. String error = "Failed to read the stream properly due to " + e.getMessage();
  15. assertFalse(error, e != null);
  16. }
  17. }

代码示例来源:origin: apache/cxf

  1. @Test
  2. public void testUploadImageFromForm2() throws Exception {
  3. File file =
  4. new File(getClass().getResource("/org/apache/cxf/systest/jaxrs/resources/java.jpg")
  5. .toURI().getPath());
  6. String address = "http://localhost:" + PORT + "/bookstore/books/formimage2";
  7. WebClient client = WebClient.create(address);
  8. client.type("multipart/form-data").accept("multipart/form-data");
  9. WebClient.getConfig(client).getRequestContext().put("support.type.as.multipart",
  10. "true");
  11. MultipartBody body2 = client.post(file, MultipartBody.class);
  12. InputStream is2 = body2.getRootAttachment().getDataHandler().getInputStream();
  13. byte[] image1 = IOUtils.readBytesFromStream(
  14. getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"));
  15. byte[] image2 = IOUtils.readBytesFromStream(is2);
  16. assertTrue(Arrays.equals(image1, image2));
  17. ContentDisposition cd2 = body2.getRootAttachment().getContentDisposition();
  18. assertEquals("form-data;name=file;filename=java.jpg", cd2.toString());
  19. assertEquals("java.jpg", cd2.getParameter("filename"));
  20. }

代码示例来源:origin: apache/cxf

  1. @Test
  2. public void testMTOM() throws Exception {
  3. QName serviceName = new QName("http://cxf.apache.org/jms_mtom", "JMSMTOMService");
  4. QName portName = new QName("http://cxf.apache.org/jms_mtom", "MTOMPort");
  5. URL wsdl = getWSDLURL("/wsdl/jms_test_mtom.wsdl");
  6. JMSMTOMService service = new JMSMTOMService(wsdl, serviceName);
  7. JMSMTOMPortType mtom = service.getPort(portName, JMSMTOMPortType.class);
  8. Binding binding = ((BindingProvider)mtom).getBinding();
  9. ((SOAPBinding)binding).setMTOMEnabled(true);
  10. Holder<String> name = new Holder<>("Sam");
  11. URL fileURL = this.getClass().getResource("/org/apache/cxf/systest/jms/JMSClientServerTest.class");
  12. Holder<DataHandler> handler1 = new Holder<>();
  13. handler1.value = new DataHandler(fileURL);
  14. int size = handler1.value.getInputStream().available();
  15. mtom.testDataHandler(name, handler1);
  16. byte[] bytes = IOUtils.readBytesFromStream(handler1.value.getInputStream());
  17. Assert.assertEquals("The response file is not same with the sent file.", size, bytes.length);
  18. ((Closeable)mtom).close();
  19. }

相关文章