List of usage examples for org.apache.commons.io FileUtils copyFile
public static void copyFile(File srcFile, File destFile) throws IOException
From source file:com.buddycloud.mediaserver.download.DownloadMediasInfoTest.java
private void storeFile(String id) throws Exception { File destDir = new File(configuration.getProperty(MediaServerConfiguration.MEDIA_STORAGE_ROOT_PROPERTY) + File.separator + BASE_CHANNEL); if (!destDir.mkdir()) { FileUtils.cleanDirectory(destDir); }//w w w. ja v a 2 s . c o m FileUtils.copyFile(new File(TEST_FILE_PATH + TEST_IMAGE_NAME), new File(destDir + File.separator + id)); Media media = buildMedia(id, TEST_FILE_PATH + TEST_IMAGE_NAME); dataSource.storeMedia(media); }
From source file:net.orpiske.sdm.lib.io.IOUtil.java
/** * Copies a file or directory/*from ww w . j ava2 s. com*/ * @param from the source file or directory * @param to the destination file or directory * @param overwrite whether or not to overwrite the destination file/directory * @throws IOException if the source is not found or there are access restrictions */ public static void copy(final String from, final String to, boolean overwrite) throws IOException { File fromFile = new File(from); File toFile = new File(to); if (!fromFile.exists()) { throw new IOException("File or directory not found: " + from); } if (fromFile.isDirectory()) { if (toFile.exists() && !toFile.isDirectory()) { throw new IOException("Illegal copy: trying to copy a directory into a file"); } else { FileUtils.copyDirectoryToDirectory(fromFile, toFile); } } else { if (toFile.isDirectory()) { FileUtils.copyFileToDirectory(fromFile, toFile); } else { if (toFile.exists()) { if (!overwrite) { System.out.println( "Ignoring copy from " + from + " to " + to + " because overwrite flag is not set"); return; } } FileUtils.copyFile(fromFile, toFile); } } }
From source file:com.mindquarry.desktop.workspace.conflict.ReplaceConflict.java
public void beforeUpdate() throws ClientException, IOException { File file = new File(status.getPath()); switch (action) { case UNKNOWN: // client did not set a conflict resolution log.error("AddConflict with no action set: " + status.getPath()); break;//from w w w . ja va2 s . co m case RENAME: log.info("renaming " + file.getAbsolutePath() + " to " + newName); File source = new File(status.getPath()); File destination = new File(source.getParent(), newName); if (source.isDirectory()) { FileUtils.copyDirectory(source, destination); removeDotSVNDirectories(destination.getPath()); } else { FileUtils.copyFile(source, destination); } client.add(destination.getPath(), true, true); client.remove(new String[] { file.getPath() }, null, true); break; case REPLACE: log.info("replacing with new file/folder from server: " + status.getPath()); client.revert(file.getPath(), true); if (status.getRepositoryTextStatus() == StatusKind.replaced) { FileUtils.forceDelete(file); } break; } }
From source file:mesclasses.util.FileSaveUtil.java
public static void restoreBackupFile(File file) { FileConfigurationManager conf = FileConfigurationManager.getInstance(); if (!file.exists()) { AppLogger.notif("Chargement impossible", "le fichier " + file.getName() + " n'existe pas"); return;// ww w .jav a 2 s . c o m } File currentFile = getSaveFile(); File tmpFile = new File( conf.getSaveDir() + File.separator + FileConfigurationManager.DEFAULT_SAVE_FILE_NAME + "tmp.xml"); try { FileUtils.copyFile(currentFile, tmpFile); } catch (IOException ex) { AppLogger.notif("Impossible de charger le fichier de sauvegarde", ex); return; } try { if (currentFile.exists()) { LOG.info("deleting " + currentFile.getName()); currentFile.delete(); } LOG.info("copying " + file.getName() + " to " + currentFile.getName()); FileUtils.copyFile(file, currentFile); LOG.info("Fichier de sauvegarde " + file.getName() + " charg"); } catch (Exception e) { AppLogger.notif("Impossible de charger le fichier de sauvegarde", e); if (currentFile.exists()) { currentFile.delete(); } try { FileUtils.copyFile(tmpFile, currentFile); } catch (IOException ex) { AppLogger.notif("Impossible de restaurer le fichier temporaire", e); } } finally { tmpFile.delete(); } }
From source file:com.lohika.alp.flexpilot.pagefactory.FlexPilotFactoryJAXB.java
public Object screenshot(TakesScreenshot takesScreenshot, String description) { Screenshot screenshot = factory.createScreenshot(); screenshot.setDescription(description); File tempFile = takesScreenshot.getScreenshotAs(OutputType.FILE); File attachmentFile = null;// ww w . j a va 2s . c o m try { attachmentFile = LogFileAttachment.getAttachmentFile("", "png"); FileUtils.copyFile(tempFile, attachmentFile); } catch (IOException e) { e.printStackTrace(); } if (attachmentFile != null) screenshot.setUrl(attachmentFile.getName()); return screenshot; }
From source file:com.theelix.libreexplorer.FileManager.java
private static void paste(File sourceFile, File destFile) throws IOException, FileNotCreatedException { try {//from ww w. j av a2 s . com if (sourceFile.isDirectory()) { FileUtils.copyDirectory(sourceFile, destFile); } else { FileUtils.copyFile(sourceFile, destFile); } if (isMoving) { if (sourceFile.isDirectory()) { FileUtils.deleteDirectory(sourceFile); } else { sourceFile.delete(); } } } catch (FileNotFoundException e) { e.printStackTrace(); throw new FileNotCreatedException(); } }
From source file:de.cismet.cids.custom.utils.vermessungsunterlagen.tasks.VermUntTaskNivPUebersicht.java
@Override public void performTask() throws VermessungsunterlagenTaskException { final File src = new File(VermessungsunterlagenHelper.getInstance().getProperties().getAbsPathPdfNivP()); final File dst = new File(getPath() + "/" + src.getName()); if (!dst.exists()) { try {/* w ww . java 2 s . com*/ FileUtils.copyFile(src, dst); } catch (final Exception ex) { final String message = "Beim Kopieren des NivP-Informations-PDFs kam es zu einem unerwarteten Fehler."; throw new VermessungsunterlagenTaskException(getType(), message, ex); } } final GeometryFactory geometryFactory = new GeometryFactory(); final Collection<Geometry> geometries = new ArrayList<Geometry>(getNivPoints().size()); for (final CidsBean nivPoint : getNivPoints()) { final Geometry geom = (Geometry) nivPoint.getProperty("geometrie.geo_field"); geometries.add(geom); } final Envelope envelope = geometryFactory.createGeometryCollection(geometries.toArray(new Geometry[0])) .getEnvelopeInternal(); final Coordinate center = envelope.centre(); final String landparcelcode = (String) flurstuecke.iterator().next().getProperty("alkis_id"); final AlkisProductDescription product = VermessungsunterlagenHelper .determineAlkisProduct(String.valueOf("WUP-Kommunal"), String.valueOf("NivP-bersicht"), envelope); InputStream in = null; OutputStream out = null; try { final URL url = ServerAlkisProducts.productKarteUrl(landparcelcode, product.getCode(), Double.valueOf(0).intValue(), Double.valueOf(center.x).intValue(), Double.valueOf(center.y).intValue(), product.getMassstab(), product.getMassstabMin(), product.getMassstabMax(), "", auftragsnummer, false, null); final String filename = product.getCode() + "." + landparcelcode.replace("/", "--") + ((flurstuecke.size() > 1) ? ".ua" : "") + ".pdf"; in = doGetRequest(url); out = new FileOutputStream(getPath() + "/" + filename); VermessungsunterlagenHelper.downloadStream(in, out); } catch (final Exception ex) { final String message = "Beim Herunterladen der NIVP-bersicht kam es zu einem unerwarteten Fehler."; throw new VermessungsunterlagenTaskException(getType(), message, ex); } finally { VermessungsunterlagenHelper.closeStream(in); VermessungsunterlagenHelper.closeStream(out); } }
From source file:com.thoughtworks.go.helper.HgTestRepo.java
public HgTestRepo(String workingCopyName, TemporaryFolder temporaryFolder) throws IOException { super(temporaryFolder); File tempFolder = temporaryFolder.newFolder(); remoteRepo = new File(tempFolder, "remote-repo"); remoteRepo.mkdirs();/* w w w . j a v a 2 s . co m*/ //Copy file to work around bug in hg File bundleToExtract = new File(tempFolder, "repo.bundle"); FileUtils.copyFile(new File(HG_BUNDLE_FILE), bundleToExtract); setUpServerRepoFromHgBundle(remoteRepo, bundleToExtract); File workingCopy = new File(tempFolder, workingCopyName); hgCommand = new HgCommand(null, workingCopy, "default", remoteRepo.getAbsolutePath(), null); InMemoryStreamConsumer output = inMemoryConsumer(); if (hgCommand.clone(output, new UrlArgument(remoteRepo.getAbsolutePath())) != 0) { fail("Error creating repository\n" + output.getAllOutput()); } }
From source file:gov.nih.nci.caintegrator.common.Cai2UtilTest.java
@Test public void testZipAndDeleteDirectory() throws IOException { FileManagerImpl fileManager = new FileManagerImpl(); fileManager.setConfigurationHelper(configurationHelper); File tempDirectory = fileManager.getNewTemporaryDirectory("cai2UtilTest"); File destFile = new File(tempDirectory, "tempFile"); File nullZipFile = Cai2Util.zipAndDeleteDirectory(tempDirectory.getCanonicalPath()); assertNull(nullZipFile);// w ww . j a v a2 s.c om FileUtils.copyFile(TestDataFiles.VALID_FILE, destFile); try { Cai2Util.zipAndDeleteDirectory(destFile.getCanonicalPath()); fail("Expected illegal argument exception, deleting a file and not directory."); } catch (IllegalArgumentException e) { } assertTrue(tempDirectory.exists()); Cai2Util.printDirContents(tempDirectory); File zippedDirectory = Cai2Util.zipAndDeleteDirectory(tempDirectory.getCanonicalPath()); assertEquals("cai2UtilTest.zip", zippedDirectory.getName()); assertTrue(Cai2Util.isValidZipFile(zippedDirectory)); assertFalse(tempDirectory.exists()); Cai2Util.printDirContents(tempDirectory); zippedDirectory.deleteOnExit(); File tempDirectory2 = fileManager.getNewTemporaryDirectory("cai2UtilTest2"); File destFile2 = new File(tempDirectory2, "tempFile2"); FileUtils.copyFile(TestDataFiles.VALID_FILE, destFile2); File newZipFile = Cai2Util.addFilesToZipFile(zippedDirectory, destFile2); assertNotNull(newZipFile); // need to actually verify it contains 2 items now. FileUtils.deleteDirectory(tempDirectory); FileUtils.deleteDirectory(tempDirectory2); try { Cai2Util.addFilesToZipFile(TestDataFiles.VALID_FILE, new File("")); fail("Expected illegal argument exception, adding to a non-zip file"); } catch (IllegalArgumentException e) { } }
From source file:com.swg.parse.docx.OpenWord.java
@Override public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File("C:/")); fc.setAcceptAllFileFilterUsed(false); //this authorize only .docx selection fc.addChoosableFileFilter(new DocxFileFilter()); if (selectedFile != null) { fc.setSelectedFile(selectedFile); }/*from w w w. ja va 2 s . c om*/ int returnVal = fc.showDialog(WindowManager.getDefault().getMainWindow(), "Extract Data"); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); selectedFile = file; pathToTxtFile = selectedFile.getAbsolutePath().replace(".docx", ".txt"); TxtFile = new File(pathToTxtFile); String zipFilePath = "C:\\Users\\KXK3\\Documents\\ZipTest\\test.zip"; String destDirectory = "C:\\Users\\KXK3\\Documents\\ZipTest\\temp"; UnzipUtility unzipper = new UnzipUtility(); try { File zip = new File(zipFilePath); File directory = new File(destDirectory); FileUtils.copyFile(selectedFile, zip); unzipper.UnzipUtility(zip, directory); String mediaPath = destDirectory + "/word/media/"; File mediaDir = new File(mediaPath); for (File fil : mediaDir.listFiles()) { FileUtils.copyFile(fil, new File("C:\\Users\\KXK3\\Documents\\ZipTest\\Pictures\\" + fil.getName())); } zip.delete(); FileUtils.deleteDirectory(directory); } catch (Exception ex) { ex.printStackTrace(); } //if the txt file doesn't exist, it tries to convert whatever //can be the txt into the actual txt. if (!TxtFile.exists()) { pathToTxtFile = selectedFile.getAbsolutePath().replace(".docx", ""); TxtFile = new File(pathToTxtFile); pathToTxtFile += ".txt"; TxtFile.renameTo(new File(pathToTxtFile)); TxtFile = new File(pathToTxtFile); } String content; String POIContent; try { content = readTxtFile(); version = DetermineVersion(content); NewExtract ext = new NewExtract(); ext.extract(content, selectedFile.getAbsolutePath(), version, 1); } catch (FileNotFoundException ex) { Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex); } catch (ParseException ex) { Exceptions.printStackTrace(ex); } } else { //do nothing } }