List of usage examples for org.apache.commons.io FileUtils copyDirectory
public static void copyDirectory(File srcDir, File destDir) throws IOException
From source file:au.org.ala.delta.confor.ToKeyTest.java
@Test public void testSampleToKey() throws Exception { File tointDirectory = urlToFile("/dataset/"); File dest = new File(System.getProperty("java.io.tmpdir")); FileUtils.copyDirectory(tointDirectory, dest); String tokeyFilePath = FilenameUtils.concat(dest.getAbsolutePath(), "sample/tokey"); CONFOR.main(new String[] { tokeyFilePath }); String expectedKCharsFilename = FilenameUtils.concat(dest.getAbsolutePath(), "sample/expected_results/kchars"); String expectedKItemsFilename = FilenameUtils.concat(dest.getAbsolutePath(), "sample/expected_results/kitems"); BinaryKeyFile expectedKChars = new BinaryKeyFile(expectedKCharsFilename, BinFileMode.FM_READONLY); BinaryKeyFile expectedKItems = new BinaryKeyFile(expectedKItemsFilename, BinFileMode.FM_READONLY); String actualKCharsFilename = FilenameUtils.concat(dest.getAbsolutePath(), "sample/kchars"); String actualKItemsFilename = FilenameUtils.concat(dest.getAbsolutePath(), "sample/kitems"); BinaryKeyFile kchars = new BinaryKeyFile(actualKCharsFilename, BinFileMode.FM_READONLY); BinaryKeyFile kitems = new BinaryKeyFile(actualKItemsFilename, BinFileMode.FM_READONLY); int numRecords = expectedKChars.getLength() / BinaryKeyFile.RECORD_LENGTH_BYTES; int actualNumRecords = kchars.getLength() / BinaryKeyFile.RECORD_LENGTH_BYTES; int count = Math.min(numRecords, actualNumRecords); for (int i = 1; i <= count; i++) { List<Integer> expectedRecord = expectedKChars.readIntegerList(i, BinaryKeyFile.RECORD_LENGTH_INTEGERS); List<Integer> actualRecord = kchars.readIntegerList(i, BinaryKeyFile.RECORD_LENGTH_INTEGERS); System.out.println("Record: " + i); System.out.println(expectedRecord); System.out.println(actualRecord); System.out.println("Expected as string: "); System.out.println(expectedKChars.readString(i, BinaryKeyFile.RECORD_LENGTH_BYTES)); System.out.println();/*from w w w . j av a2 s.com*/ assertEquals(expectedRecord, actualRecord); } numRecords = expectedKItems.getLength() / BinaryKeyFile.RECORD_LENGTH_BYTES; System.out.println("**** Items File (" + numRecords + ")*****"); List<Integer> header = expectedKItems.readIntegerList(1, BinaryKeyFile.RECORD_LENGTH_INTEGERS); ItemsFileHeader itemsHeader = new ItemsFileHeader(); itemsHeader.fromInts(header); for (int i = 1; i < numRecords; i++) { System.out.println("Record: " + i); if ((i >= itemsHeader.getCharcterReliabilitiesRecord() && i < itemsHeader.getTaxonMaskRecord()) || i >= itemsHeader.getItemAbundancesRecord()) { List<Float> expectedFloats = expectedKItems.readFloatList(i, BinaryKeyFile.RECORD_LENGTH_INTEGERS); List<Float> actualFloats = kitems.readFloatList(i, BinaryKeyFile.RECORD_LENGTH_INTEGERS); System.out.println(expectedFloats); System.out.println(actualFloats); for (int f = 0; f < expectedFloats.size(); f++) { // Note sure if this is a difference in encoding or precision // but our floats are quite different. assertEquals(expectedFloats.get(f), actualFloats.get(f), 0.021f); } } else if (i >= itemsHeader.getHeadingRecord() && i < itemsHeader.getCharacterMaskRecord()) { // The header has the date in it so will be different. } else { List<Integer> expectedRecord = expectedKItems.readIntegerList(i, BinaryKeyFile.RECORD_LENGTH_INTEGERS); List<Integer> actualRecord = kitems.readIntegerList(i, BinaryKeyFile.RECORD_LENGTH_INTEGERS); System.out.println(expectedRecord); System.out.println(actualRecord); System.out.println("Expected as string: "); char[] chars = expectedKItems.readString(i, BinaryKeyFile.RECORD_LENGTH_BYTES).toCharArray(); for (int c = 0; c < chars.length; c++) { System.out.print(chars[c]); } if (i != 1) { assertEquals(expectedRecord, actualRecord); } } System.out.println(); char[] actualChars = kitems.readString(i, BinaryKeyFile.RECORD_LENGTH_BYTES).toCharArray(); for (int c = 0; c < actualChars.length; c++) { System.out.print(actualChars[c]); } System.out.println(); System.out.println(); } }
From source file:ml.shifu.shifu.udf.EvalScoreUDFTest.java
@BeforeClass public void setUp() throws Exception { Environment.setProperty(Environment.SHIFU_HOME, "."); File models = new File("src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/models"); FileUtils.copyDirectory(models, tmpModels); instance = new EvalScoreUDF("LOCAL", "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ModelConfig.json", "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ColumnConfig.json", "EvalA"); }
From source file:de.brendamour.jpasskit.signing.PKPassTemplateFolder.java
@Override public void provisionPassAtDirectory(File tempPassDir) throws IOException { FileUtils.copyDirectory(new File(pathToTemplateDirectory), tempPassDir); }
From source file:com.mycompany.sparkrentals.client.RentalSolrClientTest.java
@Before public void setUp() throws IOException, SolrServerException { File resourceDir = new File("src/test/resources/solr"); //use a temporary folder for solr home FileUtils.copyDirectory(resourceDir, tempSolrHome.getRoot()); CoreContainer coreContainer = new CoreContainer(tempSolrHome.getRoot().getAbsolutePath()); coreContainer.load();//from w w w . j av a2s . c om server = new EmbeddedSolrServer(coreContainer, "new_core"); //populate initial data List<Rental> rentals = new ArrayList<>(); rentals.add(new Rental("A1234", "city1", "province2", "country2", "fjkso", "Villa", true, true, true, true, 10f, "$", 1, new Date())); rentals.add(new Rental("A2234", "city2", "province2", "country9", "dfsdd", "studio", true, false, true, true, 11f, "$", 2, new Date())); rentals.add(new Rental("A3234", "city3", "province5", "country1", "e9r3e", "studio", false, true, false, true, 7.2f, "$", 3, new Date())); Date threeDaysAgo = new Date(new Date().getTime() - 3 * 24 * 3600 * 1000); rentals.add(new Rental("A4234", "city4", "province7", "country6", "ghree", "Single Floor", true, false, true, true, 8f, "$", 2, threeDaysAgo)); for (Rental rental : rentals) { server.addBean(rental); server.commit(); } client = new RentalSolrClient(); client.setSolrClient(server); }
From source file:ml.shifu.shifu.util.ModelSpecLoaderUtilsTest.java
@Test public void testFindModels() throws IOException { ModelConfig modelConfig = CommonUtils.loadModelConfig( "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ModelConfig.json", SourceType.LOCAL);/*from w w w.j a va2s .c o m*/ File srcModels = new File("src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/models"); File dstModels = new File("models"); FileUtils.copyDirectory(srcModels, dstModels); List<FileStatus> modelFiles = ModelSpecLoaderUtils.findModels(modelConfig, null, SourceType.LOCAL); Assert.assertEquals(5, modelFiles.size()); EvalConfig evalConfig = modelConfig.getEvalConfigByName("EvalA"); evalConfig.setCustomPaths(new HashMap<String, String>()); evalConfig.getCustomPaths().put(Constants.KEY_MODELS_PATH, null); modelFiles = ModelSpecLoaderUtils.findModels(modelConfig, evalConfig, SourceType.LOCAL); Assert.assertEquals(5, modelFiles.size()); evalConfig.getCustomPaths().put(Constants.KEY_MODELS_PATH, " "); modelFiles = ModelSpecLoaderUtils.findModels(modelConfig, evalConfig, SourceType.LOCAL); Assert.assertEquals(5, modelFiles.size()); FileUtils.deleteDirectory(dstModels); evalConfig.getCustomPaths().put(Constants.KEY_MODELS_PATH, "./src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/models"); modelFiles = ModelSpecLoaderUtils.findModels(modelConfig, evalConfig, SourceType.LOCAL); Assert.assertEquals(5, modelFiles.size()); evalConfig.getCustomPaths().put(Constants.KEY_MODELS_PATH, "./src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/models/model0.nn"); modelFiles = ModelSpecLoaderUtils.findModels(modelConfig, evalConfig, SourceType.LOCAL); Assert.assertEquals(1, modelFiles.size()); evalConfig.getCustomPaths().put(Constants.KEY_MODELS_PATH, "not-exists"); modelFiles = ModelSpecLoaderUtils.findModels(modelConfig, evalConfig, SourceType.LOCAL); Assert.assertEquals(0, modelFiles.size()); evalConfig.getCustomPaths().put(Constants.KEY_MODELS_PATH, "./src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/models/*.nn"); modelFiles = ModelSpecLoaderUtils.findModels(modelConfig, evalConfig, SourceType.LOCAL); Assert.assertEquals(5, modelFiles.size()); evalConfig.getCustomPaths().put(Constants.KEY_MODELS_PATH, "./src/test/resources/example/cancer-judgement/ModelStore/ModelSet{0,1,9}/*/*.nn"); modelFiles = ModelSpecLoaderUtils.findModels(modelConfig, evalConfig, SourceType.LOCAL); Assert.assertEquals(5, modelFiles.size()); }
From source file:com.dragovorn.dragonbot.api.bot.file.FileManager.java
public static void reloadFiles() { FileManager.config = new File(directory, "config.yml"); FileManager.logs = new File(directory, "logs"); FileManager.plugins = new File(directory, "plugins"); FileManager.updater = new File(directory, "updater.jar"); List<File> toCopy = new ArrayList<>(); toCopy.addAll(pluginAddedFiles);/*from www. jav a 2 s . co m*/ pluginAddedFiles.clear(); toCopy.forEach(file -> { try { if (file.isDirectory()) { FileUtils.copyDirectory(file, new File(directory, file.getName())); } else { FileUtils.copyFile(file, new File(directory, file.getName())); } file.delete(); pluginAddedFiles.add(new File(directory, file.getName())); } catch (IOException exception) { exception.printStackTrace(); } }); }
From source file:com.smartbear.soapui.utils.jetty.JettyTestCaseBase.java
protected JettyTestCaseBase() { port = PORT.getAndIncrement();/*from w w w . ja v a2s. c om*/ resourceBase = Files.createTempDir().getAbsolutePath(); try { FileUtils.copyDirectory( new File(JettyTestCaseBase.class.getResource("/config").toURI()).getParentFile(), new File(resourceBase)); } catch (IOException e) { throw new IllegalStateException(e); } catch (URISyntaxException e) { throw new RuntimeException("Unexpected URI syntax exception! - this shouldn't happen", e); } ResourceHandler resource_handler = new ResourceHandler(); resource_handler.setResourceBase(resourceBase); this.server = new Server(port); HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() }); this.server.setHandler(handlers); }
From source file:com.google.cloud.tools.gradle.appengine.AppEngineFlexiblePluginIntegrationTest.java
@Before public void setUp() throws IOException { FileUtils.copyDirectory(new File("src/integTest/resources/projects/flexible-project"), testProjectDir.getRoot());/*w ww.j a v a 2 s . c o m*/ }
From source file:com.kylinolap.job.hadoop.cube.NDCuboidMapperTest.java
@Before public void setUp() throws Exception { createTestMetadata();/* ww w . ja v a2 s .c om*/ // hack for distributed cache FileUtils.deleteDirectory(new File("../job/meta")); FileUtils.copyDirectory(new File(this.getTestConfig().getMetadataUrl()), new File("../job/meta")); NDCuboidMapper mapper = new NDCuboidMapper(); CuboidReducer reducer = new CuboidReducer(); mapReduceDriver = MapReduceDriver.newMapReduceDriver(mapper, reducer); }
From source file:com.google.cloud.tools.gradle.endpoints.framework.ProjectTests.java
@Test public void testClientBuilds() throws IOException, URISyntaxException { FileUtils.copyDirectory(new File(getClass().getClassLoader().getResource("projects/client").toURI()), testProjectDir.getRoot());/*ww w . j a va2 s . com*/ BuildResult buildResult = GradleRunner.create().withProjectDir(testProjectDir.getRoot()) .withPluginClasspath().withArguments("assemble").build(); }