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


Java StreamUtils.copy方法代码示例

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


在下文中一共展示了StreamUtils.copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: downloadWithCorrectName

import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.GET, value = "/api/v1/addon/{uid}/{version}/download")
public void downloadWithCorrectName(@PathVariable("uid") String addonUid,
                                    @PathVariable("version") String version,
                                    HttpServletResponse response) throws Exception {
	
	AddOnInfoAndVersions addOn = index.getByUid(addonUid);
	if (addOn == null) {
		response.sendError(HttpServletResponse.SC_NOT_FOUND);
		return;
	}
	Optional<AddOnVersion> addOnVersion = addOn.getVersion(new Version(version));
	if (!addOnVersion.isPresent()) {
		response.sendError(HttpServletResponse.SC_NOT_FOUND);
		return;
	}
	if (addOnVersion.get().getRenameTo() == null ||
			!addOnVersion.get().getDownloadUri().startsWith("http://mavenrepo.openmrs.org/nexus/")) {
		response.sendError(HttpServletResponse.SC_BAD_REQUEST);
		return;
	}
	Resource resource = restTemplateBuilder.build().getForObject(addOnVersion.get().getDownloadUri(), Resource.class);
	
	response.setHeader("Content-Disposition", "inline;filename=" + addOnVersion.get().getRenameTo());
	StreamUtils.copy(resource.getInputStream(), response.getOutputStream());
}
 
开发者ID:openmrs,项目名称:openmrs-contrib-addonindex,代码行数:26,代码来源:RenamingFileProxyController.java

示例6: readResource

import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
/**
     * 读取流程资源
     *
     * @param processDefinitionId 流程定义ID
     * @param resourceName        资源名称
     */
    @GetMapping(value = "/{processDefinitionId}/resource/{resourceName}")
    public void readResource(@PathVariable String processDefinitionId
            , @PathVariable String resourceName, HttpServletResponse response)
            throws Exception {
        ProcessDefinitionQuery pdq = repositoryService.createProcessDefinitionQuery();
        ProcessDefinition pd = pdq.processDefinitionId(processDefinitionId).singleResult();

        // 通过接口读取
        InputStream resourceAsStream = repositoryService.getResourceAsStream(pd.getDeploymentId(), resourceName);
        StreamUtils.copy(resourceAsStream, response.getOutputStream());

//        // 输出资源内容到相应对象
//        byte[] b = new byte[1024];
//        int len = -1;
//        while ((len = resourceAsStream.read(b, 0, 1024)) != -1) {
//            response.getOutputStream().write(b, 0, len);
//        }
    }
 
开发者ID:hs-web,项目名称:hsweb-framework,代码行数:25,代码来源:FlowableDeploymentController.java

示例7: service

import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
@Override
public void service(ServletRequest request, ServletResponse response)
		throws ServletException, IOException {
	String content = "Hello World";
	if (this.echoRequestInfo) {
		content += " scheme=" + request.getScheme();
		content += " remoteaddr=" + request.getRemoteAddr();
	}
	if (this.writeWithoutContentLength) {
		response.setContentType("text/plain");
		ServletOutputStream outputStream = response.getOutputStream();
		StreamUtils.copy(content.getBytes(), outputStream);
		outputStream.flush();
	}
	else {
		response.getWriter().write(content);
	}
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:19,代码来源:ExampleServlet.java

示例8: deserializePackageFromDatabase

import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
private Package deserializePackageFromDatabase(PackageMetadata packageMetadata) {
	// package file was uploaded to a local DB hosted repository
	Path tmpDirPath = null;
	try {
		tmpDirPath = TempFileUtils.createTempDirectory("skipper");
		File targetPath = new File(tmpDirPath + File.separator + packageMetadata.getName());
		targetPath.mkdirs();
		File targetFile = PackageFileUtils.calculatePackageZipFile(packageMetadata, targetPath);
		try {
			StreamUtils.copy(packageMetadata.getPackageFile().getPackageBytes(), new FileOutputStream(targetFile));
		}
		catch (IOException e) {
			throw new SkipperException(
					"Could not copy package file for " + packageMetadata.getName() + "-"
							+ packageMetadata.getVersion() +
							" from database to target file " + targetFile,
					e);
		}
		ZipUtil.unpack(targetFile, targetPath);
		Package pkgToReturn = this.packageReader.read(new File(targetPath, packageMetadata.getName() + "-" +
				packageMetadata.getVersion()));
		pkgToReturn.setMetadata(packageMetadata);
		return pkgToReturn;
	}
	finally {
		if (tmpDirPath != null && !FileSystemUtils.deleteRecursively(tmpDirPath.toFile())) {
			logger.warn("Temporary directory can not be deleted: " + tmpDirPath);
		}
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:31,代码来源:PackageService.java

示例9: writeText

import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
private void writeText(File target, String body) {
	try (OutputStream stream = new FileOutputStream(target)) {
		StreamUtils.copy(body, Charset.forName("UTF-8"), stream);
	}
	catch (Exception e) {
		throw new IllegalStateException("Cannot write file " + target, e);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:9,代码来源:DefaultPackageWriter.java

示例10: writeBinary

import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
private void writeBinary(File target, byte[] body) {
	try (OutputStream stream = new FileOutputStream(target)) {
		StreamUtils.copy(body, stream);
	}
	catch (Exception e) {
		throw new IllegalStateException("Cannot write file " + target, e);
	}
}
 
开发者ID:rvillars,项目名称:edoras-one-initializr,代码行数:9,代码来源:ProjectGenerator.java

示例11: getFile

import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
@RequestMapping(value = "/dashboards/{name}/image", method = RequestMethod.GET)
public void getFile(
        HttpServletRequest request,
        HttpServletResponse response,
        @PathVariable("name") String name) {

    ImageStream is = dashboardService.getDashboardImage(name);

    if(is == null) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    } else {
        response.setHeader(HttpHeaders.CACHE_CONTROL, "max-age=0, must-revalidate");
        String expectedEtag = request.getHeader(HttpHeaders.IF_NONE_MATCH);
        if(is.getEtag() != null && is.getEtag().equals(expectedEtag)) {
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        } else {
            try {
                response.setHeader(HttpHeaders.ETAG, is.getEtag());
                response.setStatus(HttpServletResponse.SC_OK);
                StreamUtils.copy(is.getImageStream(), response.getOutputStream());
            } catch (IOException e) {
                LOGGER.error("Error copying streams for dashboard " + name, e);
                response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            }
        }
    }
}
 
开发者ID:BBVA,项目名称:mirrorgate,代码行数:28,代码来源:DashboardController.java

示例12: copyBodyToResponse

import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
private void copyBodyToResponse() throws IOException {
	if (this.content.size() > 0) {
		getResponse().setContentLength(this.content.size());
		StreamUtils.copy(this.content.toByteArray(), getResponse().getOutputStream());
		this.content.reset();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:ShallowEtagHeaderFilter.java

示例13: readInternal

import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
@Override
public byte[] readInternal(Class<? extends byte[]> clazz, HttpInputMessage inputMessage) throws IOException {
	long contentLength = inputMessage.getHeaders().getContentLength();
	ByteArrayOutputStream bos =
			new ByteArrayOutputStream(contentLength >= 0 ? (int) contentLength : StreamUtils.BUFFER_SIZE);
	StreamUtils.copy(inputMessage.getBody(), bos);
	return bos.toByteArray();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:ByteArrayHttpMessageConverter.java

示例14: 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.charset;
	}
	else {
		outputMessage.getHeaders().setContentType(MediaType.APPLICATION_FORM_URLENCODED);
		charset = this.charset;
	}
	StringBuilder builder = new StringBuilder();
	for (Iterator<String> nameIterator = form.keySet().iterator(); nameIterator.hasNext();) {
		String name = nameIterator.next();
		for (Iterator<String> valueIterator = form.get(name).iterator(); valueIterator.hasNext();) {
			String value = valueIterator.next();
			builder.append(URLEncoder.encode(name, charset.name()));
			if (value != null) {
				builder.append('=');
				builder.append(URLEncoder.encode(value, charset.name()));
				if (valueIterator.hasNext()) {
					builder.append('&');
				}
			}
		}
		if (nameIterator.hasNext()) {
			builder.append('&');
		}
	}
	byte[] bytes = builder.toString().getBytes(charset.name());
	outputMessage.getHeaders().setContentLength(bytes.length);
	StreamUtils.copy(bytes, outputMessage.getBody());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:FormHttpMessageConverter.java

示例15: writeInternal

import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
@Override
protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException {
	if (this.writeAcceptCharset) {
		outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
	}
	Charset charset = getContentTypeCharset(outputMessage.getHeaders().getContentType());
	StreamUtils.copy(s, charset, outputMessage.getBody());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:StringHttpMessageConverter.java


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