本文整理了Java中org.mule.runtime.core.api.util.IOUtils.toString()
方法的一些代码示例,展示了IOUtils.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.toString()
方法的具体详情如下:
包路径:org.mule.runtime.core.api.util.IOUtils
类名称:IOUtils
方法名:toString
[英]This method wraps org.apache.commons.io.IOUtils' toString(InputStream)
method but catches any IOException and wraps it into a RuntimeException.
[中]这个方法包装了组织。阿帕奇。平民木卫一。IOUtils'toString(InputStream)
方法,但捕获任何IOException并将其包装为RuntimeException。
代码示例来源:origin: mulesoft/mule
private String getDescriptorContent(File jsonFile) {
try (InputStream stream = new FileInputStream(jsonFile)) {
return IOUtils.toString(stream);
} catch (IOException e) {
throw new IllegalArgumentException(format("Could not read extension describer on artifact '%s'",
jsonFile.getAbsolutePath()),
e);
}
}
代码示例来源:origin: mulesoft/mule
@Override
public MessageDispatcher connect() throws ConnectionException {
return request -> {
try {
URL resource = Thread.currentThread().getContextClassLoader().getResource("test-http-response.xml");
String response = String.format(IOUtils.toString(resource.openStream()), getResponseWord());
return new DispatchingResponse(new ByteArrayInputStream(response.getBytes()), singletonMap("Content-Type", "text/xml"));
} catch (Exception e) {
throw new RuntimeException("Something went wrong when getting fake test response", e);
}
};
}
代码示例来源:origin: mulesoft/mule
MulePluginBasedLoaderFinder(InputStream json) {
try {
this.mulePlugin = mulePluginSerializer.deserialize(IOUtils.toString(json));
} finally {
closeQuietly(json);
}
}
代码示例来源:origin: mulesoft/mule
@OnError
public void onError(@InputJsonType(schema = "person-schema.json") InputStream person, SourceCallbackContext cc) {
onErrorResult = IOUtils.toString(person);
}
代码示例来源:origin: mulesoft/mule
@Test
public void testReadRootFile() throws IOException {
String rootResource = "root-resource.txt";
URL url = getURL(rootResource);
InputStream actualInputStream = url.openStream();
assertThat(actualInputStream, notNullValue());
String expectedRootResourceContent = org.apache.commons.io.IOUtils.toString(getClass().getClassLoader()
.getResource(new File(MULE_MODULE_ARTIFACT_PLUGIN + separator + rootResource).getPath()));
assertThat(IOUtils.toString(actualInputStream), is(expectedRootResourceContent));
}
代码示例来源:origin: mulesoft/mule
@Test
public void convertsToStringWithEncoding() throws Exception {
final Charset encoding = forName("EUC-JP");
final String encodedText = "\u3053";
InputStream in = new ByteArrayInputStream(encodedText.getBytes(encoding));
String converted = IOUtils.toString(in, encoding);
assertThat(converted, equalTo(encodedText));
}
}
代码示例来源:origin: mulesoft/mule
@Test
public void testReadElementWithinJar() throws IOException {
String file = "lib" + File.separator + "test-jar-with-resources.jar" + SEPARATOR + "test-resource-2.txt";
URL url = getURL(file);
InputStream actualInputStream = url.openStream();
assertThat(actualInputStream, notNullValue());
assertThat(IOUtils.toString(actualInputStream), is("Just some text"));
}
代码示例来源:origin: mulesoft/mule
public List<String> getPets(@Connection PetStoreClient client,
@Config PetStoreConnector config,
String ownerName,
@Optional InputStream ownerSignature) {
if (ownerSignature != null) {
ownerName += IOUtils.toString(ownerSignature);
}
return client.getPets(ownerName, config);
}
代码示例来源:origin: mulesoft/mule
@Test
public void testClassloaderWithMulePluginUrls() throws IOException {
URL jarURL = getURL("lib" + File.separator + "test-jar-with-resources.jar" + SEPARATOR);
URLClassLoader urlClassLoader = new URLClassLoader(new URL[] {jarURL});
// looking for resource that's located in the jarURL (zip within zip scenario)
InputStream testResourceWithinZipInputStream = urlClassLoader.getResourceAsStream("test-resource-2.txt");
assertThat(testResourceWithinZipInputStream, notNullValue());
assertThat(IOUtils.toString(testResourceWithinZipInputStream), is("Just some text"));
}
代码示例来源:origin: mulesoft/mule
private void assertConsumedRepeatableInputStream(CursorStreamProvider payload, TypedValue value) {
Object responsePayload = value.getValue();
assertThat(responsePayload, is(not(sameInstance(payload))));
assertThat(responsePayload, is(instanceOf(ByteArrayCursorStreamProvider.class)));
assertThat(IOUtils.toString((CursorStreamProvider) responsePayload), equalTo(TEST_PAYLOAD));
}
代码示例来源:origin: mulesoft/mule
@Test
public void generate() throws Exception {
GeneratedResource resource = resourceFactory.generateResource(extensionModel).get();
assertThat(resource.getPath(), equalTo(RESOURCE_NAME));
XMLUnit.setIgnoreWhitespace(true);
String expected = IOUtils.toString(currentThread().getContextClassLoader().getResource(RESOURCE_NAME).openStream());
XMLUnit.compareXML(expected, new String(resource.getContent()));
}
}
代码示例来源:origin: mulesoft/mule
@Test
public void handleNullEvent() throws MuleException {
TypedValue evaluate = muleContext.getExpressionManager().evaluate("%dw 2.0\noutput application/json\n---\n{a: 1}");
ByteArrayBasedCursorStreamProvider value = (ByteArrayBasedCursorStreamProvider) evaluate.getValue();
String expected = "{\n" +
" \"a\": 1\n" +
"}";
assertThat(IOUtils.toString(value), is(expected));
}
}
代码示例来源:origin: mulesoft/mule
@Test
public void decodeWithoutUnzipping() throws Exception {
final String payload = RandomStringUtils.randomAlphabetic(1024);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(payload.getBytes());
GZIPCompressorInputStream gzipCompressorInputStream = new GZIPCompressorInputStream(byteArrayInputStream);
String encoded = Base64.encodeBytes(IOUtils.toByteArray(gzipCompressorInputStream), Base64.DONT_BREAK_LINES);
GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(Base64.decodeWithoutUnzipping(encoded)));
assertThat(IOUtils.toString(gzipInputStream), is(payload));
}
}
代码示例来源:origin: mulesoft/mule
private Object evaluateHeaders(InputStream headers) {
String hs = IOUtils.toString(headers);
BindingContext context = BindingContext.builder().addBinding("payload", new TypedValue<>(hs, DataType.XML_STRING)).build();
return expressionExecutor.evaluate("%dw 2.0 \n"
+ "output application/java \n"
+ "---\n"
+ "payload.headers mapObject (value, key) -> {\n"
+ " '$key' : write((key): value, \"application/xml\")\n"
+ "}", context).getValue();
}
代码示例来源:origin: mulesoft/mule
@Test
public void testSetPayloadHardcodedFileProperty() throws Exception {
CoreEvent muleEvent = flowRunner("testSetPayloadHardcodedFileProperty").run();
final String expectedContent =
IOUtils.toString(currentThread().getContextClassLoader().getResourceAsStream("modules/module-properties-file.txt"))
.trim();
assertThat(muleEvent.getMessage().getPayload().getValue(), is(
expectedContent));
}
}
代码示例来源:origin: mulesoft/mule
@Test
public void persistDocumentation() throws Exception {
InputStream in = getClass().getResourceAsStream(expectedProductPath);
assertThat(in, is(notNullValue()));
String expectedXml = IOUtils.toString(in);
TestProcessor processor = new TestProcessor(extensionClass);
doCompile(processor);
ExtensionDocumentationResourceGenerator generator = new ExtensionDocumentationResourceGenerator();
GeneratedResource resource = generator.generateResource(processor.getExtensionModel())
.orElseThrow(() -> new RuntimeException("No Documentation Generated"));
compareXML(expectedXml, new String(resource.getContent()));
}
代码示例来源:origin: mulesoft/mule
@Test
public void getJavaObjectFromStringJsonProperty() throws MuleException {
AttributeEvaluator attributeEvaluator = getAttributeEvaluator("#[payload.host]", OBJECT);
CoreEvent event = newEvent(HOST_PORT_JSON, APPLICATION_JSON);
Object resolveValue = attributeEvaluator.resolveValue(event);
assertThat(IOUtils.toString((InputStream) ((CursorProvider) resolveValue).openCursor()), is("\"0.0.0.0\""));
}
代码示例来源:origin: mulesoft/mule
@Test
public void typedValueForInputStream() throws Exception {
CoreEvent event = flowRunner("typedValueForInputStream").run();
TypedValue jsonObject = (TypedValue) event.getMessage().getPayload().getValue();
assertThat(IOUtils.toString((InputStream) jsonObject.getValue()), is(JSON_OBJECT));
assertThat(jsonObject.getDataType(), is(like(jsonObject.getDataType().getType(), APPLICATION_JSON, UTF8)));
}
代码示例来源:origin: mulesoft/mule
@Test
public void xmlOutput() throws Exception {
Object payload = flowRunner("output").keepStreamsOpen().run().getMessage().getPayload().getValue();
assertThat(IOUtils.toString(((CursorStreamProvider) payload).openCursor()), is(XML_VALUE));
}
代码示例来源:origin: mulesoft/mule
@Test
public void jsonOutput() throws Exception {
Object payload = flowRunner("jsonOutput").keepStreamsOpen().run().getMessage().getPayload().getValue();
assertEqualJsons(IOUtils.toString(((CursorStreamProvider) payload).openCursor()), JSON_VALUE);
}
内容来源于网络,如有侵权,请联系作者删除!