List of usage examples for org.apache.commons.io FileUtils touch
public static void touch(File file) throws IOException
From source file:org.dataconservancy.dcs.util.stream.fs.FilesystemStreamSourceTest.java
@Test public void testStreams() throws Exception { final FilesystemStreamSource underTest = new FilesystemStreamSource(tmpDir); int count = 0; for (String streamId : underTest.streams()) { count++;/*from ww w.jav a2 s .c o m*/ } assertEquals(expectedCount, count); // Add a file and reset the count FileUtils.touch(new File(tmpDir, String.valueOf(expectedCount + 1))); count = 0; for (String streamId : underTest.streams()) { count++; } assertEquals(expectedCount + 1, count); }
From source file:org.dataconservancy.dcs.util.stream.fs.FilesystemStreamSourceTest.java
@Test public void testStreamsModifiedSinceNow() throws Exception { Thread.sleep(ONE_SECOND);//from www . jav a2 s .c o m final Calendar methodStart = Calendar.getInstance(); final FilesystemStreamSource underTest = new FilesystemStreamSource(tmpDir); int count = 0; for (String streamId : underTest.streams(methodStart)) { count++; } assertEquals(0, count); // Sleep for a second Thread.sleep(ONE_SECOND); // Add a file and reset the count FileUtils.touch(new File(tmpDir, String.valueOf(expectedCount + 1))); count = 0; for (String streamId : underTest.streams(methodStart)) { count++; } assertEquals(1, count); }
From source file:org.dataconservancy.dcs.util.stream.fs.FilesystemStreamSourceTest.java
@Test public void testStreamsModifiedSinceStart() throws Exception { final Calendar methodStart = Calendar.getInstance(); final FilesystemStreamSource underTest = new FilesystemStreamSource(tmpDir); int count = 0; for (String streamId : underTest.streams(CLASS_INSTANTIATED_AT)) { count++;/*from w w w .ja v a 2s . c o m*/ } assertEquals(expectedCount, count); // Add a file and reset the count FileUtils.touch(new File(tmpDir, String.valueOf(expectedCount + 1))); count = 0; for (String streamId : underTest.streams(CLASS_INSTANTIATED_AT)) { count++; } assertEquals(expectedCount + 1, count); }
From source file:org.dataconservancy.dcs.util.stream.fs.ModifiedSinceFileFilterTest.java
@Test public void testModifiedSinceAfter() throws IOException, InterruptedException { final File tempFile = new File(tempDir, "a file"); FileUtils.touch(tempFile); log.debug("Created temp file {}", tempFile); Thread.sleep(ONE_SECOND);/*from www . j a v a 2 s . c o m*/ assertTrue(FileUtils .listFiles(tempDir, new ModifiedSinceFileFilter(Calendar.getInstance()), TrueFileFilter.TRUE) .isEmpty()); }
From source file:org.dataconservancy.dcs.util.stream.fs.ModifiedSinceFileFilterTest.java
@Test public void testModifiedSinceAfterRecurseDirectories() throws IOException, InterruptedException { final File tempDir = createTemporaryDirectory(this.tempDir); final File tempFile = new File(tempDir, "a file"); log.debug("Created temp file {}", tempFile); FileUtils.touch(tempFile); Thread.sleep(ONE_SECOND);/* w ww.j av a2 s . co m*/ assertTrue(FileUtils .listFiles(tempDir, new ModifiedSinceFileFilter(Calendar.getInstance()), TrueFileFilter.TRUE) .isEmpty()); }
From source file:org.dataconservancy.dcs.util.stream.fs.ModifiedSinceFileFilterTest.java
@Test public void testModifiedSinceBefore() throws IOException, InterruptedException { final File tempFile = new File(tempDir, "a file"); FileUtils.touch(tempFile); log.debug("Created temp file {}", tempFile); final Iterator files = FileUtils .listFiles(tempDir, new ModifiedSinceFileFilter(CLASS_INSTANTIATED_AT), TrueFileFilter.TRUE) .iterator();//from www .j av a2 s .com int count = 0; while (files.hasNext()) { count++; files.next(); } assertEquals(1, count); }
From source file:org.dataconservancy.dcs.util.stream.fs.ModifiedSinceFileFilterTest.java
@Test public void testModifiedSinceBeforeRecurseDirectories() throws IOException, InterruptedException { final File tempDir = createTemporaryDirectory(this.tempDir); final File tempFile = new File(tempDir, "a file"); FileUtils.touch(tempFile); log.debug("Created temp file {}", tempFile); final Iterator files = FileUtils .listFiles(tempDir, new ModifiedSinceFileFilter(CLASS_INSTANTIATED_AT), TrueFileFilter.TRUE) .iterator();//from ww w. ja va 2s .c o m int count = 0; while (files.hasNext()) { count++; files.next(); } assertEquals(1, count); }
From source file:org.devproof.portal.core.module.theme.service.ThemeServiceImpl.java
@Override public void install(File themeArchive) { String uuid = UUID.randomUUID().toString(); try {//from w ww.j a va 2 s . c o m File folder = new File(servletContext.getRealPath("/WEB-INF/themes")); folder = new File(folder.toString() + File.separator + uuid); FileUtils.forceMkdir(folder); ZipFile zipFile = new ZipFile(themeArchive); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File out = new File(folder.getAbsolutePath() + File.separator + entry.getName()); if (entry.isDirectory()) { FileUtils.forceMkdir(out); } else { FileUtils.touch(out); FileOutputStream fos = new FileOutputStream(out, false); IOUtils.copy(zipFile.getInputStream(entry), fos); fos.close(); } } zipFile.close(); logger.info("New theme installed: " + uuid); } catch (MalformedURLException e) { logger.warn("Unknown error", e); } catch (IOException e) { logger.warn("Unknown error", e); } }
From source file:org.dicen.recolnat.services.core.data.UserProfileResource.java
/** * Save a message from the user (feedback about the application) in a local directory. * @param feedbackType Short type description of the feedback type (for example: bug, suggestion) * @param message Text of the message//from ww w .j a v a 2 s. c om * @param rsvp If the user would like a response by mail to his request. * @param userLogin Login of the user providing the feedback. * @throws IOException * @throws JSONException */ public static void postFeedback(String feedbackType, String message, Boolean rsvp, String userLogin) throws IOException, JSONException { File output = new File("./feedback/" + userLogin + "-" + dateFormat.format(new Date())); FileUtils.touch(output); FileUtils.writeStringToFile(output, feedbackType + System.getProperty("line.separator")); FileUtils.writeStringToFile(output, message + System.getProperty("line.separator"), true); if (rsvp) { FileUtils.writeStringToFile(output, "RSVP" + System.getProperty("line.separator"), true); } }
From source file:org.duracloud.mill.audit.generator.LogManagerImplTest.java
@Test public void testFlushLogs() throws IOException { int fileCount = 3; List<File> files = new ArrayList<>(); for (int i = 0; i < fileCount; i++) { File file = new File(logsRootDir, "test-log-" + i); FileUtils.touch(file); if (i < fileCount - 1) { createFileOfLength(file, SpaceLog.MAX_FILE_SIZE); } else {/*from w ww . ja v a 2 s. c om*/ createFileOfLength(file, SpaceLog.MAX_FILE_SIZE - 1); } files.add(file); String contentId = ContentIdUtil.getContentId(file, logsRootDir, null); expect(this.storageProvider.addContent(eq(logSpace), eq(contentId), isA(String.class), isNull(Map.class), eq(file.length()), isA(String.class), isA(InputStream.class))) .andReturn("checksum"); } replayAll(); createManager(); this.manager.flushLogs(); assertTrue(!files.get(0).exists()); assertTrue(!files.get(1).exists()); assertTrue(files.get(2).exists()); }