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.datatorrent.lib.io.fs.DirectoryScanInputOperatorTest.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test/* w ww. jav a 2 s.c o m*/ public void testDirectoryScan() throws InterruptedException, IOException { //Create the directory and the files used in the test case File baseDir = new File(dirName); // if the directory does not exist, create it if (!baseDir.exists()) { System.out.println("creating directory: " + dirName); boolean result = baseDir.mkdir(); if (result) { System.out.println("base directory created"); //create sub-directory File subDir = new File(dirName + "/subDir"); // if the directory does not exist, create it if (!subDir.exists()) { System.out.println("creating subdirectory: " + dirName + "/subDir"); boolean subDirResult = subDir.mkdir(); if (subDirResult) { System.out.println("sub directory created"); } } } else { System.out.println("Failed to create base directory"); return; } } //Create the files inside base dir int numOfFilesInBaseDir = 4; for (int num = 0; num < numOfFilesInBaseDir; num++) { String fileName = dirName + "/testFile" + String.valueOf(num + 1) + ".txt"; File file = new File(fileName); if (file.createNewFile()) { System.out.println(fileName + " is created!"); FileUtils.writeStringToFile(file, fileName); } else { System.out.println(fileName + " already exists."); } } //Create the files inside base subDir int numOfFilesInSubDir = 6; for (int num = 0; num < numOfFilesInSubDir; num++) { String fileName = dirName + "/subDir/testFile" + String.valueOf(num + numOfFilesInBaseDir + 1) + ".txt"; File file = new File(fileName); if (file.createNewFile()) { System.out.println(fileName + " is created!"); FileUtils.writeStringToFile(file, fileName); } else { System.out.println(fileName + " already exists."); } } DirectoryScanInputOperator oper = new DirectoryScanInputOperator(); oper.setDirectoryPath(dirName); oper.setScanIntervalInMilliSeconds(1000); oper.activate(null); CollectorTestSink sink = new CollectorTestSink(); oper.outport.setSink(sink); //Test if the existing files in the directory are emitted. Thread.sleep(1000); oper.emitTuples(); Assert.assertTrue("tuple emmitted: " + sink.collectedTuples.size(), sink.collectedTuples.size() > 0); Assert.assertEquals(sink.collectedTuples.size(), 10); //Test if the new file added is detected sink.collectedTuples.clear(); File oldFile = new File("../library/src/test/resources/directoryScanTestDirectory/testFile1.txt"); File newFile = new File("../library/src/test/resources/directoryScanTestDirectory/newFile.txt"); FileUtils.copyFile(oldFile, newFile); int timeoutMillis = 2000; while (sink.collectedTuples.isEmpty() && timeoutMillis > 0) { oper.emitTuples(); timeoutMillis -= 20; Thread.sleep(20); } Assert.assertTrue("tuple emmitted: " + sink.collectedTuples.size(), sink.collectedTuples.size() > 0); Assert.assertEquals(sink.collectedTuples.size(), 1); //clean up the directory to initial state newFile.delete(); oper.deactivate(); oper.teardown(); //clean up the directory used for the test FileUtils.deleteDirectory(baseDir); }
From source file:de.bitinsomnia.webdav.server.MiltonFileResource.java
@Override public void copyTo(CollectionResource toCollection, String name) throws NotAuthorizedException, BadRequestException, ConflictException { LOGGER.debug("Copying {} to {}/{}", this.file, toCollection.getName(), name); File copyFilePath = new File(resourceFactory.getRootFolder(), toCollection.getName()); File copyFile = new File(copyFilePath, name); try {/*ww w. j a va 2s.c om*/ FileUtils.copyFile(this.file, copyFile); } catch (IOException e) { LOGGER.error("Error copying file {} to {}/{}", this.file, toCollection, name, e); throw new RuntimeIoException(e); } }
From source file:com.adaptris.security.TestKeystoreLocation.java
@Test public void testRemoteKeystore() throws Exception { if (Boolean.parseBoolean(cfg.getProperty(Config.REMOTE_TESTS_ENABLED, "false"))) { String ks = cfg.getProperty(Config.KEYSTORE_TEST_URL); ks = ks.replaceAll("\\\\", "/"); URI uri = new URI(ks); File keystore = new File(uri.getPath()); String filename = keystore.getName(); File newFile = new File(cfg.getProperty(Config.KEYSTORE_REMOTE_REALPATH) + "/" + filename); FileUtils.copyFile(keystore, newFile); Thread.sleep(10000);//w w w . ja v a2 s . c om logR.debug("newFile " + newFile.getCanonicalPath()); String keystoreType = uri.getQuery(); String url = cfg.getProperty(Config.KEYSTORE_REMOTE_ROOT) + filename + "?" + keystoreType; KeystoreLocation k = KeystoreFactory.getDefault().create(url, cfg.getProperty(Config.KEYSTORE_COMMON_KEYSTORE_PW).toCharArray()); assertTrue("Remote Keystore exists", k.exists()); InputStream in = k.openInput(); in.close(); assertTrue(!k.isWriteable()); boolean openOutputSuccess = false; try { OutputStream o = k.openOutput(); openOutputSuccess = true; o.close(); } catch (Exception e) { // Expected as it's non-writeable } newFile.delete(); if (openOutputSuccess) { fail("Successfully opened output to a remote keystore!"); } } }
From source file:com.axelor.apps.base.service.imports.importer.Importer.java
protected File createFinalWorkspace(MetaFile metaFile) throws IOException { File data = MetaFiles.getPath(metaFile).toFile(); File finalWorkspace = new File(workspace, computeFinalWorkspaceName(data)); finalWorkspace.mkdir();/*from w w w.j a v a 2s. c o m*/ if (isZip(data)) { unZip(data, finalWorkspace); } else { FileUtils.copyFile(data, new File(finalWorkspace, metaFile.getFileName())); } return finalWorkspace; }
From source file:com.yahoo.sshd.authentication.file.TestPKUpdating.java
private void buildSshDirs(File homeDir, User[] dirs) throws IOException { for (User user : dirs) { File userDir = new File(homeDir, user.name); File sshDir = new File(userDir, ".ssh"); File authKeys = new File(sshDir, "authorized_keys"); FileUtils.forceMkdir(sshDir);//w ww . ja va 2s . c o m // give them public keys FileUtils.copyFile(user.publicKey, authKeys); } }
From source file:com.lohika.alp.selenium.log.LogElementsSeleniumFactoryJAXB.java
@Override 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 av a2 s . 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:algorithm.ImageImageFrameExpanding.java
/** * Merge of only two images. This is used by the * {@link ImageInformationEmbeddingFrame} algorithm. * /*from w w w. j av a 2s. co m*/ * @param carrier * @param payload * @return encapsulated images * @throws IOException */ public File encapsulate(File carrier, File payload) throws IOException { File outputFile = getOutputFile(carrier); FileUtils.copyFile(carrier, outputFile); append(outputFile, payload); return outputFile; }
From source file:ml.shifu.shifu.ShifuCLITest.java
@Test public void testInitializeModel() throws Exception { File originModel = new File( "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ModelConfig.json"); File tmpModel = new File("ModelConfig.json"); FileUtils.copyFile(originModel, tmpModel); ShifuCLI.initializeModel();//from ww w.j ava 2 s . co m File file = new File("ColumnConfig.json"); Assert.assertTrue(file.exists()); FileUtils.deleteQuietly(file); FileUtils.deleteQuietly(tmpModel); }
From source file:com.twinsoft.convertigo.engine.util.ProjectUtils.java
public static void copyIndexFile(String projectName) throws Exception { String projectRoot = Engine.PROJECTS_PATH + '/' + projectName; String templateBase = Engine.TEMPLATES_PATH + "/base"; File indexPage = new File(projectRoot + "/index.html"); if (!indexPage.exists()) { if (new File(projectRoot + "/sna.xsl").exists()) { /** webization javelin */ if (new File(projectRoot + "/templates/status.xsl").exists()) /** not DKU / DKU */ FileUtils.copyFile(new File(templateBase + "/index_javelin.html"), indexPage); else/* www. java 2 s . c o m*/ FileUtils.copyFile(new File(templateBase + "/index_javelinDKU.html"), indexPage); } else { FileFilter fileFilterNoSVN = new FileFilter() { public boolean accept(File pathname) { String name = pathname.getName(); return !name.equals(".svn") || !name.equals("CVS"); } }; FileUtils.copyFile(new File(templateBase + "/index.html"), indexPage); FileUtils.copyDirectory(new File(templateBase + "/js"), new File(projectRoot + "/js"), fileFilterNoSVN); FileUtils.copyDirectory(new File(templateBase + "/css"), new File(projectRoot + "/css"), fileFilterNoSVN); } } }
From source file:com.netsteadfast.greenstep.action.CommonUploadFileAction.java
private String copy2UploadDir() throws IOException, Exception { if (!YesNo.YES.equals(this.isFile)) { return ""; }/*from w w w . ja v a2 s . c om*/ File uploadDir = UploadSupportUtils.mkdirUploadFileDir(system, type); String realFileName = UploadSupportUtils.generateRealFileName(this.uploadFileName); File realFile = new File(uploadDir.getPath() + "/" + realFileName); try { FileUtils.copyFile(this.getUpload(), realFile); } catch (IOException e) { throw e; } finally { realFile = null; uploadDir = null; } return realFileName; }