本文整理了Java中org.apache.cxf.helpers.IOUtils.readBytesFromStream()
方法的一些代码示例,展示了IOUtils.readBytesFromStream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.readBytesFromStream()
方法的具体详情如下:
包路径:org.apache.cxf.helpers.IOUtils
类名称:IOUtils
方法名:readBytesFromStream
暂无
代码示例来源:origin: org.apache.cxf/cxf-rt-transports-http
InputStream ins = ReferencingAuthenticator.class
.getResourceAsStream("ReferencingAuthenticator.class");
byte[] b = IOUtils.readBytesFromStream(ins);
if (JavaUtils.isJava9Compatible()) {
Class<?> methodHandles = Class.forName("java.lang.invoke.MethodHandles");
代码示例来源:origin: org.apache.cxf/cxf-rt-frontend-jaxws
o = IOUtils.readBytesFromStream(dh.getInputStream());
} catch (IOException e) {
throw new Fault(e);
代码示例来源:origin: apache/cxf
public byte[] getBytes() throws IOException {
flush();
if (inmem) {
if (currentStream instanceof ByteArrayOutputStream) {
return ((ByteArrayOutputStream)currentStream).toByteArray();
}
throw new IOException("Unknown format of currentStream");
}
// read the file
try (InputStream fin = createInputStream(tempFile)) {
return IOUtils.readBytesFromStream(fin);
}
}
代码示例来源:origin: org.apache.cxf/cxf-core
public byte[] getBytes() throws IOException {
flush();
if (inmem) {
if (currentStream instanceof ByteArrayOutputStream) {
return ((ByteArrayOutputStream)currentStream).toByteArray();
}
throw new IOException("Unknown format of currentStream");
}
// read the file
try (InputStream fin = createInputStream(tempFile)) {
return IOUtils.readBytesFromStream(fin);
}
}
代码示例来源:origin: org.apache.cxf/cxf-api
public byte[] getBytes() throws IOException {
flush();
if (inmem) {
if (currentStream instanceof ByteArrayOutputStream) {
return ((ByteArrayOutputStream)currentStream).toByteArray();
} else {
throw new IOException("Unknown format of currentStream");
}
} else {
// read the file
InputStream fin = createInputStream(tempFile);
return IOUtils.readBytesFromStream(fin);
}
}
代码示例来源:origin: org.eclipse.dirigible/dirigible-api-tests
private Object runTest(IJavascriptEngineExecutor executor, IRepository repository, String testModule) throws IOException, ScriptingException {
try {
InputStream in = AbstractApiSuiteTest.class.getResourceAsStream(IRepositoryStructure.SEPARATOR + testModule);
if (in == null) {
throw new IOException(IRepositoryStructure.SEPARATOR + testModule + " does not exist");
}
repository.createResource(IRepositoryStructure.PATH_REGISTRY_PUBLIC + IRepositoryStructure.SEPARATOR + testModule,
IOUtils.readBytesFromStream(in));
} catch (RepositoryWriteException e) {
throw new IOException(IRepositoryStructure.SEPARATOR + testModule, e);
}
Object result = executor.executeServiceModule(testModule, null);
return result;
}
}
代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs
public byte[] getBytes() throws IOException {
flush();
if (inmem) {
if (currentStream instanceof ByteArrayOutputStream) {
return ((ByteArrayOutputStream)currentStream).toByteArray();
} else {
throw new IOException("Unknown format of currentStream");
}
} else {
// read the file
InputStream fin = createInputStream(tempFile);
return IOUtils.readBytesFromStream(fin);
}
}
代码示例来源:origin: apache/cxf
private byte[] extractMessageBody(ReaderInterceptorContext context) {
try (InputStream is = context.getInputStream()) {
return IOUtils.readBytesFromStream(is);
} catch (IOException e) {
throw new DigestFailureException("failed to validate the digest", e);
}
}
代码示例来源:origin: org.apache.cxf/cxf-rt-rs-security-http-signature
private byte[] extractMessageBody(ReaderInterceptorContext context) {
try (InputStream is = context.getInputStream()) {
return IOUtils.readBytesFromStream(is);
} catch (IOException e) {
throw new DigestFailureException("failed to validate the digest", e);
}
}
代码示例来源:origin: Talend/tesb-rt-se
private void verifyMultipartResponse(MultipartBody bodyResponse) throws Exception {
Book jaxbBook = bodyResponse.getAttachmentObject("book1", Book.class);
Book jsonBook = bodyResponse.getAttachmentObject("book2", Book.class);
byte[] receivedImageBytes = bodyResponse.getAttachmentObject("image", byte[].class);
InputStream is = getClass().getResourceAsStream("/java.jpg");
byte[] imageBytes = IOUtils.readBytesFromStream(is);
if ("JAXB".equals(jaxbBook.getName()) && 1L == jaxbBook.getId()
&& "JSON".equals(jsonBook.getName()) && 2L == jsonBook.getId()
&& Arrays.equals(imageBytes, receivedImageBytes)) {
System.out.println();
System.out.println("Book attachments have been successfully received");
} else {
throw new RuntimeException("Received Book attachment is corrupted");
}
}
代码示例来源:origin: org.apache.cxf/cxf-rt-rs-security-oauth2-jwt
protected JweDecryptionOutput decrypt(InputStream is) throws IOException {
JweDecryption theDecryptor = getInitializedDecryption();
JweDecryptionOutput out = theDecryptor.decrypt(new String(IOUtils.readBytesFromStream(is), "UTF-8"));
validateHeaders(out.getHeaders());
return out;
}
代码示例来源:origin: apache/cxf
@WebMethod
public int test(@WebParam(name = "request") @XmlElement(required = true) Request request) throws Exception {
DataHandler dataHandler = request.getContent();
InputStream inputStream = dataHandler.getInputStream();
return IOUtils.readBytesFromStream(inputStream).length;
}
}
代码示例来源:origin: apache/cxf
@Test
public void testPostBookStore() throws IOException {
final Response response = createWebClient("/bookstore", MediaType.TEXT_PLAIN)
.type(MediaType.TEXT_PLAIN)
.post(IOUtils.readBytesFromStream(getClass().getResourceAsStream("/files/books.txt")));
try {
assertEquals(200, response.getStatus());
assertThat(response.readEntity(String.class), equalTo("Book Store uploaded: 10355 bytes"));
} finally {
response.close();
}
}
代码示例来源:origin: apache/cxf
protected JweDecryptionOutput decrypt(InputStream is) throws IOException {
JweCompactConsumer jwe = new JweCompactConsumer(new String(IOUtils.readBytesFromStream(is),
StandardCharsets.UTF_8));
JweDecryptionProvider theDecryptor = getInitializedDecryptionProvider(jwe.getJweHeaders());
JweDecryptionOutput out = new JweDecryptionOutput(jwe.getJweHeaders(), jwe.getDecryptedContent(theDecryptor));
JoseUtils.traceHeaders(out.getHeaders());
validateHeaders(out.getHeaders());
return out;
}
代码示例来源:origin: apache/cxf
protected JweDecryptionOutput decrypt(InputStream is) throws IOException {
JweJsonConsumer c = new JweJsonConsumer(new String(IOUtils.readBytesFromStream(is),
StandardCharsets.UTF_8));
JweDecryptionProvider theProvider = getInitializedDecryptionProvider(c.getProtectedHeader());
JweJsonEncryptionEntry entry = c.getJweDecryptionEntry(theProvider, recipientProperties);
if (entry == null) {
throw new JweException(JweException.Error.INVALID_JSON_JWE);
}
JweDecryptionOutput out = c.decryptWith(theProvider, entry);
JAXRSUtils.getCurrentMessage().put(JweJsonConsumer.class, c);
JAXRSUtils.getCurrentMessage().put(JweJsonEncryptionEntry.class, entry);
return out;
}
代码示例来源:origin: apache/cxf
@Test
public void testAddGetImageWebClient() throws Exception {
InputStream is1 =
getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg");
String address = "http://localhost:" + PORT + "/bookstore/books/image";
WebClient client = WebClient.create(address);
client.type("multipart/mixed").accept("multipart/mixed");
WebClient.getConfig(client).getRequestContext().put("support.type.as.multipart",
"true");
InputStream is2 = client.post(is1, InputStream.class);
byte[] image1 = IOUtils.readBytesFromStream(
getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"));
byte[] image2 = IOUtils.readBytesFromStream(is2);
assertTrue(Arrays.equals(image1, image2));
}
代码示例来源:origin: apache/cxf
@Test
public void testOutMTOM() throws Exception {
QName serviceName = new QName("http://cxf.apache.org/jms_mtom", "JMSMTOMService");
QName portName = new QName("http://cxf.apache.org/jms_mtom", "MTOMPort");
URL wsdl = getWSDLURL("/wsdl/jms_test_mtom.wsdl");
JMSOutMTOMService service = new JMSOutMTOMService(wsdl, serviceName);
JMSMTOMPortType mtom = service.getPort(portName, JMSMTOMPortType.class);
URL fileURL = this.getClass().getResource("/org/apache/cxf/systest/jms/JMSClientServerTest.class");
DataHandler handler1 = new DataHandler(fileURL);
int size = handler1.getInputStream().available();
DataHandler ret = mtom.testOutMtom();
byte[] bytes = IOUtils.readBytesFromStream(ret.getInputStream());
Assert.assertEquals("The response file is not same with the original file.", size, bytes.length);
((Closeable)mtom).close();
}
代码示例来源:origin: apache/cxf
public void handleMessage(Message message) throws Fault {
InputStream is = message.getContent(InputStream.class);
if (is == null) {
return;
}
byte[] payload;
try {
// input stream will be closed by readBytesFromStream()
payload = IOUtils.readBytesFromStream(is);
assertNotNull("payload was null", payload);
assertTrue("payload was EMPTY", payload.length > 0);
message.setContent(InputStream.class, new ByteArrayInputStream(payload));
} catch (Exception e) {
String error = "Failed to read the stream properly due to " + e.getMessage();
assertFalse(error, e != null);
}
}
代码示例来源:origin: apache/cxf
@Test
public void testUploadImageFromForm2() throws Exception {
File file =
new File(getClass().getResource("/org/apache/cxf/systest/jaxrs/resources/java.jpg")
.toURI().getPath());
String address = "http://localhost:" + PORT + "/bookstore/books/formimage2";
WebClient client = WebClient.create(address);
client.type("multipart/form-data").accept("multipart/form-data");
WebClient.getConfig(client).getRequestContext().put("support.type.as.multipart",
"true");
MultipartBody body2 = client.post(file, MultipartBody.class);
InputStream is2 = body2.getRootAttachment().getDataHandler().getInputStream();
byte[] image1 = IOUtils.readBytesFromStream(
getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"));
byte[] image2 = IOUtils.readBytesFromStream(is2);
assertTrue(Arrays.equals(image1, image2));
ContentDisposition cd2 = body2.getRootAttachment().getContentDisposition();
assertEquals("form-data;name=file;filename=java.jpg", cd2.toString());
assertEquals("java.jpg", cd2.getParameter("filename"));
}
代码示例来源:origin: apache/cxf
@Test
public void testMTOM() throws Exception {
QName serviceName = new QName("http://cxf.apache.org/jms_mtom", "JMSMTOMService");
QName portName = new QName("http://cxf.apache.org/jms_mtom", "MTOMPort");
URL wsdl = getWSDLURL("/wsdl/jms_test_mtom.wsdl");
JMSMTOMService service = new JMSMTOMService(wsdl, serviceName);
JMSMTOMPortType mtom = service.getPort(portName, JMSMTOMPortType.class);
Binding binding = ((BindingProvider)mtom).getBinding();
((SOAPBinding)binding).setMTOMEnabled(true);
Holder<String> name = new Holder<>("Sam");
URL fileURL = this.getClass().getResource("/org/apache/cxf/systest/jms/JMSClientServerTest.class");
Holder<DataHandler> handler1 = new Holder<>();
handler1.value = new DataHandler(fileURL);
int size = handler1.value.getInputStream().available();
mtom.testDataHandler(name, handler1);
byte[] bytes = IOUtils.readBytesFromStream(handler1.value.getInputStream());
Assert.assertEquals("The response file is not same with the sent file.", size, bytes.length);
((Closeable)mtom).close();
}
内容来源于网络,如有侵权,请联系作者删除!