Java Code Examples for org.apache.commons.io.FileUtils#moveFile()
The following examples show how to use
org.apache.commons.io.FileUtils#moveFile() .
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: ModuleMaster.java From The-5zig-Mod with GNU General Public License v3.0 | 6 votes |
public void loadInitial() { try { if (file.exists()) { loadModules(); } else { createDefault(); } } catch (Throwable e) { The5zigMod.logger.warn("Error loading modules!", e); try { File backupFile = new File(parent, "modules.old.json"); if (backupFile.exists()) { backupFile.delete(); } FileUtils.moveFile(file, backupFile); createDefault(); } catch (Throwable e1) { The5zigMod.logger.error("Could not create default modules file!", e1); } } }
Example 2
Source File: SimpleThriftLogger.java From singer with Apache License 2.0 | 6 votes |
/** * Simple implementation of log file rotation. * @throws java.io.IOException */ public void rotate() throws IOException { close(); int i = 0; while (new File(String.format("%s.%d", fileName, ++i)).exists()) { ; } for (int j = i - 1; j >= 1; --j) { FileUtils.moveFile( new File(String.format("%s.%d", fileName, j)), new File(String.format("%s.%d", fileName, j + 1))); } FileUtils.moveFile(new File(fileName), new File(fileName + ".1")); bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(fileName, true)); transport = new ByteOffsetTFramedTransport(new TIOStreamTransport(bufferedOutputStream)); protocol = new TBinaryProtocol(transport); }
Example 3
Source File: SharedFolderWithWritePermissionMoveInTest.java From Hive2Hive with MIT License | 6 votes |
@Test public void testSynchronizeMoveFileFromAIntoSharedFolderAtA() throws NoSessionException, NoPeerConnectionException, IOException, IllegalArgumentException, IllegalArgumentException, GetFailedException { logger.info("Upload a new file 'fileFromA' into root folder of A."); File fileFromAAtA = FileTestUtil.createFileRandomContent("fileFromA", new Random().nextInt(MAX_NUM_CHUNKS) + 1, rootA); UseCaseTestUtil.uploadNewFile(network.get(0), fileFromAAtA); logger.info("Move file 'fileFromA' at A into shared folder 'sharedfolder'."); File movedFileFromAAtA = new File(sharedFolderA, fileFromAAtA.getName()); FileUtils.moveFile(fileFromAAtA, movedFileFromAAtA); UseCaseTestUtil.moveFile(network.get(0), fileFromAAtA, movedFileFromAAtA); logger.info("Wait till new moved in file 'fileFromA' gets synchronized with B."); File movedFileFromAAtB = new File(sharedFolderB, fileFromAAtA.getName()); waitTillSynchronized(movedFileFromAAtB, true); compareFiles(movedFileFromAAtA, movedFileFromAAtB); checkIndex(movedFileFromAAtA, movedFileFromAAtB); }
Example 4
Source File: SharedFolderWithReadPermissionMoveOutTest.java From Hive2Hive with MIT License | 6 votes |
@Test public void testSynchronizeAddFileAtAMoveOutAtA() throws NoSessionException, NoPeerConnectionException, IOException, IllegalArgumentException, IllegalArgumentException, GetFailedException { File fileFromAAtA = FileTestUtil.createFileRandomContent("file1FromA", new Random().nextInt(MAX_NUM_CHUNKS) + 1, sharedFolderA); logger.info("Upload a new file '{}' at A.", fileFromAAtA.toString()); UseCaseTestUtil.uploadNewFile(nodeA, fileFromAAtA); logger.info("Wait till new file '{}' gets synchronized with B.", fileFromAAtA.toString()); File fileFromAAtB = new File(sharedFolderB, fileFromAAtA.getName()); waitTillSynchronized(fileFromAAtB, true); logger.info("Move file '{}' at A to root folder of A.", fileFromAAtA.toString()); File movedFileFromAAtA = new File(rootA, fileFromAAtA.getName()); FileUtils.moveFile(fileFromAAtA, movedFileFromAAtA); UseCaseTestUtil.moveFile(nodeA, fileFromAAtA, movedFileFromAAtA); logger.info("Wait till moving of file '{}' to '{}' gets synchronized with B.", fileFromAAtA.toString(), movedFileFromAAtA.toString()); waitTillSynchronized(fileFromAAtB, false); checkIndexesAfterMoving(fileFromAAtA, fileFromAAtB, movedFileFromAAtA); }
Example 5
Source File: SharedFolderWithWritePermissionMoveInternalTest.java From Hive2Hive with MIT License | 6 votes |
@Test public void testSynchronizeAddFileFromBMoveToSubfolderAtA() throws NoSessionException, NoPeerConnectionException, IOException, IllegalArgumentException, IllegalArgumentException, GetFailedException { logger.info("Upload a new file 'sharedfolder/file1FromB' from B."); File fileFromBAtB = FileTestUtil.createFileRandomContent("file1FromB", new Random().nextInt(MAX_NUM_CHUNKS) + 1, sharedFolderB); UseCaseTestUtil.uploadNewFile(network.get(1), fileFromBAtB); logger.info("Wait till new file 'sharedFolder/file1FromB' gets synchronized with A."); File fileFromBAtA = new File(sharedFolderA, fileFromBAtB.getName()); waitTillSynchronized(fileFromBAtA, true); logger.info("Move file 'file1FromB' at A into shared subfolder 'sharedfolder/subfolder1'."); File movedFileFromAAtA = new File(subFolder1AtA, fileFromBAtA.getName()); FileUtils.moveFile(fileFromBAtA, movedFileFromAAtA); UseCaseTestUtil.moveFile(network.get(0), fileFromBAtA, movedFileFromAAtA); logger.info("Wait till new moved file 'file1FromB' gets synchronized with B."); File movedFileFromAAtB = new File(subFolder1AtB, fileFromBAtA.getName()); waitTillSynchronized(movedFileFromAAtB, true); compareFiles(movedFileFromAAtA, movedFileFromAAtB); checkIndex(fileFromBAtA, fileFromBAtB, movedFileFromAAtA, movedFileFromAAtB); }
Example 6
Source File: SharedFolderWithWritePermissionMoveInternalTest.java From Hive2Hive with MIT License | 6 votes |
@Test public void testSynchronizeAddSubfileFromAMoveToFolderAtA() throws NoSessionException, NoPeerConnectionException, IOException, IllegalArgumentException, IllegalArgumentException, GetFailedException { logger.info("Upload a new file 'sharedfolder/subfolder1/subfile1FromA' from A."); File fileFromAAtA = FileTestUtil.createFileRandomContent("subfile1FromA", new Random().nextInt(MAX_NUM_CHUNKS) + 1, subFolder1AtA); UseCaseTestUtil.uploadNewFile(network.get(0), fileFromAAtA); logger.info("Wait till new file 'sharedFolder/subfolder1/subfile1FromA' gets synchronized with B."); File fileFromAAtB = new File(subFolder1AtB, fileFromAAtA.getName()); waitTillSynchronized(fileFromAAtB, true); logger.info("Move file 'subfileFromA' at A into shared folder 'sharedfolder'."); File movedFileFromAAtA = new File(sharedFolderA, fileFromAAtA.getName()); FileUtils.moveFile(fileFromAAtA, movedFileFromAAtA); UseCaseTestUtil.moveFile(network.get(0), fileFromAAtA, movedFileFromAAtA); logger.info("Wait till new moved file 'subfile1FromA' gets synchronized with B."); File movedFileFromAAtB = new File(sharedFolderB, fileFromAAtA.getName()); waitTillSynchronized(movedFileFromAAtB, true); compareFiles(movedFileFromAAtA, movedFileFromAAtB); checkIndex(fileFromAAtA, fileFromAAtB, movedFileFromAAtA, movedFileFromAAtB); }
Example 7
Source File: SharedFolderWithReadPermissionMoveInternalTest.java From Hive2Hive with MIT License | 6 votes |
@Test public void testSynchronizeAddSubFileAtAMoveToSubfolderAtA() throws NoSessionException, NoPeerConnectionException, IOException, IllegalArgumentException, IllegalArgumentException, GetFailedException { File fileFromAAtA = FileTestUtil.createFileRandomContent("subfile3FromA", new Random().nextInt(MAX_NUM_CHUNKS) + 1, subFolder1A); logger.info("Upload a new file '{}' at A.", fileFromAAtA.getName()); UseCaseTestUtil.uploadNewFile(nodeA, fileFromAAtA); logger.info("Wait till new file '{}' gets synchronized with B.", fileFromAAtA.getName()); File fileFromAAtB = new File(subFolder1B, fileFromAAtA.getName()); waitTillSynchronized(fileFromAAtB, true); File movedFileFromAAtA = new File(subFolder2A, fileFromAAtA.getName()); logger.info("Move file '{}' at A into shared subfolder '{}'.", fileFromAAtA.getName(), subFolder2A); FileUtils.moveFile(fileFromAAtA, movedFileFromAAtA); UseCaseTestUtil.moveFile(nodeA, fileFromAAtA, movedFileFromAAtA); logger.info("Wait till new moved file '{}' gets synchronized with B.", fileFromAAtA.getName()); File movedFileFromAAtB = new File(subFolder2B, fileFromAAtA.getName()); waitTillSynchronized(movedFileFromAAtB, true); compareFiles(movedFileFromAAtA, movedFileFromAAtB); checkIndexAfterMoving(fileFromAAtA, fileFromAAtB, movedFileFromAAtA, movedFileFromAAtB); }
Example 8
Source File: SharedFolderWithWritePermissionMoveOutTest.java From Hive2Hive with MIT License | 6 votes |
@Test public void testSynchronizeAddFileFromAMoveOutFromA() throws NoSessionException, NoPeerConnectionException, IOException, IllegalArgumentException, IllegalArgumentException, GetFailedException { logger.info("Upload a new file 'sharedFolder/file1FromA' from A."); File file1FromAAtA = FileTestUtil.createFileRandomContent("file1FromA", new Random().nextInt(MAX_NUM_CHUNKS) + 1, sharedFolderA); UseCaseTestUtil.uploadNewFile(network.get(0), file1FromAAtA); logger.info("Wait till new file 'sharedFolder/file1FromA' gets synchronized with B."); File file1FromAAtB = new File(sharedFolderB, file1FromAAtA.getName()); waitTillSynchronized(file1FromAAtB, true); logger.info("Move file 'sharedFolder/file1FromA' from A to root folder of A."); File movedFile1FromAAtA = new File(rootA, file1FromAAtA.getName()); FileUtils.moveFile(file1FromAAtA, movedFile1FromAAtA); UseCaseTestUtil.moveFile(network.get(0), file1FromAAtA, movedFile1FromAAtA); logger.info("Wait till moving of file 'shardFolder/file1FromA' gets synchronized with B."); waitTillSynchronized(file1FromAAtB, false); checkIndexes(file1FromAAtA, file1FromAAtB, movedFile1FromAAtA, true); }
Example 9
Source File: ContinuousFileProcessingMigrationTest.java From flink with Apache License 2.0 | 6 votes |
/** * Create a file with pre-determined String format of the form: * {@code fileIdx +": "+ sampleLine +" "+ lineNo}. * */ private Tuple2<File, String> createFileAndFillWithData( File base, String fileName, int fileIdx, String sampleLine) throws IOException { File file = new File(base, fileName + fileIdx); Assert.assertFalse(file.exists()); File tmp = new File(base, "." + fileName + fileIdx); FileOutputStream stream = new FileOutputStream(tmp); StringBuilder str = new StringBuilder(); for (int i = 0; i < LINES_PER_FILE; i++) { String line = fileIdx + ": " + sampleLine + " " + i + "\n"; str.append(line); stream.write(line.getBytes()); } stream.close(); FileUtils.moveFile(tmp, file); Assert.assertTrue("No result file present", file.exists()); return new Tuple2<>(file, str.toString()); }
Example 10
Source File: CreateSample.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private void renameNode() throws Exception, IOException { File file_node = new File(FileTools.parent(FileTools.parent(new File("./"))), "configSample/node.json"); File file_node_local = new File(FileTools.parent(FileTools.parent(new File("./"))), "configSample/node_127.0.0.1.json"); if (file_node_local.exists()) { file_node_local.delete(); } FileUtils.moveFile(file_node, file_node_local); }
Example 11
Source File: GFileUtils.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public static void moveFile(File source, File destination) { try { FileUtils.moveFile(source, destination); } catch (IOException e) { throw new UncheckedIOException(e); } }
Example 12
Source File: FileUtilsEx.java From pgptool with GNU General Public License v3.0 | 5 votes |
/** * This method will pick OTHER vacant file name to write data to and when * operation is completed, old file will be removed and new file will be renamed * to target name. * * See https://github.com/pgptool/pgptool/issues/131 "Improvement: when * encrypting back - don't overwrite existing file until encryption 100% * completed" * * @param targetFile desired target file name * @param fileCreatorLogic operation which will create the file */ public static void baitAndSwitch(String targetFile, FileCreatorLogic fileCreatorLogic) throws Exception, UserRequestedCancellationException { File targetFileFile = new File(targetFile); File targetFolder = targetFileFile.getParentFile(); if (!targetFolder.exists()) { Preconditions.checkState(targetFolder.mkdirs(), "Failed to ensure parent directories for %s", targetFile); log.debug("Had to create parent directory for " + targetFile); } boolean needBaitAndSwitch = targetFileFile.exists(); if (!needBaitAndSwitch) { fileCreatorLogic.createFile(targetFile); return; } String tempTargetFile = FileUtilsEx.ensureFileNameVacant(targetFile); File tempTargetFileFile = new File(tempTargetFile); boolean newMoved = false; boolean originalDeleted = false; try { fileCreatorLogic.createFile(tempTargetFile); FileUtils.forceDelete(targetFileFile); originalDeleted = true; FileUtils.moveFile(tempTargetFileFile, targetFileFile); newMoved = true; } catch (Throwable t) { if (originalDeleted && !newMoved) { throw new GenericException("exception.tempFileSwitchFailed", t, tempTargetFile, targetFile); } throw t; } }
Example 13
Source File: AsciidocMojo.java From wisdom with Apache License 2.0 | 5 votes |
protected void renderFile(Map<String, Object> options, File f) throws IOException { File filtered = getFilteredVersion(f); boolean unfiltered; if (filtered == null) { // It was not copied. getLog().error("Cannot find the filtered version of " + f.getAbsolutePath() + ", " + "using unprocessed file."); filtered = f; unfiltered = true; } else { // It was copied. unfiltered = false; } instance.renderFile(filtered, options); // Move the file to the expected place if not filtered if (unfiltered) { String name = filtered.getName().substring(0, filtered.getName().lastIndexOf(".")) + ".html"; File output = new File(filtered.getParentFile(), name); if (output.isFile()) { // Move... File finalFile = getOutputFile(filtered, "html"); FileUtils.moveFile(output, finalFile); } else { getLog().error("Cannot find the output file for " + filtered.getAbsolutePath()); } } }
Example 14
Source File: AddonManager.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
private void doBackupOldAddon(AddonInfo oldAddon) throws IOException { //备份 资源文件 String resPath = PathKit.getWebRootPath() + File.separator + "addons" + File.separator + oldAddon.getId(); String resBakPath = resPath + "_bak"; //清空之前的备份文件 File resBakPathDir = new File(resBakPath); if (resBakPathDir.exists()) { FileUtils.deleteDirectory(resBakPathDir); } //备份资源文件 FileUtils.moveDirectory(new File(resPath), resBakPathDir); File jarFile = oldAddon.buildJarFile(); File bakJarFile = new File(jarFile.getAbsolutePath() + "_bak"); if (bakJarFile.exists()) { FileUtils.deleteQuietly(bakJarFile); } //备份jar文件 FileUtils.moveFile(jarFile, bakJarFile); }
Example 15
Source File: FileResourceStore.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
@Override protected void putResourceImpl(String resPath, ContentWriter content, long ts) throws IOException { if (--failPutResourceCountDown == 0) throw new IOException("for test"); File tmp = File.createTempFile("kylin-fileresource-", ".tmp"); try { try (FileOutputStream out = new FileOutputStream(tmp); DataOutputStream dout = new DataOutputStream(out)) { content.write(dout); dout.flush(); } File f = file(resPath); f.getParentFile().mkdirs(); if (!tmp.renameTo(f)) { f.delete(); for (int i = 0; f.exists() && i < 3; i++) { try { Thread.sleep(10); } catch (InterruptedException e) { throw new RuntimeException(e); } f.delete(); } FileUtils.moveFile(tmp, f); } f.setLastModified(ts); } finally { if (tmp.exists()) FileUtils.forceDelete(tmp); } }
Example 16
Source File: LocalStorageManager.java From entando-core with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void editFile(String subPath, boolean isProtectedResource, InputStream is) throws ApsSystemException { subPath = (null == subPath) ? "" : subPath; String fullPath = this.createFullPath(subPath, isProtectedResource); String tempFilePath = null; try { File oldFile = new File(fullPath); if (oldFile.exists()) { String tempDir = System.getProperty("java.io.tmpdir"); tempFilePath = tempDir + File.separator + subPath; FileUtils.copyFile(oldFile, new File(tempFilePath)); } this.saveFile(subPath, isProtectedResource, is); } catch (Throwable t) { try { if (null != tempFilePath) { FileUtils.moveFile(new File(tempFilePath), new File(fullPath)); } } catch (Throwable tr) { logger.error("Error restoring File from path {} to path", tempFilePath, fullPath, tr); } logger.error("Error writing File with path {}", subPath, t); throw new ApsSystemException("Error editing file", t); } finally { if (null != tempFilePath) { boolean deleted = new File(tempFilePath).delete(); if(!deleted) { logger.warn("Failed to delete file {}", tempFilePath); } } } }
Example 17
Source File: FileUtilsCobra.java From obevo with Apache License 2.0 | 5 votes |
public static void moveFile(File srcFile, File destFile) { try { FileUtils.moveFile(srcFile, destFile); } catch (IOException e) { throw new RuntimeException(e); } }
Example 18
Source File: CreateConfigSample.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private static void renameNode(File dir) throws Exception, IOException { File file_node = new File(dir, "node.json"); File file_node_local = new File(dir, "node_127.0.0.1.json"); if (file_node_local.exists()) { file_node_local.delete(); } FileUtils.moveFile(file_node, file_node_local); }
Example 19
Source File: LicenseHeaderUpdate.java From kfs with GNU Affero General Public License v3.0 | 4 votes |
@Override protected void handleFile(File file, int depth, @SuppressWarnings("rawtypes") Collection results) throws IOException { if (isBlacklisted(file.getAbsolutePath())) { System.err.println( "Found blacklisted file, skipping file: " + file.getAbsolutePath() ); results.add("FILE SKIPPED - BLACKLISTED: " + file.getAbsolutePath() ); return; } System.out.println( "Handing File: " + file.getAbsolutePath() ); BufferedReader r = new BufferedReader(new FileReader( file ) ); String currentLine = null; String savedFirstLine = null; // check the initial line of the file String line1 = r.readLine(); // if the file is empty, just skip if ( line1 == null ) { results.add("FILE SKIPPED - EMPTY: " + file.getAbsolutePath() ); return; } if ( line1.startsWith("<?") ) { // special hack for XML files savedFirstLine = line1; line1 = r.readLine(); } if ( line1.trim().equals(firstLine.trim()) ) { // if found, skip until find a line containing the lastLine while ( (currentLine = r.readLine()) != null ) { // throw away the lines if ( currentLine.trim().equals(lastLine.trim()) ) { break; } } if ( currentLine == null ) { // we reached the end of the file before finding the end of the comment, ABORT! System.err.println( "Unable to find end of existing header section, skipping file: " + file.getAbsolutePath() ); results.add("FILE SKIPPED - UNABLE TO FIND END OF HEADER: " + file.getAbsolutePath() ); return; } } File outputFile = new File( file.getAbsolutePath() + "-out" ); BufferedWriter w = new BufferedWriter( new FileWriter( outputFile ) ); if ( savedFirstLine != null ) { w.write( savedFirstLine ); w.write( LINE_SEPARATOR ); } // now, write the new header file w.write( firstLine ); w.write( LINE_SEPARATOR ); BufferedReader headerReader = new BufferedReader( new StringReader( AGPL_LICENSE_TEXT ) ); while ( (currentLine = headerReader.readLine()) != null ) { w.write( linePrefix ); w.write( currentLine ); w.write( LINE_SEPARATOR ); } if ( lastLine.equals(LINE_SEPARATOR) ) { // special hack for SQL files w.write("--" + LINE_SEPARATOR); w.write( LINE_SEPARATOR ); } else { w.write( lastLine ); w.write( LINE_SEPARATOR ); } headerReader.close(); if ( !line1.trim().equals(firstLine.trim()) ) { w.write( line1 ); w.write( LINE_SEPARATOR ); } while ( (currentLine = r.readLine()) != null ) { w.write(currentLine); w.write(LINE_SEPARATOR); } // delete the original file and replace with the completed output file w.close(); r.close(); FileUtils.deleteQuietly(file); FileUtils.moveFile(outputFile, file); }
Example 20
Source File: Sample364TestCase.java From product-ei with Apache License 2.0 | 3 votes |
@BeforeClass(alwaysRun = true) public void initialize() throws Exception { super.init(); NodeList nodeList = context.getConfigurationNodeList("//datasource"); mysqlConnection = createMySqlConnection(nodeList); addDB(); datasourceOriginalPath = FrameworkPathUtil.getCarbonHome() + File.separator + "repository" + File.separator + "conf" + File.separator + "datasources" + File.separator + "master-datasources.xml"; datasourceBkupPath = FrameworkPathUtil.getCarbonHome() + File.separator + "repository" + File.separator + "conf" + File.separator + "datasources" + File.separator + "master-datasources.xml_bk"; serverManager = new ServerConfigurationManager(context); //copping dependency jms jar files to component/lib serverManager.copyToComponentLib(new File(FrameworkPathUtil.getSystemResourceLocation() + File.separator + "artifacts" + File.separator + "ESB" + File.separator + "jar" + File.separator + MYSQL_LIB)); FileUtils.moveFile(new File(datasourceOriginalPath), new File(datasourceBkupPath)); FileUtils.copyFile(new File(FrameworkPathUtil.getSystemResourceLocation() + File.separator + "artifacts" + File.separator + "ESB" + File.separator + "other" + File.separator + "master-datasources.xml"), new File(datasourceOriginalPath)); serverManager.restartGracefully(); super.init(); loadSampleESBConfiguration(364); }