當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。