Java Code Examples for org.apache.commons.io.FileUtils#copyFile()
The following examples show how to use
org.apache.commons.io.FileUtils#copyFile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InboundTransportTest.java From product-ei with Apache License 2.0 | 6 votes |
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE }) @Test(groups = "wso2.esb", description = "Inbound endpoint Reading file with Contect type XML Test Case") public void testInboundEnpointReadFile_ContentType_XML() throws Exception { logViewerClient.clearLogs(); File sourceFile = new File(pathToFtpDir + File.separator + TEST_XML_FILE_NAME); File targetFolder = new File(inboundFileListeningFolder + File.separator + CONTENT_TYPE); File targetFile = new File(targetFolder + File.separator + TEST_XML_FILE_NAME); FileUtils.copyFile(sourceFile, targetFile); addInboundEndpoint(addEndpoint1(targetFolder.getAbsolutePath())); boolean isFileRead = Utils.checkForLog(logViewerClient, "LOG_SYMBOL_WSO2", 10); Assert.assertTrue(isFileRead, "The XML file is not getting read"); }
Example 2
Source File: RenameFileTest.java From butterfly with MIT License | 6 votes |
@Test public void test() throws IOException { File originalFile = new File(transformedAppFolder, "foo.xml"); assertTrue(originalFile.exists()); assertTrue(originalFile.isFile()); // Saving original file as a temp file to have its content compared later File tempOriginalFile = File.createTempFile("butterfly-test-file", null); FileUtils.copyFile(originalFile, tempOriginalFile); RenameFile renameFile = new RenameFile("bar.xml").relative("foo.xml"); TOExecutionResult executionResult = renameFile.execution(transformedAppFolder, transformationContext); assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS); assertEquals(renameFile.getDescription(), "Rename file foo.xml to bar.xml"); assertEquals(executionResult.getDetails(), "File 'foo.xml' has been renamed to 'bar.xml'"); File renamedFile = new File(transformedAppFolder, "bar.xml"); assertFalse(originalFile.exists()); assertTrue(renamedFile.exists()); assertTrue(FileUtils.contentEquals(tempOriginalFile, renamedFile)); tempOriginalFile.delete(); }
Example 3
Source File: AsciidocMojoTest.java From wisdom with Apache License 2.0 | 6 votes |
@Test public void testInitializationWithUnfilteredInternalAndExternalFilesUsingRegularExtensions() throws MojoExecutionException, IOException { AsciidocMojo mojo = new AsciidocMojo(); mojo.basedir = basedir; mojo.buildDirectory = new File(mojo.basedir, "target"); mojo.doctype = "article"; mojo.backend = "html5"; FileUtils.copyFile(new File("src/test/resources/hello.ad"), new File(basedir, "src/main/resources/assets/doc/hello.ad")); FileUtils.copyFile(new File("src/test/resources/hello.ad"), new File(basedir, "src/main/assets/doc/hello.asciidoc")); mojo.execute(); final File internal = new File(mojo.getInternalAssetOutputDirectory(), "doc/hello.html"); final File external = new File(mojo.getExternalAssetsOutputDirectory(), "doc/hello.html"); assertThat(internal).isFile(); assertThat(external).isFile(); assertThat(FileUtils.readFileToString(internal)).contains("<h1>Hello, " + "Wisdom!</h1>").contains("href=\"http://asciidoc.org\""); assertThat(FileUtils.readFileToString(external)).contains("<h1>Hello, " + "Wisdom!</h1>").contains("href=\"http://asciidoc.org\""); }
Example 4
Source File: LocalFileManage.java From bbs with GNU Affero General Public License v3.0 | 6 votes |
/** * 图片格式转换 * @param resFilePath 原文件路径 * @param newFilePath 生成文件路径 * @param suffix 新文件后缀 jpg bmp * @throws IOException */ public void converterImage(String resFilePath,String newFilePath,String suffix) throws IOException{ File file = new File(PathUtil.path()+File.separator+resFilePath); if(file.isFile() &&file.exists()){ BufferedImage bIMG =ImageIO.read(file); String old_suffix = FileUtil.getExtension(resFilePath); if(old_suffix != null && "png".equalsIgnoreCase(old_suffix)){ //下面两句解决png转jpg时图片发生颜色失真问题 BufferedImage newBufferedImage = new BufferedImage(bIMG.getWidth(), bIMG.getHeight(), BufferedImage.TYPE_INT_RGB); newBufferedImage.createGraphics().drawImage(bIMG, 0, 0, Color.WHITE, null); ImageIO.write(newBufferedImage, suffix, new File(PathUtil.path()+File.separator+newFilePath)); }else{ if(old_suffix != null && old_suffix.equals(suffix)){//如果同后缀,则直接复制 FileUtils.copyFile(file,new File(PathUtil.path()+File.separator+newFilePath)); }else{ ImageIO.write(bIMG, suffix, new File(PathUtil.path()+File.separator+newFilePath)); } } } }
Example 5
Source File: InboundTransportTest.java From product-ei with Apache License 2.0 | 6 votes |
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE }) @Test(groups = { "wso2.esb" }, dependsOnMethods = "testInboundEndpointFileName_SpecialChars", description = "Inbound Endpoint Content type invalid Test case") public void testInboundEndpointContentTypeInvalid() throws Exception { logViewerClient.clearLogs(); File sourceFile = new File(pathToFtpDir + File.separator + TEST_XML_FILE_NAME); File targetFolder = new File(inboundFileListeningFolder + File.separator + IN); File targetFile = new File(targetFolder + File.separator + INVALID_CONTENT_TYPE_XML); try { FileUtils.copyFile(sourceFile, targetFile); addInboundEndpoint(addEndpoint6()); boolean isFileRead = Utils.checkForLog(logViewerClient, LOG_SYMBOL_WSO2, 10); Assert.assertTrue(isFileRead, "The XML file is not getting read"); Assert.assertTrue(!targetFile.exists(), "file not deleted after processed"); } finally { deleteFile(targetFile); } }
Example 6
Source File: ConfigTest.java From uyuni with GNU General Public License v2.0 | 5 votes |
public void setUp() throws Exception { c = new Config(); // create test config path String confPath = "/tmp/" + TestUtils.randomString(); new File(confPath + "/conf/default").mkdirs(); ArrayList<String> paths = new ArrayList<>(); paths.add("conf/rhn.conf"); paths.add("conf/default/rhn_web.conf"); paths.add("conf/default/rhn_prefix.conf"); paths.add("conf/default/bug154517.conf.rpmsave"); // copy test configuration files over for (String relPath : paths) { try { FileUtils.copyURLToFile(TestUtils.findTestData(relPath), new File(confPath, relPath)); } catch (NullPointerException e) { FileUtils.copyFile(new File(TEST_CONF_LOCATION + relPath), new File(confPath, relPath)); } } c.addPath(confPath + "/conf"); c.addPath(confPath + "/conf/default"); c.parseFiles(); }
Example 7
Source File: XMLManipulatorTest.java From pom-manipulation-ext with Apache License 2.0 | 5 votes |
@Test(expected = ManipulationException.class) public void testNotFound() throws Exception { String path = "//include[starts-with(.,'i-do-not-exist')]"; File target = tf.newFile(); FileUtils.copyFile( xmlFile, target ); Project p = new Project( target, TestUtils.getDummyModel() ); xmlManipulator.internalApplyChanges( p, new XMLState.XMLOperation( target.getName(), path, null) ); }
Example 8
Source File: VFSTransportTestCase.java From product-ei with Apache License 2.0 | 5 votes |
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE}) @Test(groups = {"wso2.esb"}, description = "Sending a file through VFS Transport :" + " transport.vfs.FileURI = Linux Path, " + "transport.vfs.ContentType = text/xml, " + "transport.vfs.FileNamePattern = - *\\.xml " + "transport.vfs.ActionAfterFailure=NotSpecified") public void testVFSProxyActionAfterFailure_NotSpecified() throws Exception { addVFSProxy14(); File sourceFile = new File(pathToVfsDir + File.separator + "fail.xml"); File targetFile = new File(pathToVfsDir + "test" + File.separator + "in" + File.separator + "fail.xml"); File outfile = new File(pathToVfsDir + "test" + File.separator + "out" + File.separator + "out.xml"); File originalFile = new File(pathToVfsDir + "test" + File.separator + "failure" + File.separator + "fail.xml"); try { FileUtils.copyFile(sourceFile, targetFile); Awaitility.await() .pollInterval(50, TimeUnit.MILLISECONDS) .atMost(60, TimeUnit.SECONDS) .until(isFileNotExist(outfile)); Assert.assertTrue(!outfile.exists()); Assert.assertTrue(!originalFile.exists()); Assert.assertFalse(new File(pathToVfsDir + "test" + File.separator + "in" + File.separator + "fail.xml.lock").exists(), "lock file exists even after moving the failed file"); } finally { deleteFile(targetFile); deleteFile(outfile); deleteFile(originalFile); removeProxy("VFSProxy14"); } }
Example 9
Source File: Edition112_iOS_Screenshot_Orientation.java From appiumpro with Apache License 2.0 | 5 votes |
@Test public void testScreenshots() throws Exception { Thread.sleep(2000); String desktop = System.getenv("HOME") + "/Desktop"; driver.rotate(ScreenOrientation.LANDSCAPE); File regularScreenshot = driver.getScreenshotAs(OutputType.FILE); driver.setSetting("screenshotOrientation", "landscapeRight"); File adjustedScreenshot = driver.getScreenshotAs(OutputType.FILE); FileUtils.copyFile(regularScreenshot, new File(desktop + "/screen1.png")); FileUtils.copyFile(adjustedScreenshot, new File(desktop + "/screen2.png")); }
Example 10
Source File: AbstractGoDependencyAwareMojo.java From mvn-golang with Apache License 2.0 | 5 votes |
private void preprocessModules(@Nonnull @MustNotContainNull final List<Tuple<Artifact, File>> unpackedDependencyFolders) throws MojoExecutionException { try { final List<Tuple<Artifact, Tuple<GoMod, File>>> lst = preprocessModuleFilesInDependencies(unpackedDependencyFolders); final List<Tuple<GoMod, File>> dependencyGoMods = listRightPart(lst); final List<Tuple<Artifact, Tuple<GoMod, File>>> projectGoMods = fildGoModsAndParse(Collections.singletonList(Tuple.of(this.getProject().getArtifact(), this.getSources(false)))); for (final Tuple<Artifact, Tuple<GoMod, File>> f : projectGoMods) { final File goModFileBak = new File(f.right().right().getParentFile(), GO_MOD_FILE_NAME_BAK); final File goModFile = f.right().right(); if (goModFileBak.isFile()) { if (goModFile.isFile() && !goModFile.delete()) { throw new IOException("Can't detete go.mod file: " + goModFile); } FileUtils.copyFile(goModFileBak, goModFile); } else { if (goModFile.isFile()) { FileUtils.copyFile(goModFile, goModFileBak); } } if (goModFile.isFile()) { final GoMod parsed = GoMod.from(FileUtils.readFileToString(goModFile, StandardCharsets.UTF_8)); if (replaceLinksToModules(Tuple.of(parsed, goModFile), dependencyGoMods)) { FileUtils.write(goModFile, parsed.toString(), StandardCharsets.UTF_8); } } } } catch (IOException ex) { throw new MojoExecutionException("Can't process a go.mod file", ex); } }
Example 11
Source File: VFSTransportTestCase.java From micro-integrator with Apache License 2.0 | 5 votes |
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE }) @Test(groups = { "wso2.esb" }, description = "Sending a file through VFS Transport : " + "transport.vfs.FileURI = Linux Path, " + "transport.vfs.ContentType = text/xml, " + "transport.vfs.FileNamePattern = - *\\.xml " + "transport.vfs.MoveAfterFailure = Invalid") public void testVFSProxyMoveAfterFailure() throws Exception { String proxyName = "VFSProxy22"; File sourceFile = new File(pathToVfsDir + "fail.xml"); File targetFile = new File(proxyVFSRoots.get(proxyName) + File.separator + "in" + File.separator + "fail.xml"); File outfile = new File(proxyVFSRoots.get(proxyName) + File.separator + "out" + File.separator + "out.xml"); File originalFile = new File(proxyVFSRoots.get(proxyName) + File.separator + "invalid" + File.separator + "fail.xml"); /*File lockFile = new File(pathToVfsDir + "test" + File.separator + "in" + File.separator + "fail.xml.lock");*/ FileUtils.copyFile(sourceFile, targetFile); Awaitility.await().pollInterval(50, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS) .until(isFileNotExist(targetFile)); Awaitility.await().pollDelay(2, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).atMost(60, TimeUnit.SECONDS) .until(isFileNotExist(outfile)); Awaitility.await().pollInterval(50, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS) .until(isFileExist(originalFile)); Assert.assertFalse(outfile.exists(), "Out put file found"); Assert.assertTrue(originalFile.exists(), "Input file not moved even if failure happens while building message"); Assert.assertFalse(targetFile.exists(), "input file not found even if it is invalid file"); }
Example 12
Source File: YUIBuilder.java From opoopress with Apache License 2.0 | 5 votes |
private void compressIfRequired(File inputFile, File outputFile) throws Exception { //for min.css or min.js, copy only if (inputFile.getName().endsWith(".min." + type)) { FileUtils.copyFile(inputFile, outputFile); } else { try { compress(inputFile, outputFile); } catch (Exception e) { FileUtils.deleteQuietly(outputFile); throw e; } } }
Example 13
Source File: GroovyFunctionsTest.java From pom-manipulation-ext with Apache License 2.0 | 5 votes |
@Test public void testTempOverrideWithNonTemp() throws Exception { final File base = TestUtils.resolveFileResource( "profile.pom", "" ); final File root = temporaryFolder.newFolder(); final File target = new File ( root, "profile.xml"); FileUtils.copyFile( base, target); final DefaultContainerConfiguration config = new DefaultContainerConfiguration(); config.setClassPathScanning( PlexusConstants.SCANNING_ON ); config.setComponentVisibility( PlexusConstants.GLOBAL_VISIBILITY ); config.setName( "PME-CLI" ); final PlexusContainer container = new DefaultPlexusContainer( config); final PomIO pomIO = container.lookup( PomIO.class ); final List<Project> projects = pomIO.parseProject( target ); assertThat( projects.size(), equalTo(1) ); BaseScriptImplTest impl = new BaseScriptImplTest(); Properties p = new Properties( ); p.setProperty( "versionIncrementalSuffix", "temporary-redhat" ); p.setProperty( "restRepositoryGroup", "GroovyWithTemporary" ); p.setProperty( "restURL", mockServer.getUrl() ); impl.setValues(pomIO, null, null, TestUtils.createSession( p ), projects, projects.get( 0 ), InvocationStage.FIRST ); impl.overrideProjectVersion( SimpleProjectVersionRef.parse( "org.goots:testTempOverrideWithNonTemp:1.0.0" ) ); assertEquals( "redhat-5", impl.getUserProperties().getProperty( VersioningState.VERSION_SUFFIX_SYSPROP ) ); }
Example 14
Source File: MarkdownMojoTest.java From wisdom with Apache License 2.0 | 5 votes |
@Test public void testInitializationWithFilteredInternalAndExternalFilesUsingRegularExtensions() throws MojoExecutionException, IOException { MarkdownMojo mojo = new MarkdownMojo(); mojo.basedir = basedir; mojo.buildDirectory = new File(mojo.basedir, "target"); FileUtils.copyFile(new File("src/test/resources/hello.md"), new File(basedir, "src/main/resources/assets/doc/hello.md")); // Filtered version: FileUtils.copyFile(new File("src/test/resources/hello.md"), new File(basedir, "target/classes/assets/doc/hello.md")); FileUtils.copyFile(new File("src/test/resources/hello.md"), new File(basedir, "src/main/assets/doc/hello.md")); // Filtered version: FileUtils.copyFile(new File("src/test/resources/hello.md"), new File(basedir, "target/wisdom/assets/doc/hello.md")); mojo.execute(); final File internal = new File(mojo.getInternalAssetOutputDirectory(), "doc/hello.html"); final File external = new File(mojo.getExternalAssetsOutputDirectory(), "doc/hello.html"); assertThat(internal).isFile(); assertThat(external).isFile(); assertThat(FileUtils.readFileToString(internal)).contains("<h1>Hello, " + "Wisdom!</h1>").contains("href=\"http://perdu.com\""); assertThat(FileUtils.readFileToString(external)).contains("<h1>Hello, " + "Wisdom!</h1>").contains("href=\"http://perdu.com\""); }
Example 15
Source File: ChromeInterface.java From candybean with GNU Affero General Public License v3.0 | 4 votes |
@Override public void start() throws CandybeanException { ChromeOptions chromeOptions = new ChromeOptions(); String chromeDriverLogPath = candybean.config.getPathValue("browser.chrome.driver.log.path"); logger.info("chromeDriverLogPath: " + chromeDriverLogPath); chromeOptions.addArguments("--log-path=" + chromeDriverLogPath); String chromeDriverPath = candybean.config.getPathValue("browser.chrome.driver.path"); validateChromeDriverExist(chromeDriverPath); // If parallel is enabled and the chromedriver-<os>_<thread-name> doesn't exist, duplicate one // from chromedriver-<os> and give it executable permission. if("true".equals(candybean.config.getPathValue("parallel.enabled"))) { String originalChromePath = chromeDriverPath; // Cross platform support if(OSValidator.isWindows()) { chromeDriverPath = chromeDriverPath.replaceAll("(.*)(\\.exe)", "$1_" + Thread.currentThread().getName() + "$2"); } else { chromeDriverPath = chromeDriverPath.replaceAll("$", "_" + Thread.currentThread().getName()); } if(!new File(chromeDriverPath).exists()) { try { FileUtils.copyFile(new File(originalChromePath), new File(chromeDriverPath)); if(!OSValidator.isWindows()) { //Not needed in Windows Runtime.getRuntime().exec("chmod u+x " + chromeDriverPath); } } catch(IOException e) { String error = "Cannot duplicate a new chromedriver for parallelization"; logger.severe(error); throw new CandybeanException(error); } } } logger.info("chromeDriverPath: " + chromeDriverPath); System.setProperty("webdriver.chrome.driver", chromeDriverPath); logger.info("Instantiating Chrome with:\n log path:"+ chromeDriverLogPath + "\n driver path: " + chromeDriverPath); super.wd = ThreadGuard.protect(new ChromeDriver(chromeOptions)); super.start(); // requires wd to be instantiated first }
Example 16
Source File: GoConfigMigration.java From gocd with Apache License 2.0 | 4 votes |
private void backup(File configFile, File backupFile) throws IOException { FileUtils.copyFile(configFile, backupFile); LOG.info("Config file is backed up, location: {}", backupFile.getAbsolutePath()); }
Example 17
Source File: GoFileSystem.java From gocd with Apache License 2.0 | 4 votes |
public void copyFile (File srcFile, File destFile) throws IOException { FileUtils.copyFile(srcFile, destFile); }
Example 18
Source File: CliCommandExecutor.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
private void copyNative(String localFile, String destDir) throws IOException { File src = new File(localFile); File dest = new File(destDir, src.getName()); FileUtils.copyFile(src, dest); }
Example 19
Source File: StratosTestServerManager.java From attic-stratos with Apache License 2.0 | 4 votes |
public synchronized String setUpCarbonHome(String carbonServerZipFile) throws IOException, AutomationFrameworkException { if (this.process != null) { return this.carbonHome; } else { int indexOfZip = carbonServerZipFile.lastIndexOf(".zip"); if (indexOfZip == -1) { throw new IllegalArgumentException(carbonServerZipFile + " is not a zip file"); } else { String fileSeparator = File.separator.equals("\\") ? "\\" : "/"; if (fileSeparator.equals("\\")) { carbonServerZipFile = carbonServerZipFile.replace("/", "\\"); } String extractedCarbonDir = carbonServerZipFile .substring(carbonServerZipFile.lastIndexOf(fileSeparator) + 1, indexOfZip); FileManipulator.deleteDir(extractedCarbonDir); String extractDir = "carbontmp" + System.currentTimeMillis(); String baseDir = System.getProperty("basedir", ".") + File.separator + "target"; log.info("Extracting carbon zip file.. "); (new ArchiveExtractor()).extractFile(carbonServerZipFile, baseDir + File.separator + extractDir); this.carbonHome = (new File(baseDir)).getAbsolutePath() + File.separator + extractDir + File.separator + extractedCarbonDir; try { this.isCoverageEnable = Boolean .parseBoolean(this.automationContext.getConfigurationValue("//coverage")); } catch (XPathExpressionException var8) { throw new AutomationFrameworkException("Coverage configuration not found in automation.xml", var8); } // Fix startup script issue by copying stratos.sh as stratos-server.sh // TODO: remove this class after automation engine provides a way to pass startup script name // currently startup script should be either wso2server.sh or contain the string 'server' FileUtils.copyFile(new File(carbonHome + File.separator + "bin" + File.separator + "stratos.sh"), new File(carbonHome + File.separator + "bin" + File.separator + "stratos-server.sh")); if (this.isCoverageEnable) { this.instrumentForCoverage(); } return this.carbonHome; } } }
Example 20
Source File: PackageDialog.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
private void packr(Platform platform, String jdk, String exe, String jar, String mainClass, String outDir) throws IOException { String suffix = null; switch (platform) { case Linux32: suffix = "lin32"; break; case Linux64: suffix = "lin64"; break; case MacOS: suffix = "mac.app"; break; case Windows64: suffix = "win64"; break; case Windows32: suffix = "win"; break; } PackrConfig config = new PackrConfig(); config.platform = platform; config.jdk = jdk; config.executable = exe; config.classpath = Arrays.asList(jar); config.mainClass = mainClass.replace('/', '.'); config.vmArgs = Arrays.asList("-Xmx1G"); config.minimizeJre = "hard"; config.outDir = new File(outDir + "/" + exe + "-" + suffix); new Packr().pack(config); // COPY MAC OS ICON if (platform == Platform.MacOS && icon.getText() != null && icon.getText().endsWith(".icns")) { FileUtils.copyFile(new File(icon.getText()), new File(config.outDir.getAbsolutePath() + "/Contents/Resources/icons.icns")); } }