当前位置: 首页>>代码示例>>Java>>正文


Java StreamUtils类代码示例

本文整理汇总了Java中org.springframework.util.StreamUtils的典型用法代码示例。如果您正苦于以下问题:Java StreamUtils类的具体用法?Java StreamUtils怎么用?Java StreamUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StreamUtils类属于org.springframework.util包,在下文中一共展示了StreamUtils类的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);
	}
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:23,代码来源:PolicySerializationUnitTests.java

示例3: updateResponse

import org.springframework.util.StreamUtils; //导入依赖的package包/类
private void updateResponse(String requestURI, ContentCachingResponseWrapper responseWrapper) throws IOException {
	try {
		HttpServletResponse rawResponse = (HttpServletResponse) responseWrapper.getResponse();
		byte[] body = responseWrapper.getContentAsByteArray();
		ServletOutputStream outputStream = rawResponse.getOutputStream();
		if (rawResponse.isCommitted()) {
			if (body.length > 0) {
				StreamUtils.copy(body, outputStream);
			}
		} else {
			if (body.length > 0) {
				rawResponse.setContentLength(body.length);
				StreamUtils.copy(body, rawResponse.getOutputStream());
			}
		}
		finishResponse(outputStream, body);
	} catch (Exception ex) {
		logger.error("请求地址为" + requestURI + "的连接返回报文失败,原因是{}", ex.getMessage());
	}
}
 
开发者ID:wengwh,项目名称:plumdo-stock,代码行数:21,代码来源:RequestLogFilter.java

示例4: write

import org.springframework.util.StreamUtils; //导入依赖的package包/类
@Override
public void write(InputStream inputStream, String destination) throws IOException {
	String[] tokens = getBucketAndObjectFromPath(destination);
	Assert.state(tokens.length == 2, "Can only write to files, not buckets.");

	BlobInfo gcsBlobInfo = BlobInfo.newBuilder(BlobId.of(tokens[0], tokens[1])).build();

	try (InputStream is = inputStream) {
		try (WriteChannel channel = this.gcs.writer(gcsBlobInfo)) {
			channel.write(ByteBuffer.wrap(StreamUtils.copyToByteArray(is)));
		}
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:14,代码来源:GcsSession.java

示例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 set('requestEntity'): "+ body;
		body = body.toUpperCase();
		context.set("requestEntity", new ByteArrayInputStream(body.getBytes("UTF-8")));
	}
	catch (IOException e) {
		rethrowRuntimeException(e);
	}
	return null;
}
 
开发者ID:spring-cloud-samples,项目名称:sample-zuul-filters,代码行数:18,代码来源:UppercaseRequestEntityFilter.java

示例6: testMustasche

import org.springframework.util.StreamUtils; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testMustasche() throws IOException {
	Yaml yaml = new Yaml();
	Map model = (Map) yaml.load(valuesResource.getInputStream());
	String templateAsString = StreamUtils.copyToString(nestedMapResource.getInputStream(),
			Charset.defaultCharset());
	Template mustacheTemplate = Mustache.compiler().compile(templateAsString);
	String resolvedYml = mustacheTemplate.execute(model);
	Map map = (Map) yaml.load(resolvedYml);

	logger.info("Resolved yml = " + resolvedYml);
	assertThat(map).containsKeys("apiVersion", "deployment");
	Map deploymentMap = (Map) map.get("deployment");
	assertThat(deploymentMap).contains(entry("name", "time"))
			.contains(entry("count", 10));
	Map applicationProperties = (Map) deploymentMap.get("applicationProperties");
	assertThat(applicationProperties).contains(entry("log.level", "DEBUG"), entry("server.port", 8089));
	Map deploymentProperties = (Map) deploymentMap.get("deploymentProperties");
	assertThat(deploymentProperties).contains(entry("app.time.producer.partitionKeyExpression", "payload"),
			entry("app.log.spring.cloud.stream.bindings.input.consumer.maxAttempts", 5));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:23,代码来源:PackageTemplateTests.java

示例7: testInvalidVersions

import org.springframework.util.StreamUtils; //导入依赖的package包/类
@Test
public void testInvalidVersions() throws IOException {
	UploadRequest uploadRequest = new UploadRequest();
	uploadRequest.setRepoName("local");
	uploadRequest.setName("log");
	uploadRequest.setVersion("abc");
	uploadRequest.setExtension("zip");
	Resource resource = new ClassPathResource("/org/springframework/cloud/skipper/server/service/log-9.9.9.zip");
	assertThat(resource.exists()).isTrue();
	byte[] originalPackageBytes = StreamUtils.copyToByteArray(resource.getInputStream());
	assertThat(originalPackageBytes).isNotEmpty();
	Assert.isTrue(originalPackageBytes.length != 0,
			"PackageServiceTests.Assert.isTrue: Package file as bytes must not be empty");
	assertInvalidPackageVersion(uploadRequest);
	uploadRequest.setVersion("1abc");
	assertInvalidPackageVersion(uploadRequest);
	uploadRequest.setVersion("1.abc.2");
	assertInvalidPackageVersion(uploadRequest);
	uploadRequest.setVersion("a.b.c");
	assertInvalidPackageVersion(uploadRequest);
	uploadRequest.setVersion("a.b.c.2");
	assertInvalidPackageVersion(uploadRequest);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:24,代码来源:PackageServiceTests.java

示例8: writeForm

import org.springframework.util.StreamUtils; //导入依赖的package包/类
private void writeForm(MultiValueMap<String, String> form, MediaType contentType,
    HttpOutputMessage outputMessage) throws IOException {

    Charset charset;
    if (contentType != null) {
        outputMessage.getHeaders().setContentType(contentType);
        charset = contentType.getCharset() != null ? contentType.getCharset() : this.defaultCharset;
    } else {
        outputMessage.getHeaders().setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        charset = this.defaultCharset;
    }
    StringBuilder builder = new StringBuilder();
    buildByNames(form, charset, builder);
    final byte[] bytes = builder.toString().getBytes(charset.name());
    outputMessage.getHeaders().setContentLength(bytes.length);

    if (outputMessage instanceof StreamingHttpOutputMessage) {
        StreamingHttpOutputMessage streamingOutputMessage = (StreamingHttpOutputMessage) outputMessage;
        streamingOutputMessage.setBody(outputStream -> StreamUtils.copy(bytes, outputStream));
    } else {
        StreamUtils.copy(bytes, outputMessage.getBody());
    }
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:24,代码来源:MultipartMixedConverter.java

示例9: writeInternal

import org.springframework.util.StreamUtils; //导入依赖的package包/类
@Override
protected void writeInternal(Resource resource, HttpOutputMessage outputMessage)
		throws IOException, HttpMessageNotWritableException {

	InputStream in = resource.getInputStream();
	try {
		StreamUtils.copy(in, outputMessage.getBody());
	}
	finally {
		try {
			in.close();
		}
		catch (IOException ex) {
		}
	}
	outputMessage.getBody().flush();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:ResourceHttpMessageConverter.java

示例10: getBodyInternal

import org.springframework.util.StreamUtils; //导入依赖的package包/类
@Override
protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
	if (this.body == null) {
		if (this.outputStreaming) {
			int contentLength = (int) headers.getContentLength();
			if (contentLength >= 0) {
				this.connection.setFixedLengthStreamingMode(contentLength);
			}
			else {
				this.connection.setChunkedStreamingMode(this.chunkSize);
			}
		}
		writeHeaders(headers);
		this.connection.connect();
		this.body = this.connection.getOutputStream();
	}
	return StreamUtils.nonClosing(this.body);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:SimpleStreamingAsyncClientHttpRequest.java

示例11: getBodyInternal

import org.springframework.util.StreamUtils; //导入依赖的package包/类
@Override
protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
	if (this.body == null) {
		if(this.outputStreaming) {
			int contentLength = (int) headers.getContentLength();
			if (contentLength >= 0) {
				this.connection.setFixedLengthStreamingMode(contentLength);
			}
			else {
				this.connection.setChunkedStreamingMode(this.chunkSize);
			}
		}
		writeHeaders(headers);
		this.connection.connect();
		this.body = this.connection.getOutputStream();
	}
	return StreamUtils.nonClosing(this.body);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:SimpleStreamingClientHttpRequest.java

示例12: execute

import org.springframework.util.StreamUtils; //导入依赖的package包/类
@Override
public ClientHttpResponse execute(HttpRequest request, byte[] body) throws IOException {
	if (iterator.hasNext()) {
		ClientHttpRequestInterceptor nextInterceptor = iterator.next();
		return nextInterceptor.intercept(request, body, this);
	}
	else {
		ClientHttpRequest delegate = requestFactory.createRequest(request.getURI(), request.getMethod());

		delegate.getHeaders().putAll(request.getHeaders());

		if (body.length > 0) {
			StreamUtils.copy(body, delegate.getBody());
		}
		return delegate.execute();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:InterceptingClientHttpRequest.java

示例13: calculate

import org.springframework.util.StreamUtils; //导入依赖的package包/类
public static Checksums calculate(InputStream content) throws IOException {
	Assert.notNull(content, "Content must not be null");
	try {
		DigestInputStream sha1 = new DigestInputStream(content,
				MessageDigest.getInstance("SHA-1"));
		DigestInputStream md5 = new DigestInputStream(sha1,
				MessageDigest.getInstance("MD5"));
		StreamUtils.drain(md5);
		return new Checksums(getDigestHex(sha1), getDigestHex(md5));
	}
	catch (Exception ex) {
		throw new RuntimeException(ex);
	}
	finally {
		content.close();
	}
}
 
开发者ID:spring-io,项目名称:artifactory-resource,代码行数:18,代码来源:Checksums.java

示例14: TensorFlowService

import org.springframework.util.StreamUtils; //导入依赖的package包/类
public TensorFlowService(Resource modelLocation) throws IOException {
	try (InputStream is = modelLocation.getInputStream()) {
		if (logger.isInfoEnabled()) {
			logger.info("Loading TensorFlow graph model: " + modelLocation);
		}
		graph = new Graph();
		graph.importGraphDef(StreamUtils.copyToByteArray(is));
	}
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:tensorflow,代码行数:10,代码来源:TensorFlowService.java

示例15: 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;
}
 
开发者ID:openmrs,项目名称:openmrs-contrib-addonindex,代码行数:17,代码来源:FetchDetailsToIndex.java


注:本文中的org.springframework.util.StreamUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。