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


Java IOUtils.copy方法代码示例

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


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

示例1: buildMetadataGeneratorParameters

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
 * Build metadata generator parameters by passing the encryption,
 * signing and back-channel certs to the parameter generator.
 *
 * @throws Exception Thrown if cert files are missing, or metadata file inaccessible.
 */
protected void buildMetadataGeneratorParameters() throws Exception {
    final SamlIdPProperties idp = casProperties.getAuthn().getSamlIdp();
    final Resource template = this.resourceLoader.getResource("classpath:/template-idp-metadata.xml");

    String signingKey = FileUtils.readFileToString(idp.getMetadata().getSigningCertFile().getFile(), StandardCharsets.UTF_8);
    signingKey = StringUtils.remove(signingKey, BEGIN_CERTIFICATE);
    signingKey = StringUtils.remove(signingKey, END_CERTIFICATE).trim();

    String encryptionKey = FileUtils.readFileToString(idp.getMetadata().getEncryptionCertFile().getFile(), StandardCharsets.UTF_8);
    encryptionKey = StringUtils.remove(encryptionKey, BEGIN_CERTIFICATE);
    encryptionKey = StringUtils.remove(encryptionKey, END_CERTIFICATE).trim();

    try (StringWriter writer = new StringWriter()) {
        IOUtils.copy(template.getInputStream(), writer, StandardCharsets.UTF_8);
        final String metadata = writer.toString()
                .replace("${entityId}", idp.getEntityId())
                .replace("${scope}", idp.getScope())
                .replace("${idpEndpointUrl}", getIdPEndpointUrl())
                .replace("${encryptionKey}", encryptionKey)
                .replace("${signingKey}", signingKey);
        FileUtils.write(idp.getMetadata().getMetadataFile(), metadata, StandardCharsets.UTF_8);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:30,代码来源:TemplatedMetadataAndCertificatesGenerationService.java

示例2: setUp

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
  // resource file
  this.jsonResource = "org/apache/geode/security/templates/security.json";
  InputStream inputStream = ClassLoader.getSystemResourceAsStream(this.jsonResource);

  assertThat(inputStream).isNotNull();

  // non-resource file
  this.jsonFile = new File(temporaryFolder.getRoot(), "security.json");
  IOUtils.copy(inputStream, new FileOutputStream(this.jsonFile));

  // string
  this.json = FileUtils.readFileToString(this.jsonFile, "UTF-8");
  this.exampleSecurityManager = new ExampleSecurityManager();
}
 
开发者ID:ampool,项目名称:monarch,代码行数:17,代码来源:ExampleSecurityManagerTest.java

示例3: getDataSinkForOpenPgpDecryptedInlineData

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private OpenPgpDataSink<MimeBodyPart> getDataSinkForOpenPgpDecryptedInlineData() {
    return new OpenPgpDataSink<MimeBodyPart>() {
        @Override
        public MimeBodyPart processData(InputStream is) throws IOException {
            try {
                ByteArrayOutputStream decryptedByteOutputStream = new ByteArrayOutputStream();
                IOUtils.copy(is, decryptedByteOutputStream);
                TextBody body = new TextBody(new String(decryptedByteOutputStream.toByteArray()));
                return new MimeBodyPart(body, "text/plain");
            } catch (MessagingException e) {
                Timber.e(e, "MessagingException");
            }

            return null;
        }
    };
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:18,代码来源:MessageCryptoHelper.java

示例4: getConsole

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
 * Return a snapshot of the console.
 * 
 * @param subscription
 *            the valid screenshot of the console.
 * @return the valid screenshot of the console.
 */
@GET
@Path("{subscription:\\d+}/console.png")
@Produces("image/png")
public StreamingOutput getConsole(@PathParam("subscription") final int subscription) {
	final Map<String, String> parameters = subscriptionResource.getParameters(subscription);
	final VCloudCurlProcessor processor = new VCloudCurlProcessor();
	authenticate(parameters, processor);

	// Get the screen thumbnail
	return output -> {
		final String url = StringUtils.appendIfMissing(parameters.get(PARAMETER_API), "/") + "vApp/vm-" + parameters.get(PARAMETER_VM)
				+ "/screen";
		final CurlRequest curlRequest = new CurlRequest("GET", url, null, (request, response) -> {
			if (response.getStatusLine().getStatusCode() == HttpServletResponse.SC_OK) {
				// Copy the stream
				IOUtils.copy(response.getEntity().getContent(), output);
				output.flush();
			}
			return false;
		});
		processor.process(curlRequest);
	};
}
 
开发者ID:ligoj,项目名称:plugin-vm-vcloud,代码行数:31,代码来源:VCloudPluginResource.java

示例5: getAuthorizedPhoto

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@RequestMapping(value="/{eppn}/restrictedPhoto")
public void getAuthorizedPhoto(@PathVariable String eppn, HttpServletRequest request, HttpServletResponse response) throws IOException, SQLException {
	List<Card> validCards = Card.findCardsByEppnAndEtatNotEquals(eppn, Etat.REJECTED, "dateEtat", "desc").getResultList();
	if(!validCards.isEmpty()) {
		Card card = validCards.get(0);
		User user = User.findUser(eppn);
		if(user.getDifPhoto()) {
			PhotoFile photoFile = card.getPhotoFile();
			Long size = photoFile.getFileSize();
			String contentType = photoFile.getContentType();
			response.setContentType(contentType);
			response.setContentLength(size.intValue());
			IOUtils.copy(photoFile.getBigFile().getBinaryFile().getBinaryStream(), response.getOutputStream());
		}else{
			ClassPathResource noImg = new ClassPathResource(ManagerCardController.IMG_INTERDIT);
			IOUtils.copy(noImg.getInputStream(), response.getOutputStream());
		}
	}
}
 
开发者ID:EsupPortail,项目名称:esup-sgc,代码行数:20,代码来源:WsRestPhotoController.java

示例6: processFolder

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private static void processFolder(final File folder, final ZipOutputStream zipOutputStream, final int prefixLength)
        throws IOException {
    for (final File file : folder.listFiles()) {
        if (file.isFile()) {
            final ZipEntry zipEntry = new ZipEntry(file.getPath().substring(prefixLength));
            zipOutputStream.putNextEntry(zipEntry);
            try (FileInputStream inputStream = new FileInputStream(file)) {
                IOUtils.copy(inputStream, zipOutputStream);
            }
            zipOutputStream.closeEntry();
        } else if (file.isDirectory()) {
            processFolder(file, zipOutputStream, prefixLength);
        }
    }
}
 
开发者ID:Panzer1119,项目名称:JAddOn,代码行数:16,代码来源:ZipUtils.java

示例7: streamDocumentContentVersion

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public void streamDocumentContentVersion(@NotNull DocumentContentVersion documentContentVersion) {
    if (documentContentVersion.getDocumentContent() == null || documentContentVersion.getDocumentContent().getData() == null) {
        throw new CantReadDocumentContentVersionBinaryException("File content is null", documentContentVersion);
    }
    try {
        response.setHeader(HttpHeaders.CONTENT_TYPE, documentContentVersion.getMimeType());
        response.setHeader(HttpHeaders.CONTENT_LENGTH, documentContentVersion.getSize().toString());
        response.setHeader("OriginalFileName", documentContentVersion.getOriginalDocumentName());
        IOUtils.copy(documentContentVersion.getDocumentContent().getData().getBinaryStream(), response.getOutputStream(), streamBufferSize);
    } catch (Exception e) {
        throw new CantReadDocumentContentVersionBinaryException(e, documentContentVersion);
    }
}
 
开发者ID:hmcts,项目名称:document-management-store-app,代码行数:14,代码来源:DocumentContentVersionService.java

示例8: responseBody

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private String responseBody(RequestContext context) throws IOException {
  try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(STREAM_BUFFER_SIZE.get())) {
    IOUtils.copy(context.getResponseDataStream(), outputStream);
    context.setResponseBody(outputStream.toString());
    return outputStream.toString();
  }
}
 
开发者ID:ServiceComb,项目名称:ServiceComb-Company-WorkShop,代码行数:8,代码来源:CacheUpdateFilter.java

示例9: execute

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String path=req.getContextPath()+URuleServlet.URL+URL;
	String uri=req.getRequestURI();
	String resPath=uri.substring(path.length()+1);
	String p="classpath:"+resPath;
	if(p.endsWith(".js")){
		resp.setContentType("text/javascript");	
	}else if(p.endsWith(".css")){
		resp.setContentType("text/css");
	}else if(p.endsWith(".png")){
		resp.setContentType("image/png");
	}else if(p.endsWith(".jpg")){
		resp.setContentType("image/jpeg");
	}else{
		resp.setContentType("application/octet-stream");
	}
	InputStream input=applicationContext.getResource(p).getInputStream();
	OutputStream output=resp.getOutputStream();
	try{
		IOUtils.copy(input, output);			
	}finally{
		if(input!=null){
			input.close();
		}
		if(output!=null){
			output.flush();
			output.close();
		}
	}
}
 
开发者ID:youseries,项目名称:urule,代码行数:32,代码来源:ResourceLoaderServletHandler.java

示例10: copyFileToBin

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public static void copyFileToBin(String fileName, InputStream inputStream) {
	binFolder.mkdirs();
	File copy = new File(binFolder, fileName);
	try 
	{
		if(copy.exists())
			copy.delete();
		FileOutputStream outputStream = new FileOutputStream(copy);
		IOUtils.copy(inputStream, outputStream);
	} 
	catch (IOException e) {e.printStackTrace();}		
}
 
开发者ID:ObsidianSuite,项目名称:ObsidianSuite,代码行数:13,代码来源:FileHandler.java

示例11: nextPart

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public MimePart nextPart(OutputStream os) throws IOException, MessagingException {			
	MimeBodyPart bodyPart = readHeaders();
	
	if (bodyPart != null) {
		IOUtils.copy(pis, os);
		
		pis.nextPart();	
	}
	
	return bodyPart;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:12,代码来源:BigMimeMultipart.java

示例12: copyImages

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private void copyImages() throws IOException {
    File imagesDir = new File(basedir, "images");
    imagesDir.mkdirs();
    for(File file : listFiles()){
        IOUtils.copy(new FileInputStream(file), new FileOutputStream(new File(imagesDir, file.getName())));
    }
}
 
开发者ID:jmrozanec,项目名称:pdf-converter,代码行数:8,代码来源:EpubCreator.java

示例13: readStream

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private static String readStream(InputStream stream) throws IOException {
    if (stream == null) {
        return "";
    }
    try (StringWriter writer = new StringWriter()){
        IOUtils.copy(stream, writer, "UTF-8");
        return writer.toString();
    }
}
 
开发者ID:JFrogDev,项目名称:jfrog-idea-plugin,代码行数:10,代码来源:XrayImpl.java

示例14: sendImage

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private void sendImage(File file, HttpServletResponse response) throws IOException {
    response.setContentType(StringUtil.getMimeType(FilenameUtils.getExtension(file.getName())));
    InputStream in = new FileInputStream(file);
    try {
        IOUtils.copy(in, response.getOutputStream());
    } finally {
        IOUtils.closeQuietly(in);
    }
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:10,代码来源:CoverArtController.java

示例15: tagStorage

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Bean
public TagStorage tagStorage(Preferences preferences) throws Exception {
    new File(preferences.getDataDir(), "misc").mkdirs();
    File file = new File(preferences.getDataDir(), TagStorage.DOCKER_IMAGE_TAGS);
    InputStream input = getClass().getResourceAsStream("/kubernetes/base-image-mapper/docker-tagbase.json");
    FileOutputStream out = new FileOutputStream(file);

    IOUtils.copy(input, out);
    input.close();
    out.close();

    return new TagStorage(preferences);
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:14,代码来源:MapperTestConfiguration.java


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