Java Code Examples for org.apache.commons.io.FileUtils.moveFile()

The following are Jave code examples for showing how to use moveFile() of the org.apache.commons.io.FileUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Pogamut3   File: NavMeshMakerStep.java   View Source Code Vote up 6 votes
public boolean moveOutput() {
	File outputFile = null;
	File targetFile = null;
	try {
		for (int i = 0; i < outputFiles.length; ++i) {
			outputFile = outputFiles[i];
			targetFile = targetFiles[i];
			
			if (!outputFile.exists()) continue;
			String outputFileAbsolute = removeThisDir(outputFile.getAbsolutePath());
			String targetFileAbsolute = removeThisDir(targetFile.getAbsolutePath());
			if (outputFileAbsolute.equals(targetFileAbsolute)) continue;
			
			FileUtils.moveFile(outputFile, targetFile);
		}
		return true;
	} catch (Exception e) {
		fail("Failed to move " + outputFile.getAbsolutePath() + " to " + targetFile.getAbsolutePath(), e);
		return false;
	}
}
 
Example 2
Project: framework   File: StorageManager.java   View Source Code Vote up 6 votes
private static State saveTmpFile(File tmpFile, String path) {
	State state = null;
	File targetFile = new File(path);

	if (targetFile.canWrite()) {
		return new BaseState(false, AppInfo.PERMISSION_DENIED);
	}
	try {
		FileUtils.moveFile(tmpFile, targetFile);
	} catch (IOException e) {
		return new BaseState(false, AppInfo.IO_ERROR);
	}

	state = new BaseState(true);
	state.putInfo("size", targetFile.length());
	state.putInfo("title", targetFile.getName());

	return state;
}
 
Example 3
Project: atlas   File: AwoFullApkBuildTask.java   View Source Code Vote up 6 votes
@TaskAction
public void doTask() throws IOException, SigningException {

    baseApkFile = getBaseApkFile();
    destPath = getDestPath();
    awoFile = getAwoFile();
    zipAlign = getZipAlign();
    outApkFile = getOutApkFile();

    ZipUtils.addFileToZipFile(baseApkFile, outApkFile, awoFile, destPath, true);

    File signFile = new File(outApkFile.getParent(), outApkFile.getName().replace(".apk", "-signed.apk"));
    AtlasBuildContext.sBuilderAdapter.androidSigner.signFile(outApkFile, signFile, getSigningConfig());
    if (null != zipAlign && zipAlign) {
        File signAndZipAlignedFile = ZipAlignUtils.doZipAlign(androidBuilder, getProject(), signFile);
        FileUtils.deleteQuietly(outApkFile);
        FileUtils.moveFile(signAndZipAlignedFile, outApkFile);
    }

}
 
Example 4
Project: s3-proxy-chunk-upload   File: IOUploadUtils.java   View Source Code Vote up 6 votes
/**
 * The operation copies the file in the specified path.
 * @param dirPath Target directory
 * @param fileName File name
 * @param srcFile
 * @throws IOException
 */
public static void saveFile(String dirPath, String fileName, File srcFile)
        throws IOException {
    
    try {
        File uploadPart = new File(dirPath, fileName);
        if (uploadPart.exists()) {
            uploadPart.delete();
        }
        FileUtils.moveFile(srcFile, uploadPart);
    } catch (IOException ex) {
        String prefix = "Save file error: '";
        Logger.error(prefix + ex.getMessage() + "'");
        throw new IOException(prefix + ex.getMessage() + "'");
    }
}
 
Example 5
Project: xmanager   File: DefaultFileManager.java   View Source Code Vote up 6 votes
private static State saveTmpFile(File tmpFile, String path) {
	File targetFile = new File(path);

	if (targetFile.canWrite()) {
		return new BaseState(false, AppInfo.PERMISSION_DENIED);
	}
	try {
		FileUtils.moveFile(tmpFile, targetFile);
	} catch (IOException e) {
		return new BaseState(false, AppInfo.IO_ERROR);
	}

	State state = new BaseState(true);
	state.putInfo("size", targetFile.length());
	state.putInfo("title", targetFile.getName());
	return state;
}
 
Example 6
Project: OneClient   File: Updater.java   View Source Code Vote up 6 votes
public static void main(String[] args) throws IOException, InterruptedException {
	Thread.sleep(3000); //We wait a few seconds to allow the old instance to close so we can rename it without causing an exception
	File oldJar = new File(args[0]);
	File newJar = getTempFile(false);
	File backupJar = new File(oldJar.getAbsolutePath() + ".old");
	if (backupJar.exists()) {
		backupJar.delete();
	}
	FileUtils.moveFile(oldJar, backupJar); //Backup the old jar so if things go wrong it can be manually reverted
	FileUtils.copyFile(newJar, oldJar);

	List<String> newArgs = new ArrayList<>();
	newArgs.add("java");
	newArgs.add("-jar");
	newArgs.add(oldJar.getAbsolutePath()); //The old jar is now the new jar as we copyied it over
	newArgs.add("-updateSuccess"); //Added here so we can show a dialog if when the new jar is opened

	ProcessBuilder processBuilder = new ProcessBuilder();
	processBuilder.command(newArgs);
	processBuilder.start();
	//Should close here
}
 
Example 7
Project: flow-platform   File: LogServiceImpl.java   View Source Code Vote up 6 votes
/**
 * save job zip
 */
private File saveJobLog(Job job) {
    Path jobPath = getJobLogPath(job);
    Path zipPath = Paths.get(jobPath.getParent().toString(), job.getId().toString() + ".zip");
    Path destPath = Paths.get(jobPath.toString(), job.getId().toString() + ".zip");
    File folderFile = new File(jobPath.toString());
    File zipFile = new File(zipPath.toString());
    File destFile = new File(destPath.toString());

    try {
        ZipUtil.zipFolder(folderFile, zipFile);
        FileUtils.moveFile(zipFile, destFile);
    } catch (IOException e) {
        throw new FlowException("save zip log error");
    }

    return destFile;
}
 
Example 8
Project: Reer   File: GFileUtils.java   View Source Code Vote up 5 votes
public static void moveFile(File source, File destination) {
    try {
        FileUtils.moveFile(source, destination);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example 9
Project: Pogamut3   File: FixLineEndings.java   View Source Code Vote up 5 votes
public synchronized boolean fix(File file) throws IOException {
	File tempFile = new File("temp.line-endings.txt");
	if (fix(file, tempFile)) {
		// file was changed
		file.delete();
		FileUtils.moveFile(tempFile, file);
		tempFile.delete();
		return true;
	} else {
		// no changes
		tempFile.delete();
		return false;
	}
}
 
Example 10
Project: Pogamut3   File: Rewriter.java   View Source Code Vote up 5 votes
public synchronized boolean rewriteFile(File file, String encoding) throws IOException {
	File tempFile = new File("temp.rewrite.txt");
	if (rewriteFile(file, tempFile, encoding)) {
		// file was changed
		file.delete();
		FileUtils.moveFile(tempFile, file);
		tempFile.delete();
		return true;
	} else {
		// no changes
		tempFile.delete();
		return false;
	}
}
 
Example 11
Project: buenojo   File: ImageResourceService.java   View Source Code Vote up 5 votes
private void moveFile(String currentAbsolutePath, String newAbsolutePath) throws BuenOjoFileException{
	try {
		FileUtils.moveFile(new File(currentAbsolutePath), new File(newAbsolutePath));
	}  catch (FileExistsException fe){
		log.error(fe.getMessage());
		throw new BuenOjoFileException("no se pudo mover el archivo: " +currentAbsolutePath+" al destino"+ newAbsolutePath + " porque ese archivo ya existe");
	} catch (IOException e) {
		log.error(e.getMessage());
		throw new BuenOjoFileException("no se pudo mover el archivo: " +currentAbsolutePath+" al destino: "+ newAbsolutePath + e.getMessage());
	}
}
 
Example 12
Project: headless-chrome   File: HeadlessDriverUtils.java   View Source Code Vote up 5 votes
public static void takeFullScreenshot(WebDriver webDriver, File pngFile, By... highlights)
        throws IOException {
    final PageSnapshot pageSnapshot = Shutterbug.shootPage(webDriver, BOTH_DIRECTIONS);
    if (ArrayUtils.isNotEmpty(highlights)) {
        Arrays.stream(highlights)
                .map(webDriver::findElements)
                .flatMap(Collection::stream)
                .forEach(pageSnapshot::highlight);
    }
    FileUtils.forceMkdirParent(pngFile);
    pageSnapshot.withName(pngFile.getName());
    pageSnapshot.save(pngFile.getParent());
    FileUtils.deleteQuietly(pngFile);
    FileUtils.moveFile(new File(pngFile.getPath() + ".png"), pngFile);
}
 
Example 13
Project: atlas   File: BuildHelper.java   View Source Code Vote up 5 votes
public static void writeFileToApk(File destFile, File file, String path) throws IOException {
    File outPutFile = new File(file.getParent(), "temp.apk");
    ZipUtils.addFileToZipFile(file, outPutFile, destFile, path, true);
    FileUtils.deleteQuietly(file);
    FileUtils.moveFile(outPutFile, file);
    FileUtils.deleteQuietly(destFile);
}
 
Example 14
Project: wx-idk   File: FileIo.java   View Source Code Vote up 5 votes
/**
 * 移动文件
 * @author Rocye
 * @param srcPath 	移动的源文件路径
 * @param destPath 	移动的目标文件路径
 * @return true OR false
 * @version 2017-02-28
 */
public static boolean moveFile(String srcPath, String destPath) {
	try {
		FileUtils.moveFile(new File(srcPath), new File(destPath));
		return true;
	} catch (IOException e) {
		e.printStackTrace();
		logger.error("调用ApacheCommon移动文件时:" + e.toString());
		return false;
	}
}
 
Example 15
Project: Cognizant-Intelligent-Test-Scripter   File: UILogger.java   View Source Code Vote up 5 votes
private void backupLog() {
    try {
        File bkp = new File(LOG_BKP_LOC);
        if (!bkp.exists()) {
            bkp.mkdirs();
        }
        String filename = "log-" + Utility.getdatetimeString() + ".txt";
        FileUtils.moveFile(new File(LOG_FILE), new File(bkp, filename));
    } catch (IOException ex) {
        java.util.logging.Logger.getLogger(UILogger.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 16
Project: hadoop   File: BlockPoolSlice.java   View Source Code Vote up 5 votes
/**
 * Move a persisted replica from lazypersist directory to a subdirectory
 * under finalized.
 */
File activateSavedReplica(Block b, File metaFile, File blockFile)
    throws IOException {
  final File blockDir = DatanodeUtil.idToBlockDir(finalizedDir, b.getBlockId());
  final File targetBlockFile = new File(blockDir, blockFile.getName());
  final File targetMetaFile = new File(blockDir, metaFile.getName());
  FileUtils.moveFile(blockFile, targetBlockFile);
  FsDatasetImpl.LOG.info("Moved " + blockFile + " to " + targetBlockFile);
  FileUtils.moveFile(metaFile, targetMetaFile);
  FsDatasetImpl.LOG.info("Moved " + metaFile + " to " + targetMetaFile);
  return targetBlockFile;
}
 
Example 17
Project: obevo   File: FileUtilsCobra.java   View Source Code Vote up 5 votes
public static void moveFile(File srcFile, File destFile) {
    try {
        FileUtils.moveFile(srcFile, destFile);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 18
Project: careconnect-reference-implementation   File: BaseCommand.java   View Source Code Vote up 4 votes
protected Collection<File> loadFile(FhirContext theCtx, String theSpecUrl, String theFilepath, boolean theCacheFile) throws IOException {
	String userHomeDir = System.getProperty("user.home");

	File applicationDir = new File(userHomeDir + File.separator + "." + "hapi-fhir-cli");
	FileUtils.forceMkdir(applicationDir);

	Collection<File> inputFiles;
	if (isNotBlank(theFilepath)) {
		ourLog.info("Loading from local path: {}", theFilepath);

		if (theFilepath.startsWith("~" + File.separator)) {
			theFilepath = userHomeDir + theFilepath.substring(1);
		}

		File suppliedFile = new File(FilenameUtils.normalize(theFilepath));

		if (suppliedFile.isDirectory()) {
			inputFiles = FileUtils.listFiles(suppliedFile, new String[]{"zip"}, false);
		} else {
			inputFiles = Collections.singletonList(suppliedFile);
		}

	} else {

		File cacheDir = new File(applicationDir, "cache");
		FileUtils.forceMkdir(cacheDir);

		File inputFile = new File(cacheDir, "examples-json-" + theCtx.getVersion().getVersion() + ".zip");

		Date cacheExpiryDate = DateUtils.addHours(new Date(), -12);

		if (!inputFile.exists() | (theCacheFile && FileUtils.isFileOlder(inputFile, cacheExpiryDate))) {

			File exampleFileDownloading = new File(cacheDir, "examples-json-" + theCtx.getVersion().getVersion() + ".zip.partial");

			HttpGet get = new HttpGet(theSpecUrl);
			CloseableHttpClient client = HttpClientBuilder.create().build();
			CloseableHttpResponse result = client.execute(get);

			if (result.getStatusLine().getStatusCode() != 200) {
				throw new CommandFailureException("Got HTTP " + result.getStatusLine().getStatusCode() + " response code loading " + theSpecUrl);
			}

			ourLog.info("Downloading from remote url: {}", theSpecUrl);
			downloadFileFromInternet(result, exampleFileDownloading);

			FileUtils.deleteQuietly(inputFile);
			FileUtils.moveFile(exampleFileDownloading, inputFile);

			if (!theCacheFile) {
				inputFile.deleteOnExit();
			}

			ourLog.info("Successfully Loaded example pack ({})", FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(inputFile)));
			IOUtils.closeQuietly(result.getEntity().getContent());
		}

		inputFiles = Collections.singletonList(inputFile);

	}
	return inputFiles;
}
 
Example 19
Project: convertigo-engine   File: MoveStep.java   View Source Code Vote up 4 votes
@Override
protected void doActionForSourceFile(File sourceFile, File destinationFile) throws IOException {
	FileUtils.moveFile(sourceFile, destinationFile);
}
 
Example 20
Project: dremio-oss   File: FMPPMojo.java   View Source Code Vote up 4 votes
private Report moveIfChanged(File root, String tmpPath) throws MojoFailureException, IOException {
  Report report = new Report();
  for (File file : root.listFiles()) {
    if (file.isDirectory()) {
      report.add(moveIfChanged(file, tmpPath));
      if (!file.delete()) {
        throw new MojoFailureException(format("can not delete %s", file));
      }
    } else {
      String absPath = file.getAbsolutePath();
      if (!absPath.startsWith(tmpPath)) {
        throw new MojoFailureException(format("%s should start with %s", absPath, tmpPath));
      }
      String relPath = absPath.substring(tmpPath.length());
      File outputFile = new File(output, relPath);
      if (!outputFile.exists()) {
        report.addNew();
      } else if (!FileUtils.contentEquals(file, outputFile)) {
        getLog().info(format("%s has changed", relPath));
        if (!outputFile.delete()) {
          throw new MojoFailureException(format("can not delete %s", outputFile));
        }
        report.addChanged();
      } else {
        report.addUnchanged();
      }
      if (!outputFile.exists()) {
        File parentDir = outputFile.getParentFile();
        if (parentDir.exists() && !parentDir.isDirectory()) {
          throw new MojoFailureException(format("can not move %s to %s as %s is not a dir", file, outputFile, parentDir));
        }
        if (!parentDir.exists() && !parentDir.mkdirs()) {
          throw new MojoFailureException(format("can not move %s to %s as dir %s can not be created", file, outputFile, parentDir));
        }
        FileUtils.moveFile(file, outputFile);
      } else {
        if (!file.delete()) {
          throw new MojoFailureException(format("can not delete %s", file));
        }
      }
    }
  }
  return report;
}