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方法的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 filethis.jsonResource = "org/apache/geode/security/templates/security.json";InputStream inputStream = ClassLoader.getSystemResourceAsStream(this.jsonResource);assertThat(inputStream).isNotNull();// non-resource filethis.jsonFile = new File(temporaryFolder.getRoot(), "security.json");IOUtils.copy(inputStream, new FileOutputStream(this.jsonFile));// stringthis.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>() {@Overridepublic 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 thumbnailreturn 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 streamIOUtils.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() {@Overridepublic 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包/類 @Overridepublic 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" parameterLong 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 necessaryif (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 mapExtServer extServer = integrationService.getExtServer(serverId);// authenticateAuthenticator.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方法代碼示例 - 純凈天空
總結
以上是生活随笔為你收集整理的Java IOUtils.copy方法代码示例(亲测)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: springboot中使用poi导出ex
- 下一篇: 银行上下班时间是几点 周末上班时间介绍