List of usage examples for org.apache.commons.io FileUtils copyFile
public static void copyFile(File srcFile, File destFile) throws IOException
From source file:can.yrt.onebusaway.backup.Backup.java
/** * Performs a restore from the SD card./* ww w. ja va 2s. com*/ * * @param context */ public static void restore(Context context) throws IOException { File dbPath = getDB(context); File backupPath = getBackup(context); // At least here we can decide that the database is closed. ContentProviderClient client = null; try { client = context.getContentResolver().acquireContentProviderClient(ObaContract.AUTHORITY); ObaProvider provider = (ObaProvider) client.getLocalContentProvider(); provider.closeDB(); FileUtils.copyFile(backupPath, dbPath); } finally { if (client != null) { client.release(); } } }
From source file:com.evolveum.midpoint.model.intest.manual.CsvBackingStore.java
@Override public void initialize() throws IOException { FileUtils.copyFile(sourceFile, targetFile); }
From source file:gov.wa.wsdot.cms.utils.Migration.java
/** * Renames resources to original filename which are not GUID based. * /* ww w.j a va 2 s. c o m*/ * @param oldFilename * @param newFilename */ public static void resourceCopy(String archiveFolder, String oldFilename, String newFilename) { File destinationPath = new File("export/" + archiveFolder); File oldFile = new File(archiveFolder + File.separator + oldFilename); File newFile = new File(destinationPath + File.separator + newFilename); if (!destinationPath.exists()) { if (destinationPath.mkdirs()) { try { FileUtils.copyFile(oldFile, newFile); } catch (IOException e) { System.out.println("Copy failed: " + oldFilename + " to " + newFilename); e.printStackTrace(); } } } else { try { FileUtils.copyFile(oldFile, newFile); } catch (IOException e) { System.out.println("Copy failed: " + oldFilename + " to " + newFilename); e.printStackTrace(); } } }
From source file:hudson.plugins.git.converter.RemoteConfigConverterTest.java
@Before public void setUp() throws URISyntaxException, IOException { sourceConfigFile = new File(this.getClass().getResource("config.xml").toURI()); //Create target config file in order to perform marshall operation targetConfigFile = new File(sourceConfigFile.getParent(), "target_config.xml"); FileUtils.copyFile(sourceConfigFile, targetConfigFile); }
From source file:com.buddycloud.mediaserver.update.UpdateMediaTest.java
@Override protected void testSetUp() throws Exception { File destDir = new File(configuration.getProperty(MediaServerConfiguration.MEDIA_STORAGE_ROOT_PROPERTY) + File.separator + BASE_CHANNEL); if (!destDir.mkdir()) { FileUtils.cleanDirectory(destDir); }//ww w. j a v a2 s . c o m FileUtils.copyFile(new File(TEST_FILE_PATH + TEST_IMAGE_NAME), new File(destDir + File.separator + MEDIA_ID)); Media media = buildMedia(MEDIA_ID, TEST_FILE_PATH + TEST_IMAGE_NAME); dataSource.storeMedia(media); // mocks AuthVerifier authClient = xmppTest.getAuthVerifier(); EasyMock.expect(authClient.verifyRequest(EasyMock.matches(BASE_USER), EasyMock.matches(BASE_TOKEN), EasyMock.startsWith(URL))).andReturn(true); PubSubClient pubSubClient = xmppTest.getPubSubClient(); EasyMock.expect(pubSubClient.matchUserCapability(EasyMock.matches(BASE_USER), EasyMock.matches(BASE_CHANNEL), (CapabilitiesDecorator) EasyMock.notNull())).andReturn(true); EasyMock.replay(authClient); EasyMock.replay(pubSubClient); }
From source file:com.nubits.nubot.options.SaveOptions.java
/** * backup an options file. write it to .bak and increase counter * * @param filepath//from www . j av a 2s .co m * @return */ public static boolean backupOptions(String filepath) throws IOException { File f = new File(filepath); if (f.exists()) { boolean wrote = false; int i = 0; while (!wrote) { String fp = f.getParent() + File.separator + f.getName() + "_" + i + ".bak"; File dest = new File(fp); if (!dest.exists()) { try { FileUtils.copyFile(f, dest); return true; } catch (IOException e) { throw new IOException(e); } } i++; if (i > 100) return false; } } return false; }
From source file:com.amazonaws.eclipse.rds.MySqlConnectionFactory.java
@Override public Properties createDriverProperties() { Bundle bundle = Platform.getBundle(RDSPlugin.PLUGIN_ID); Path path = new Path("lib/" + MYSQL_DRIVER_FILE_NAME); URL fileURL = FileLocator.find(bundle, path, null); String jarList = path.toOSString(); try {/* w w w.j av a 2 s. co m*/ IPath stateLocation = Platform.getStateLocation(Platform.getBundle(RDSPlugin.PLUGIN_ID)); File mysqlDriversDir = new File(stateLocation.toFile(), "mysqlDrivers"); String jarPath = FileLocator.resolve(fileURL).getPath(); File sourceFile = new File(jarPath); File destinationFile = new File(mysqlDriversDir, MYSQL_DRIVER_FILE_NAME); FileUtils.copyFile(sourceFile, destinationFile); jarList = destinationFile.getAbsolutePath(); } catch (IOException e) { throw new RuntimeException("Unable to locate MySQL driver on disk.", e); } Properties driverProperties = new Properties(); driverProperties.setProperty(IDriverMgmtConstants.PROP_DEFN_JARLIST, jarList); driverProperties.setProperty(IJDBCConnectionProfileConstants.DRIVER_CLASS_PROP_ID, "com.mysql.jdbc.Driver"); //$NON-NLS-1$ driverProperties.setProperty(IJDBCConnectionProfileConstants.DATABASE_VENDOR_PROP_ID, "MySql"); driverProperties.setProperty(IJDBCConnectionProfileConstants.DATABASE_VERSION_PROP_ID, "5.1"); driverProperties.setProperty(IJDBCConnectionProfileConstants.SAVE_PASSWORD_PROP_ID, String.valueOf(true)); driverProperties.setProperty(IDriverMgmtConstants.PROP_DEFN_TYPE, "org.eclipse.datatools.enablement.mysql.5_1.driverTemplate"); return driverProperties; }
From source file:memoryaid.GalleryController.java
@FXML private void uploadImageAction(ActionEvent event) throws IOException { String imgPath = imagePathText.getText(); String baseName = FilenameUtils.getBaseName(imgPath); String destinationPath = "/Users/madhaviunnam/NetBeansProjects/MemoryAid/src/GalleryImages"; File destinationPathObject = new File(destinationPath + "/" + baseName + ".png"); File sourceFilePathObject = new File(imgPath); FileUtils.copyFile(sourceFilePathObject, destinationPathObject); Parent Gallery = FXMLLoader.load(getClass().getResource("Gallery1.fxml")); Scene Gallery_scene = new Scene(Gallery); Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); app_stage.hide();// ww w . j av a 2 s. c o m app_stage.setScene(Gallery_scene); app_stage.show(); }
From source file:ml.shifu.shifu.core.pmml.PMMLTranslatorTest.java
@Test public void testAllNumericVariablePmmlCase() throws Exception { // Step 1. Eval the scores using SHIFU File originModel = new File( "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ModelConfig.json"); File tmpModel = new File("ModelConfig.json"); File originColumn = new File( "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ColumnConfig.json"); File tmpColumn = new File("ColumnConfig.json"); File modelsDir = new File("src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/models"); File tmpModelsDir = new File("models"); FileUtils.copyFile(originModel, tmpModel); FileUtils.copyFile(originColumn, tmpColumn); FileUtils.copyDirectory(modelsDir, tmpModelsDir); // run evaluation set ShifuCLI.runEvalScore("EvalA"); File evalScore = new File("evals/EvalA/EvalScore"); ShifuCLI.exportModel(null);/*from w ww .jav a 2 s.c o m*/ // Step 2. Eval the scores using PMML and compare it with SHIFU output String DataPath = "./src/test/resources/example/cancer-judgement/DataStore/Full_data/data.dat"; String OutPath = "./pmml_out.dat"; for (int index = 0; index < 5; index++) { String num = Integer.toString(index); String pmmlPath = "pmmls/cancer-judgement" + num + ".pmml"; evalPmml(pmmlPath, DataPath, OutPath, "\\|", "model" + num); compareScore(evalScore, new File(OutPath), "model" + num, "\\|", 1.0); FileUtils.deleteQuietly(new File(OutPath)); } FileUtils.deleteQuietly(tmpModel); FileUtils.deleteQuietly(tmpColumn); FileUtils.deleteDirectory(tmpModelsDir); FileUtils.deleteQuietly(new File("./pmmls")); FileUtils.deleteQuietly(new File("evals")); }
From source file:com.buddycloud.mediaserver.download.DownloadImageTest.java
@Override protected void testSetUp() throws Exception { File destDir = new File(configuration.getProperty(MediaServerConfiguration.MEDIA_STORAGE_ROOT_PROPERTY) + File.separator + BASE_CHANNEL); if (!destDir.mkdir()) { FileUtils.cleanDirectory(destDir); }/*from ww w .ja v a2 s . c o m*/ FileUtils.copyFile(new File(TEST_FILE_PATH + TEST_IMAGE_NAME), new File(destDir + File.separator + MEDIA_ID)); Media media = buildMedia(MEDIA_ID, TEST_FILE_PATH + TEST_IMAGE_NAME); dataSource.storeMedia(media); // mocks AuthVerifier authClient = xmppTest.getAuthVerifier(); EasyMock.expect(authClient.verifyRequest(BASE_USER, BASE_TOKEN, URL)).andReturn(true); PubSubClient pubSubClient = xmppTest.getPubSubClient(); EasyMock.expect(pubSubClient.matchUserCapability(EasyMock.matches(BASE_USER), EasyMock.matches(BASE_CHANNEL), (CapabilitiesDecorator) EasyMock.notNull())).andReturn(true); EasyMock.replay(authClient); EasyMock.replay(pubSubClient); }