List of usage examples for org.apache.commons.io FileUtils copyFile
public static void copyFile(File srcFile, File destFile) throws IOException
From source file:hudson.scm.credential.SshPublicKeyCredential.java
/** * @param keyFile stores SSH private key. The file will be copied. *///from w w w . j av a2 s . c o m public SshPublicKeyCredential(String userName, String passphrase, File keyFile) throws SVNException { this.userName = userName; this.passphrase = Scrambler.scramble(passphrase); SecureRandom r = new SecureRandom(); StringBuilder buf = new StringBuilder(); for (int i = 0; i < 16; i++) { buf.append(Integer.toHexString(r.nextInt(16))); } this.id = buf.toString(); try { File savedKeyFile = getKeyFile(); System.out.println(keyFile.getAbsolutePath()); System.out.println(savedKeyFile.getAbsolutePath()); FileUtils.copyFile(keyFile, savedKeyFile); setFilePermissions(savedKeyFile, "600"); } catch (IOException e) { throw new SVNException(SVNErrorMessage.create(SVNErrorCode.AUTHN_CREDS_UNAVAILABLE, Messages.SshPublicKeyCredential_private_key_save_error()), e); } }
From source file:com.khubla.antlr4formatter.Antlr4Formatter.java
static void formatFile(File inputFile, File outputFile) throws Exception { /*/*from w ww .j av a 2 s. c o m*/ * filenames */ if (true == inputFile.exists()) { /* * temp file */ final File tempFile = File.createTempFile(inputFile.getName(), ".g4"); /* * show the filename */ System.out.println("Formatting: " + inputFile.getName()); /* * format */ format(new FileInputStream(inputFile), new FileOutputStream(tempFile)); /* * copy file */ FileUtils.copyFile(tempFile, outputFile); tempFile.delete(); } else { throw new Exception("Unable to find: '" + inputFile + "'"); } }
From source file:com.thoughtworks.go.config.ConfigCipherUpdater.java
public void migrate() { File cipherFile = systemEnvironment.getDESCipherFile(); String timestamp = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(timeProvider.currentTime()); File backupCipherFile = new File(systemEnvironment.getConfigDir(), "cipher.original." + timestamp); File configFile = new File(systemEnvironment.getCruiseConfigFile()); File backupConfigFile = new File(configFile.getParentFile(), configFile.getName() + ".original." + timestamp); try {/*from w w w . j ava 2 s . c o m*/ if (!cipherFile.exists() || !FileUtils.readFileToString(cipherFile, UTF_8).equals(FLAWED_VALUE)) { return; } LOGGER.info("Found unsafe cipher {} on server, Go will make an attempt to rekey", FLAWED_VALUE); FileUtils.copyFile(cipherFile, backupCipherFile); LOGGER.info("Old cipher was successfully backed up to {}", backupCipherFile.getAbsoluteFile()); FileUtils.copyFile(configFile, backupConfigFile); LOGGER.info("Old config was successfully backed up to {}", backupConfigFile.getAbsoluteFile()); String oldCipher = FileUtils.readFileToString(backupCipherFile, UTF_8); new DESCipherProvider(systemEnvironment).resetCipher(); String newCipher = FileUtils.readFileToString(cipherFile, UTF_8); if (newCipher.equals(oldCipher)) { LOGGER.warn("Unable to generate a new safe cipher. Your cipher is unsafe."); FileUtils.deleteQuietly(backupCipherFile); FileUtils.deleteQuietly(backupConfigFile); return; } Document document = new SAXBuilder().build(configFile); List<String> encryptedAttributes = Arrays.asList("encryptedPassword", "encryptedManagerPassword"); List<String> encryptedNodes = Arrays.asList("encryptedValue"); XPathFactory xPathFactory = XPathFactory.instance(); for (String attributeName : encryptedAttributes) { XPathExpression<Element> xpathExpression = xPathFactory .compile(String.format("//*[@%s]", attributeName), Filters.element()); List<Element> encryptedPasswordElements = xpathExpression.evaluate(document); for (Element element : encryptedPasswordElements) { Attribute encryptedPassword = element.getAttribute(attributeName); encryptedPassword.setValue(reEncryptUsingNewKey(decodeHex(oldCipher), decodeHex(newCipher), encryptedPassword.getValue())); LOGGER.debug("Replaced encrypted value at {}", element.toString()); } } for (String nodeName : encryptedNodes) { XPathExpression<Element> xpathExpression = xPathFactory.compile(String.format("//%s", nodeName), Filters.element()); List<Element> encryptedNode = xpathExpression.evaluate(document); for (Element element : encryptedNode) { element.setText( reEncryptUsingNewKey(decodeHex(oldCipher), decodeHex(newCipher), element.getValue())); LOGGER.debug("Replaced encrypted value at {}", element.toString()); } } try (FileOutputStream fileOutputStream = new FileOutputStream(configFile)) { XmlUtils.writeXml(document, fileOutputStream); } LOGGER.info("Successfully re-encrypted config"); } catch (Exception e) { LOGGER.error("Re-keying of cipher failed with error: [{}]", e.getMessage(), e); if (backupCipherFile.exists()) { try { FileUtils.copyFile(backupCipherFile, cipherFile); } catch (IOException e1) { LOGGER.error( "Could not replace the cipher file [{}] with original one [{}], please do so manually. Error: [{}]", cipherFile.getAbsolutePath(), backupCipherFile.getAbsolutePath(), e.getMessage(), e); bomb(e1); } } } }
From source file:FileTransferPackage.ConfigFileUpload.java
public String uploadRootAACredentials() { String path = getServletRequest().getSession().getServletContext().getRealPath("/"); File certFile = new File(path + "AA/Certs/Root_AA/root_cert.pem"); File publicFile = new File(path + "AA/Keystore/Root_AA/publicKey.key"); File privateFile = new File(path + "AA/Keystore/Root_AA/privateKey.key"); if (certFile.exists()) { certFile.delete();//from w w w. ja v a 2 s .c o m } if (publicFile.exists()) { publicFile.delete(); } if (privateFile.exists()) { privateFile.delete(); } try { FileUtils.copyFile(getRootCertFile(), certFile); FileUtils.copyFile(getRootPubFile(), publicFile); FileUtils.copyFile(getRootPrivFile(), privateFile); } catch (IOException ex) { Logger.getLogger(ConfigFileUpload.class.getName()).log(Level.SEVERE, null, ex); } return SUCCESS; }
From source file:com.galenframework.api.PageDump.java
public void exportAllScreenshots(Browser browser, File reportFolder) throws IOException { File screenshotOriginalFile = browser.createScreenshot(); FileUtils.copyFile(screenshotOriginalFile, new File(reportFolder.getAbsolutePath() + File.separator + "page.png")); BufferedImage image = Rainbow4J.loadImage(screenshotOriginalFile.getAbsolutePath()); File objectsFolder = new File(reportFolder.getAbsolutePath() + File.separator + "objects"); objectsFolder.mkdirs();/*from w w w .j av a 2 s.co m*/ for (Element element : items.values()) { if (element.hasImage) { int[] area = element.getArea(); try { BufferedImage subImage = image.getSubimage(area[0], area[1], area[2], area[3]); Rainbow4J.saveImage(subImage, new File( objectsFolder.getAbsolutePath() + File.separator + element.getObjectName() + ".png")); } catch (Exception ex) { LOG.error("Got error during saving image", ex); } } } }
From source file:com.dhenton9000.file.FileWatchers.java
/** * generate a runnable that will process a file on a thread * * @param file file to process//w w w. ja va2 s . c o m * @return the constructed runnable */ private Runnable getRunnable(final File file, final IReaderSink sink) { return new Runnable() { @Override public void run() { //move from inputDir to tempDir File tempFile = new File(tempDir, FilenameUtils.getBaseName(file.getAbsolutePath()) + "_tmp.txt"); String simpleName = FilenameUtils.getName(tempFile.getAbsolutePath()); try { FileUtils.copyFile(file, tempFile); FileUtils.deleteQuietly(file); } catch (IOException ex) { LOG.error("problem moving to temp " + ex.getMessage()); } LOG.info("$#$move done " + simpleName); try { LOG.info("$#$processing " + tempFile.getAbsolutePath()); FileReader in = new FileReader(tempFile); BufferedReader bRead = new BufferedReader(in); String line = bRead.readLine(); //skipping the header //output the line while (line != null) { line = bRead.readLine(); if (line != null) { LOG.debug(simpleName + " " + line.substring(0, 10) + "..."); if (sink != null) { sink.report(line); } } } // parse each file into individual events // } catch (Exception e) { LOG.error("$#$tried to process csv " + e.getClass().getName() + " " + e.getMessage()); } } }; }
From source file:com.perceptive.epm.perkolcentral.bl.ImageNowLicenseBL.java
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.SERIALIZABLE, rollbackFor = ExceptionWrapper.class) public void addImageNowLicenseRequest(Imagenowlicenses imagenowlicenses, String groupRequestedFor, String employeeUIDWhoRequestedLicense, File sysfpFile, String originalFileName) throws ExceptionWrapper { try {//from w w w .ja v a 2 s. c o m imageNowLicenseDataAccessor.addImageNowLicense(imagenowlicenses, groupRequestedFor, employeeUIDWhoRequestedLicense); if (!new File(fileUploadPath).exists()) FileUtils.forceMkdir(new File(fileUploadPath)); File filePathForThisRequest = new File( FilenameUtils.concat(fileUploadPath, imagenowlicenses.getImageNowLicenseRequestId())); FileUtils.forceMkdir(filePathForThisRequest); File fileNameToCopy = new File( FilenameUtils.concat(filePathForThisRequest.getAbsolutePath(), originalFileName)); FileUtils.copyFile(sysfpFile, fileNameToCopy); //Send the email String messageToSend = String.format(Constants.email_license_request, imagenowlicenses.getEmployeeByRequestedByEmployeeId().getEmployeeName(), imagenowlicenses.getGroups().getGroupName(), new SimpleDateFormat("dd-MMM-yyyy").format(imagenowlicenses.getLicenseRequestedOn()), imagenowlicenses.getImageNowVersion(), imagenowlicenses.getHostname(), Long.toString(imagenowlicenses.getNumberOfLicenses())); email = new HtmlEmail(); email.setHostName(emailHost); email.setHtmlMsg(messageToSend); email.setSubject("ImageNow License Request"); //email.setFrom("ImageNowLicenseRequest@perceptivesoftware.com", "ImageNow License Request"); email.setFrom("ImageNowLicenseRequest@lexmark.com", "ImageNow License Request"); // Create the attachment EmailAttachment attachment = new EmailAttachment(); attachment.setPath(fileNameToCopy.getAbsolutePath()); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(originalFileName); attachment.setName(originalFileName); email.attach(attachment); //Send mail to scrum masters for (EmployeeBO item : employeeBL.getAllEmployeesKeyedByGroupId().get(Integer.valueOf("14"))) { email.addTo(item.getEmail(), item.getEmployeeName()); } //email.addTo("saibal.ghosh@perceptivesoftware.com","Saibal Ghosh"); email.addCc(imagenowlicenses.getEmployeeByRequestedByEmployeeId().getEmail()); email.send(); } catch (Exception ex) { throw new ExceptionWrapper(ex); } }
From source file:javafxqrgenerator.model.GeneratorModel.java
public void exportQRImageFromRecent(String destPath, File f) { File dest = new File(destPath); try {/* w w w . ja va 2s. c o m*/ if (!destPath.endsWith(".jpg")) { dest = new File(destPath + ".jpg"); } FileUtils.copyFile(f, dest); QRImage = dest.getAbsolutePath(); } catch (IOException iOException) { System.out.println(iOException); } }
From source file:com.evolveum.midpoint.provisioning.impl.manual.TestSemiManual.java
@Override public void initSystem(Task initTask, OperationResult initResult) throws Exception { super.initSystem(initTask, initResult); resource = addResource(initResult);//from ww w.java 2 s .c o m resourceType = resource.asObjectable(); FileUtils.copyFile(CSV_SOURCE_FILE, CSV_TARGET_FILE); }
From source file:file.FileOperatorTest.java
public static void test11() { long a = System.currentTimeMillis(); try {/*from w w w . jav a 2 s. c o m*/ new File(DEST_FILE).createNewFile(); FileUtils.copyFile(new File(SOURCE_FILE), new File(DEST_FILE)); } catch (IOException e) { e.printStackTrace(); } long b = System.currentTimeMillis(); System.out.println(":" + (b - a));//18460 18342 }