本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java IOUtils.copy怎么用?Java IOUtils.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.IOUtils的用法示例。
在下文中一共展示了IOUtils.copy方法的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: buildMetadataGeneratorParameters
点赞 6
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
点赞 3
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
点赞 3
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
点赞 3
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
点赞 3
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
点赞 3
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
点赞 2
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
点赞 2
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
点赞 2
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
点赞 2
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
点赞 2
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
点赞 2
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
点赞 2
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
点赞 2
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
点赞 2
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
示例16: testUploadByStream
点赞 2
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
* 使用流的方式来操作hdfs上的文件
*/
@Test
public void testUploadByStream() throws IOException {
FileSystem fileSystem = FileSystem.get(conf);
FSDataOutputStream fsDataOutputStream = fileSystem.create(new Path("/精通Python设计模式.pdf"));
FileInputStream inputStream = new FileInputStream(new File("/haoc/books/精通Python设计模式.pdf"));
IOUtils.copy(inputStream, fsDataOutputStream);
}
开发者ID:cbooy,项目名称:cakes,代码行数:11,代码来源:SimpleDemos.java
示例17: saveAttachment
点赞 2
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
* Save an uploaded file to the given target file
* @param attachment
* @param targetFile
* @throws IOException
*/
public void saveAttachment(MultipartFile attachment, File targetFile) throws IOException {
try (InputStream inputStream = attachment.getInputStream(); OutputStream outputStream = new FileOutputStream(targetFile)) {
IOUtils.copy(inputStream, outputStream);
} catch (IOException e) {
throw e;
}
}
开发者ID:xtianus,项目名称:yadaframework,代码行数:14,代码来源:YadaWebUtil.java
示例18: testAuthenticatePuTTYKeyWithWrongPassword
点赞 2
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testAuthenticatePuTTYKeyWithWrongPassword() throws Exception {
final Credentials credentials = new Credentials(
System.getProperties().getProperty("sftp.user"), ""
);
final Local key = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
try {
credentials.setIdentity(key);
new DefaultLocalTouchFeature().touch(key);
final String putty = "PuTTY-User-Key-File-2: ssh-rsa\n" +
"Encryption: aes256-cbc\n" +
"Comment: rsa-key-20121215\n" +
"Public-Lines: 4\n" +
"AAAAB3NzaC1yc2EAAAABJQAAAIB7KdUyuvGb2ne9G9YDAjaYvX/Mq6Q6ppGjbEQo\n" +
"bac66VUazxVpZsnAWikcdYAU7odkyt3jg7Nn1NgQS1a5mpXk/j77Ss5C9W4rymrU\n" +
"p32cmbgB/KIV80DnOyZyOtDWDPM0M0RRXqQvAO6TsnmsNSnBa8puMLHqCtrhvvJD\n" +
"KU+XEw==\n" +
"Private-Lines: 8\n" +
"4YMkPgLQJ9hOI1L1HsdOUnYi57tDy5h9DoPTHD55fhEYsn53h4WaHpxuZH8dTpbC\n" +
"5TcV3vYTfhh+aFBY0p/FI8L1hKfABLRxhkqkkc7xMmOGlA6HejAc8oTA3VArgSeG\n" +
"tRBuQRmBAC1Edtek/U+s8HzI2whzTw8tZoUUnT6844oc4tyCpWJUy5T8l+O3/03s\n" +
"SceJ98DN2k+L358VY8AXgPxP6NJvHvIlwmIo+PtcMWsyZegfSHEnoXN2GN4N0ul6\n" +
"298RzA9R+I3GSKKxsxUvWfOVibLq0dDM3+CTwcbmo4qvyM2xrRRLhObB2rVW07gL\n" +
"7+FZpHxf44QoQQ8mVkDJNaT1faF+h/8tCp2j1Cj5yEPHMOHGTVMyaz7gqhoMw5RX\n" +
"sfSP4ZaCGinLbouPrZN9Ue3ytwdEpmqU2MelmcZdcH6kWbLCqpWBswsxPfuhFdNt\n" +
"oYhmT2+0DKBuBVCAM4qRdA==\n" +
"Private-MAC: 40ccc8b9a7291ec64e5be0c99badbc8a012bf220";
IOUtils.copy(new StringReader(putty), key.getOutputStream(false), Charset.forName("UTF-8"));
final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch", credentials);
final SFTPSession session = new SFTPSession(host);
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
final AtomicBoolean p = new AtomicBoolean();
try {
assertFalse(new SFTPPublicKeyAuthentication(session).authenticate(host, new DisabledPasswordStore(), new DisabledLoginCallback() {
@Override
public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) throws LoginCanceledException {
p.set(true);
throw new LoginCanceledException();
}
}, new DisabledCancelCallback()));
}
catch(LoginCanceledException e) {
// Expected
}
assertTrue(p.get());
session.close();
}
finally {
key.delete();
}
}
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:52,代码来源:SFTPPublicKeyAuthenticationTest.java
示例19: doGet
点赞 2
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
String serverId = request.getParameter(CentralConstants.PARAM_SERVER_ID);
String datetime = request.getParameter(CentralConstants.PARAM_DATE_TIME);
String hashValue = request.getParameter(CentralConstants.PARAM_HASH_VALUE);
String username = request.getParameter(CentralConstants.PARAM_USERNAME);
// in case lsId parameter is provided - get learningDesignId from the responsible lesson, otherwise try to get
// it from a request as "ldId" parameter
Long lessonId = WebUtil.readLongParam(request, CentralConstants.PARAM_LESSON_ID, true);
Long learningDesignId = (lessonId == null) ? WebUtil.readLongParam(request, CentralConstants.PARAM_LEARNING_DESIGN_ID) :
lessonService.getLessonDetails(lessonId).getLearningDesignID();
if (serverId == null || datetime == null || hashValue == null || username == null) {
String msg = "Parameters missing";
log.error(msg);
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameters missing");
}
// LDEV-2196 preserve character encoding if necessary
if (request.getCharacterEncoding() == null) {
log.debug(
"request.getCharacterEncoding is empty, parsing username and courseName as 8859_1 to UTF-8...");
username = new String(username.getBytes("8859_1"), "UTF-8");
}
// get Server map
ExtServer extServer = integrationService.getExtServer(serverId);
// authenticate
Authenticator.authenticate(extServer, datetime, username, hashValue);
String imagePath = LearningDesignService.getLearningDesignSVGPath(learningDesignId);
File imageFile = new File(imagePath);
if (!imageFile.canRead()) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
boolean download = WebUtil.readBooleanParam(request, "download", false);
// should the image be downloaded or a part of page?
if (download) {
String name = learningDesignService
.getLearningDesignDTO(learningDesignId, Configuration.get(ConfigurationKeys.SERVER_LANGUAGE))
.getTitle();
name += "." + "svg";
name = FileUtil.encodeFilenameForDownload(request, name);
response.setContentType("application/x-download");
response.setHeader("Content-Disposition", "attachment;filename=" + name);
} else {
response.setContentType("image/svg+xml");
}
FileInputStream input = new FileInputStream(imagePath);
OutputStream output = response.getOutputStream();
IOUtils.copy(input, output);
IOUtils.closeQuietly(input);
IOUtils.closeQuietly(output);
} catch (Exception e) {
log.error("Problem with LearningDesignSVGServlet request", e);
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Problem with LearningDesignSVGServlet request");
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:65,代码来源:LearningDesignSVGServlet.java
示例20: createFile
点赞 2
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private static void createFile(Path fileToCreate, InputStream inputStream) throws IOException {
Files.createFile(fileToCreate);
try (OutputStream outputStream = Files.newOutputStream(fileToCreate)) {
IOUtils.copy(inputStream, outputStream);
}
}
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:7,代码来源:StreamUtil.java
注:本文中的org.apache.commons.io.IOUtils.copy方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。
来源:Java IOUtils.copy方法代码示例 - 纯净天空