本文整理汇总了Java中org.springframework.util.StreamUtils.copyToString方法的典型用法代码示例。如果您正苦于以下问题:Java StreamUtils.copyToString方法的具体用法?Java StreamUtils.copyToString怎么用?Java StreamUtils.copyToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.util.StreamUtils
的用法示例。
在下文中一共展示了StreamUtils.copyToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTest
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
private void doTest(AnnotationConfigEmbeddedWebApplicationContext context,
String resourcePath) throws Exception {
SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
ClientHttpRequest request = clientHttpRequestFactory.createRequest(
new URI("http://localhost:"
+ context.getEmbeddedServletContainer().getPort() + resourcePath),
HttpMethod.GET);
ClientHttpResponse response = request.execute();
try {
String actual = StreamUtils.copyToString(response.getBody(),
Charset.forName("UTF-8"));
assertThat(actual).isEqualTo("Hello World");
}
finally {
response.close();
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:EmbeddedServletContainerMvcIntegrationTests.java
示例2: shouldSerialize
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
@Test
public void shouldSerialize() throws Exception {
Rule rule = Rule.builder().path("secret/*")
.capabilities("create", "read", "update")
.allowedParameter("ttl", "1h", "2h").deniedParameter("password").build();
Rule another = Rule.builder().path("secret/foo")
.capabilities("create", "read", "update", "delete", "list")
.minWrappingTtl(Duration.ofMinutes(1))
.maxWrappingTtl(Duration.ofHours(1)).allowedParameter("ttl", "1h", "2h")
.deniedParameter("password").build();
Policy policy = Policy.of(rule, another);
try (InputStream is = new ClassPathResource("policy.json").getInputStream()) {
String expected = StreamUtils.copyToString(is, StandardCharsets.UTF_8);
JSONAssert.assertEquals(expected, objectMapper.writeValueAsString(policy),
JSONCompareMode.STRICT);
}
}
示例3: run
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
public Object run() {
try {
RequestContext context = getCurrentContext();
InputStream in = (InputStream) context.get("requestEntity");
if (in == null) {
in = context.getRequest().getInputStream();
}
String body = StreamUtils.copyToString(in, Charset.forName("UTF-8"));
// body = "request body modified via set('requestEntity'): "+ body;
body = body.toUpperCase();
context.set("requestEntity", new ByteArrayInputStream(body.getBytes("UTF-8")));
}
catch (IOException e) {
rethrowRuntimeException(e);
}
return null;
}
示例4: buildRequestBody
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
private void buildRequestBody(PactDslRequestWithPath pactRequest) throws IOException {
final RequestContext context = RequestContext.getCurrentContext();
String requestBody = null;
InputStream in = (InputStream) context.get("requestEntity");
if (in == null) {
in = context.getRequest().getInputStream();
}
if (in != null) {
String encoding = context.getRequest().getCharacterEncoding();
requestBody = StreamUtils.copyToString(in,
Charset.forName(encoding != null ? encoding : "UTF-8"));
}
if (requestBody != null && requestBody.length() > 0) {
pactRequest.body(requestBody);
}
}
示例5: run
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
public Object run() {
try {
RequestContext context = getCurrentContext();
InputStream in = (InputStream) context.get("requestEntity");
if (in == null) {
in = context.getRequest().getInputStream();
}
String body = StreamUtils.copyToString(in, Charset.forName("UTF-8"));
body = "request body modified via request wrapper: "+ body;
byte[] bytes = body.getBytes("UTF-8");
context.setRequest(new HttpServletRequestWrapper(getCurrentContext().getRequest()) {
@Override
public ServletInputStream getInputStream() throws IOException {
return new ServletInputStreamWrapper(bytes);
}
@Override
public int getContentLength() {
return bytes.length;
}
@Override
public long getContentLengthLong() {
return bytes.length;
}
});
}
catch (IOException e) {
rethrowRuntimeException(e);
}
return null;
}
示例6: fetchConfigXml
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
String fetchConfigXml(AddOnToIndex addOnToIndex, AddOnVersion addOnVersion) throws IOException {
logger.info("fetching config.xml from " + addOnVersion.getDownloadUri());
Resource resource = restTemplateBuilder.build().getForObject(addOnVersion.getDownloadUri(), Resource.class);
try (
InputStream inputStream = resource.getInputStream();
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(inputStream))
) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (entry.getName().equals("config.xml")) {
return StreamUtils.copyToString(zis, Charset.defaultCharset());
}
}
}
return null;
}
示例7: beforeClass
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() throws Exception {
elasticsearchServer = new EmbeddedElasticsearchServer();
elasticsearchTemplate = new ElasticsearchTemplate(elasticsearchServer.getClient());
elasticsearchTemplate.deleteIndex(INDEX_NAME);
String mappings = StreamUtils.copyToString(
ODataIntegrationTest.class.getResourceAsStream("mappings.json"),
StandardCharsets.UTF_8);
createIndex(INDEX_NAME, mappings);
waitForGreenStatus(INDEX_NAME);
indexDocument("entityId1", "entity1-source.json");
indexDocument("entityId2", "entity2-source.json");
indexDocument("entityId3", "entity3-source.json");
refresh(INDEX_NAME);
}
示例8: getEmptyWebXml
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
private String getEmptyWebXml() {
InputStream stream = TomcatEmbeddedServletContainerFactory.class
.getResourceAsStream("empty-web.xml");
Assert.state(stream != null, "Unable to read empty web.xml");
try {
try {
return StreamUtils.copyToString(stream, Charset.forName("UTF-8"));
}
finally {
stream.close();
}
}
catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:TomcatEmbeddedServletContainerFactory.java
示例9: printBanner
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
@Override
public void printBanner(Environment environment, Class<?> sourceClass,
PrintStream out) {
try {
String banner = StreamUtils.copyToString(this.resource.getInputStream(),
environment.getProperty("banner.charset", Charset.class,
Charset.forName("UTF-8")));
for (PropertyResolver resolver : getPropertyResolvers(environment,
sourceClass)) {
banner = resolver.resolvePlaceholders(banner);
}
out.println(banner);
}
catch (Exception ex) {
logger.warn("Banner not printable: " + this.resource + " (" + ex.getClass()
+ ": '" + ex.getMessage() + "')", ex);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:ResourceBanner.java
示例10: readInternal
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
/**
* ③
*/
@Override
protected DemoObj readInternal(Class<? extends DemoObj> clazz,
HttpInputMessage inputMessage) throws IOException,
HttpMessageNotReadableException {
String temp = StreamUtils.copyToString(inputMessage.getBody(),
Charset.forName("UTF-8"));
String[] tempArr = temp.split("-");
return new DemoObj(new Long(tempArr[0]), tempArr[1]);
}
示例11: testNoChange
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
@Test
public void testNoChange() throws Exception {
String initialYaml = StreamUtils.copyToString(
TestResourceUtils.qualifiedResource(getClass(), "nopassword.yaml").getInputStream(),
Charset.defaultCharset());
String result = ArgumentSanitizer.sanitizeYml(initialYaml);
assertThat(result).isEqualTo(initialYaml);
}
示例12: run
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
public Object run() {
try {
RequestContext context = getCurrentContext();
InputStream stream = context.getResponseDataStream();
String body = StreamUtils.copyToString(stream, Charset.forName("UTF-8"));
context.setResponseBody("Modified via setResponseBody(): "+body);
}
catch (IOException e) {
rethrowRuntimeException(e);
}
return null;
}
示例13: testPasswordDefaultConfig
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
@Test
public void testPasswordDefaultConfig() throws Exception {
String initialYaml = StreamUtils.copyToString(
TestResourceUtils.qualifiedResource(getClass(), "configpassword.yaml").getInputStream(),
Charset.defaultCharset());
String redactedYaml = StreamUtils.copyToString(
TestResourceUtils.qualifiedResource(getClass(), "configpasswordredacted.yaml").getInputStream(),
Charset.defaultCharset());
String result = ArgumentSanitizer.sanitizeYml(initialYaml);
assertThat(result).isEqualTo(redactedYaml);
}
示例14: getDefaultTemplate
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
private String getDefaultTemplate() {
Resource resource = new ClassPathResource("/org/springframework/cloud/skipper/io/generic-template.yml");
String genericTempateData = null;
try {
genericTempateData = StreamUtils.copyToString(resource.getInputStream(), Charset.defaultCharset());
}
catch (IOException e) {
throw new IllegalArgumentException("Can't load generic template", e);
}
return genericTempateData;
}
示例15: testNonMatchingManifestReader
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
@Test
public void testNonMatchingManifestReader() throws IOException {
String manifestYaml = StreamUtils.copyToString(
TestResourceUtils.qualifiedResource(getClass(), "erroneous-manifest.yml").getInputStream(),
Charset.defaultCharset());
try {
List<SpringCloudDeployerApplicationManifest> applicationSpecList = this.applicationManifestReader
.read(manifestYaml);
fail("Expected IllegalStateException when non matching appKinds are found");
}
catch (SkipperException e) {
assertThat(e.getMessage()).isEqualTo("No reader available to read all the kind SpringBootApp1");
}
}
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:15,代码来源:SpringCloudDeployerApplicationManifestReaderTests.java