FileHelper { public static boolean updateTimestamp(final String path, final boolean recursive) throws IOException { if (path == null || "".equals(path)) { return false; } if (!FileHelper.doesDirectoryOrFileExist(path)) { return false; } if (recursive) { Iterator<File> files = FileUtils.iterateFiles(new File(path), null, true); while (files.hasNext()) { File file = files.next(); FileUtils.touch(file); log.debug(new StringBuilder("Updated timestamp on file: ").append(file.getPath()).toString()); } } else { FileUtils.touch(new File(path)); log.debug(new StringBuilder("Updated timestamp on file: ").append(new File(path).getPath()).toString()); } return true; }  static byte[] base64Encode(final File input); static byte[] base64Encode(final byte[] input); static byte[] getByteArrayFromFile(File file); static boolean renameFile(final File fromFile, final String toFileName); static boolean copyFileToPath(final File inFile, final String outFilePath); static boolean copyFileToPath(final File inFile, final String outPath, boolean deleteOriginalFile); static Collection<File> wipeOldFiles(File directory, Long cutoffTime, boolean deleteDirectory); static boolean createDir(File directory); static boolean createDir(String directory); static boolean deleteDirRecursively(File directory); static boolean deleteDirRecursively(String directory); static boolean deleteFileQuietly(String filePath); static boolean deleteFileQuietly(File file); static boolean deleteFile(String filePath); static boolean deleteFile(File file); static boolean doesDirectoryOrFileExist(String filePath); static File findFile(String file, String rootPath); static List<String> getFileList(String filePath, boolean recursive); static List<String> getFileList(String filePath, String[] extensions, boolean recursive); static Collection<File> getFileCollection(String filePath, boolean recursive); static Collection<?> getFileCollection(String filePath, String[] extensions, boolean recursive); static String getSystemTemp(); static boolean zipDirectory(String inputDirectory, String absoluteFileName); static boolean unzipFile(String outputDirectory, File zipFile); static String createUserDirectory(String applicationUserSpaceDir); static boolean updateTimestamp(final String path, final boolean recursive); static Boolean validateShapeFile(final File shapeFile); static Boolean validateShapeZIP(final File shapeZip);  }
@Test public void testUpdateTimeStampWithNullPath() { System.out.println("Test: " + "testUpdateTimeStampWithNullPath"); boolean result = true; try { result = FileHelper.updateTimestamp(null, true); } catch (IOException ex) { Logger.getLogger(FileHelperTest.class.getName()).log(Level.SEVERE, null, ex); } assertFalse(result); }
@Test public void testUpdateTimeStampWithEmptyStringPath() { System.out.println("Test: " + "testUpdateTimeStampWithEmptyStringPath"); boolean result = true; try { result = FileHelper.updateTimestamp("", true); } catch (IOException ex) { Logger.getLogger(FileHelperTest.class.getName()).log(Level.SEVERE, null, ex); } assertFalse(result); }
@Test public void testUpdateTimeStampOnSingleFile() { System.out.println("Test: " + "testUpdateTimeStampOnSingleFile"); File file1 = new File(FileHelperTest.testFilePath + ".dbf"); long file1Date = file1.lastModified(); boolean result = true; try { result = FileHelper.updateTimestamp(FileHelperTest.testFilePath + ".dbf", false); } catch (IOException ex) { Logger.getLogger(FileHelperTest.class.getName()).log(Level.SEVERE, null, ex); } assertTrue(result); File file2 = new File(FileHelperTest.testFilePath + ".dbf"); long file2Date = file2.lastModified(); assertTrue(file2Date > file1Date); }
@Test public void testUpdateTimeStampOnSingleNonexistentFile() { System.out.println("Test: " + "testUpdateTimeStampOnSingleNonexistentFile"); File file1 = new File(FileHelperTest.testFilePath); long file1Date = file1.lastModified(); boolean result = true; try { result = FileHelper.updateTimestamp(FileHelperTest.testFilePath, false); } catch (IOException ex) { Logger.getLogger(FileHelperTest.class.getName()).log(Level.SEVERE, null, ex); } assertFalse(result); }
@Test public void testUpdateTimeStampOnSingleDirectoryRecursive() { System.out.println("Test: " + "testUpdateTimeStampOnSingleDirectoryRecursive"); File file1 = new File(FileHelperTest.sampleDir); long file1Date = file1.lastModified(); boolean result = true; try { result = FileHelper.updateTimestamp(FileHelperTest.sampleDir, true); } catch (IOException ex) { Logger.getLogger(FileHelperTest.class.getName()).log(Level.SEVERE, null, ex); } assertTrue(result); }