List of usage examples for org.apache.commons.io FileUtils touch
public static void touch(File file) throws IOException
From source file:net.sourceforge.atunes.kernel.modules.cdripper.FakeEncoder.java
@Override public boolean encode(final File originalFile, final File encodedFile) { Logger.info("Encoding with fake encoder"); Logger.info("Original file: ", net.sourceforge.atunes.utils.FileUtils.getPath(originalFile)); Logger.info("Encoded file: ", net.sourceforge.atunes.utils.FileUtils.getPath(encodedFile)); // Create file try {/* w w w . ja v a 2s .com*/ FileUtils.touch(encodedFile); } catch (IOException e1) { Logger.error(e1); } // Simulate encoding to wav for an amount of time for (int i = 0; i <= 10; i++) { final int progress = i * 10; try { Thread.sleep(200); GuiUtils.callInEventDispatchThread(new Runnable() { @Override public void run() { getListener().notifyProgress(progress); } }); } catch (InterruptedException e) { Logger.error(e); return false; } } return true; }
From source file:com.linkedin.pinot.core.segment.creator.impl.fwd.SingleValueUnsortedForwardIndexCreator.java
public SingleValueUnsortedForwardIndexCreator(FieldSpec spec, File baseIndexDir, int cardinality, int numDocs, int totalNumberOfValues, boolean hasNulls) throws Exception { forwardIndexFile = new File(baseIndexDir, spec.getName() + V1Constants.Indexes.UN_SORTED_SV_FWD_IDX_FILE_EXTENTION); this.spec = spec; FileUtils.touch(forwardIndexFile); maxNumberOfBits = getNumOfBits(cardinality); sVWriter = new FixedBitSingleValueWriter(forwardIndexFile, numDocs, maxNumberOfBits); }
From source file:com.linkedin.pinot.core.segment.creator.impl.fwd.MultiValueUnsortedForwardIndexCreator.java
public MultiValueUnsortedForwardIndexCreator(FieldSpec spec, File baseIndexDir, int cardinality, int numDocs, int totalNumberOfValues, boolean hasNulls) throws Exception { forwardIndexFile = new File(baseIndexDir, spec.getName() + V1Constants.Indexes.UN_SORTED_MV_FWD_IDX_FILE_EXTENTION); this.spec = spec; FileUtils.touch(forwardIndexFile); maxNumberOfBits = SingleValueUnsortedForwardIndexCreator.getNumOfBits(cardinality); mVWriter = new FixedBitMultiValueWriter(forwardIndexFile, numDocs, totalNumberOfValues, maxNumberOfBits); }
From source file:cat.calidos.morfeu.utils.FileSaver.java
public void save() throws SavingException { File destinationFile = new File(destination); if (destinationFile.isDirectory()) { log.error("Cannot save to '{}' as it is a folder and not a file", destination); throw new SavingException("Could not save to '" + destination + "' as it is a folder and not a file"); }/* w w w .jav a 2 s .c om*/ try { FileUtils.touch(destinationFile); } catch (IOException e) { log.error("Cannot save to '{}' as we cannot even touch it", destination); throw new SavingException("Could not save to '" + destination + "' as we cannot write to it", e); } if (!destinationFile.canWrite()) { log.error("Cannot save to '{}' as we cannot write to it", destination); throw new SavingException("Could not save to '" + destination + "' as we cannot write to it"); } if (destinationFile.exists()) { String backupPath = destinationFile.getAbsolutePath() + BACKUP_EXTENSION; log.info("Renaming old '{}' to '{}'", destination, backupPath); File backupFile = new File(backupPath); if (backupFile.exists()) { backupFile.delete(); } destinationFile.renameTo(backupFile); } try { FileUtils.writeStringToFile(destinationFile, content, Config.DEFAULT_CHARSET); } catch (IOException e) { log.error("Removing old '{}' to replace it with new content", destination); throw new SavingException("Could not save to '" + destination + "' due to IO problems", e); } }
From source file:net.lmxm.ute.utils.FileSystemUtilsTest.java
/** * Test convert to file objects./*from w w w . j a v a2 s .c om*/ * * @throws IOException Signals that an I/O exception has occurred. */ @Test public void testConvertToFileObjects() throws IOException { // Create temp file that we can locate final File tempFile1 = File.createTempFile("UTE", ".TESTFILE"); FileUtils.touch(tempFile1); tempFile1.deleteOnExit(); final File tempFile2 = File.createTempFile("ute", ".testfile"); FileUtils.touch(tempFile2); tempFile2.deleteOnExit(); // Run the test final FileReference fileReference = new FileReference(); fileReference.setName("UTE*.TESTFILE"); final List<FileReference> fileReferences = new ArrayList<FileReference>(); fileReferences.add(fileReference); final List<File> files = FileSystemUtils.convertToFileObjects(TMP_DIR, fileReferences); assertNotNull(files); assertTrue(files.size() == 1); // Delete the temp file we created for this test tempFile1.delete(); tempFile2.delete(); }
From source file:com.linkedin.pinot.core.segment.index.loader.LoaderUtilsTest.java
@Test public void testReloadFailureRecovery() throws IOException { String segmentName = "dummySegment"; String indexFileName = "dummyIndex"; File indexDir = new File(TEST_DIR, segmentName); File segmentBackupDir = new File(TEST_DIR, segmentName + CommonConstants.Segment.SEGMENT_BACKUP_DIR_SUFFIX); File segmentTempDir = new File(TEST_DIR, segmentName + CommonConstants.Segment.SEGMENT_TEMP_DIR_SUFFIX); // Only index directory exists (normal case, or failed before the first renaming) Assert.assertTrue(indexDir.mkdir()); FileUtils.touch(new File(indexDir, indexFileName)); LoaderUtils.reloadFailureRecovery(indexDir); Assert.assertTrue(indexDir.exists()); Assert.assertTrue(new File(indexDir, indexFileName).exists()); Assert.assertFalse(segmentBackupDir.exists()); Assert.assertFalse(segmentTempDir.exists()); FileUtils.deleteDirectory(indexDir); // Only segment backup directory exists (failed after the first renaming but before copying happened) Assert.assertTrue(segmentBackupDir.mkdir()); FileUtils.touch(new File(segmentBackupDir, indexFileName)); LoaderUtils.reloadFailureRecovery(indexDir); Assert.assertTrue(indexDir.exists()); Assert.assertTrue(new File(indexDir, indexFileName).exists()); Assert.assertFalse(segmentBackupDir.exists()); Assert.assertFalse(segmentTempDir.exists()); FileUtils.deleteDirectory(indexDir); // Index directory and segment backup directory exist (failed before second renaming) Assert.assertTrue(indexDir.mkdir()); Assert.assertTrue(segmentBackupDir.mkdir()); FileUtils.touch(new File(segmentBackupDir, indexFileName)); LoaderUtils.reloadFailureRecovery(indexDir); Assert.assertTrue(indexDir.exists()); Assert.assertTrue(new File(indexDir, indexFileName).exists()); Assert.assertFalse(segmentBackupDir.exists()); Assert.assertFalse(segmentTempDir.exists()); FileUtils.deleteDirectory(indexDir); // Index directory and segment temporary directory exist (failed after second renaming) Assert.assertTrue(indexDir.mkdir()); FileUtils.touch(new File(indexDir, indexFileName)); Assert.assertTrue(segmentTempDir.mkdir()); LoaderUtils.reloadFailureRecovery(indexDir); Assert.assertTrue(indexDir.exists()); Assert.assertTrue(new File(indexDir, indexFileName).exists()); Assert.assertFalse(segmentBackupDir.exists()); Assert.assertFalse(segmentTempDir.exists()); FileUtils.deleteDirectory(indexDir); }
From source file:com.util.FileService.java
/** * This tests the file lock to see if a file is in use if there is an issue * with the file beyond being locked then an exception is thrown and placed * into the database.// ww w .j a va 2s .c o m * * @param path String * @return boolean */ public static boolean testFileLock(String path) { File PDFfile = new File(path); if (PDFfile.exists() && PDFfile.isDirectory() == false) { try { FileUtils.touch(PDFfile); return true; } catch (IOException ex) { System.out.println("file in use: " + PDFfile); ExceptionHandler.Handle(ex); return false; } } else if (PDFfile.exists() == false) { // System.out.println("file does not exist: " + PDFfile); SECExceptionsModel item = new SECExceptionsModel(); item.setClassName("FileService"); item.setMethodName("testFileLock"); item.setExceptionType("FileMissing"); item.setExceptionDescription("Can't Stamp Scan, File Missing: " + PDFfile); ExceptionHandler.HandleNoException(item); } else if (PDFfile.isDirectory() == false) { // System.out.println("file is a directory: " + PDFfile); SECExceptionsModel item = new SECExceptionsModel(); item.setClassName("FileService"); item.setMethodName("testFileLock"); item.setExceptionType("NotAFile"); item.setExceptionDescription("Can't Stamp Scan, is Directory: " + PDFfile); } return false; }
From source file:net.sourceforge.atunes.kernel.modules.cdripper.FakeCDToWavConverter.java
/** * @param file/*from w w w . j a v a 2s . com*/ * @return true */ private boolean waitConversion(final File file) { // Create file try { FileUtils.touch(file); } catch (IOException e) { Logger.error(e); } // Simulate converting to wav for an amount of time for (int i = 0; i <= 10; i++) { final int progress = i * 10; try { Thread.sleep(200); GuiUtils.callInEventDispatchThread(new Runnable() { @Override public void run() { getListener().notifyProgress(progress); } }); } catch (InterruptedException e) { Logger.error(e); return false; } } return true; }
From source file:com.github.neio.filesystem.paths.TestDirectoryPath.java
@Test(expected = PathException.class) public void test_directoryExists_ButWasFile() throws IOException { FileUtils.touch(new File(testDir, "tempFile")); new DirectoryPath("./testTempDir/tempFile"); }
From source file:com.BuildCraft.install.InstallMain.java
private void doInstall() { boolean installSuccessful = true; for (int i = 0; i < fileList.length; i++) { if (!fileList[i].exists()) { if (isDirectory[i]) { ConsoleOut.printMsgNNL("InstallMain: Creating directory " + fileList[i].getName() + "..."); try { FileUtils.forceMkdir(fileList[i]); ConsoleOut.printMsg("Done!"); } catch (Exception ex) { installSuccessful = false; ConsoleOut.printMsg("Failed!"); }/*from w w w . jav a2s .co m*/ } else { ConsoleOut.printMsgNNL("InstallMain: Creating file " + fileList[i].getName() + "..."); try { FileUtils.touch(fileList[i]); ConsoleOut.printMsg("Done!"); } catch (Exception ex) { installSuccessful = false; ConsoleOut.printMsg("Failed!"); } } } } }