public static void delete(File dest) throws IOException { delete(dest, fileUtilParams); }
@Test void testZipBuilderFile() throws IOException { File zipFile = new File(dataRoot, "test.zip"); ZipBuilder.createZipFile(zipFile) .add(new File(dataRoot, "sb.data")) .path("sbdata").comment("This is sb data file").save() .add(new File(dataRoot, "file")) .path("folder").comment("This is a folder and all its files").save() .toZipFile(); assertTrue(zipFile.exists()); ZipUtil.unzip(zipFile, new File(dataRoot), "sbda*"); assertTrue(new File(dataRoot, "sbdata").exists()); assertFalse(new File(dataRoot, "folder").exists()); ZipUtil.unzip(zipFile, new File(dataRoot)); assertTrue(new File(dataRoot, "sbdata").exists()); assertTrue(new File(dataRoot, "folder").exists()); assertTrue(new File(new File(dataRoot, "folder"), "a.png").exists()); // cleanup FileUtil.delete(new File(dataRoot, "sbdata")); FileUtil.deleteDir(new File(dataRoot, "folder")); FileUtil.delete(zipFile); }
public static void delete(String dest) throws IOException { delete(file(dest), fileUtilParams); }
public static void delete(String dest, FileUtilParams params) throws IOException { delete(file(dest), params); }
/** * @see #delete(File) */ public static void delete(final String dest) throws IOException { delete(file(dest)); }
@Test void testZip() throws IOException { ZipUtil.zip(new File(dataRoot, "sb.data")); File zipFile = new File(dataRoot, "sb.data.zip"); assertTrue(zipFile.exists()); // cleanup FileUtil.delete(zipFile); ZipUtil.zip(new File(dataRoot, "file")); zipFile = new File(dataRoot, "file.zip"); assertTrue(zipFile.exists()); // cleanup FileUtil.delete(zipFile); }
@Test void testZlib() throws IOException { ZipUtil.zlib(new File(dataRoot, "sb.data")); File zlibFile = new File(dataRoot, "sb.data.zlib"); assertTrue(zlibFile.exists()); // cleanup FileUtil.delete(zlibFile); }
@Test void testFileManipulation() throws IOException { FileUtil.copy(new File(dataRoot, "sb.data"), new File(dataRoot, "sb1.data")); assertFalse(FileUtil.isNewer(new File(dataRoot, "sb.data"), new File(dataRoot, "sb1.data"))); assertFalse(FileUtil.isOlder(new File(dataRoot, "sb.data"), new File(dataRoot, "sb1.data"))); FileUtil.delete(new File(dataRoot, "sb1.data")); }
@Test void testZipDir() throws IOException { ZipUtil.zip(new File(dataRoot)); File zipFile = new File(dataRoot + ".zip"); assertTrue(zipFile.exists()); int directoryCount = 0; try (ZipFile zipfile = new ZipFile(zipFile)) { for (Enumeration<? extends ZipEntry> entries = zipfile.entries(); entries.hasMoreElements(); ) { ZipEntry zipEntry = entries.nextElement(); if (zipEntry.isDirectory()) { directoryCount++; assertTrue(zipEntry.getName().equals("data/") || zipEntry.getName().equals("data/file/")); } } } assertEquals(2, directoryCount); // cleanup FileUtil.delete(zipFile); }
@Test void testGzip() throws IOException { ZipUtil.gzip(new File(dataRoot, "sb.data")); File gzipFile = new File(dataRoot, "sb.data.gz"); assertTrue(gzipFile.exists()); FileUtil.move(gzipFile, new File(dataRoot, "sb2.data.gz")); ZipUtil.ungzip(new File(dataRoot, "sb2.data.gz")); File data = new File(dataRoot, "sb2.data"); assertTrue(data.exists()); byte[] data2Bytes = FileUtil.readBytes(data); byte[] data1Bytes = FileUtil.readBytes(new File(dataRoot, "sb.data")); assertTrue(Arrays.equals(data1Bytes, data2Bytes)); // cleanup FileUtil.delete(new File(dataRoot, "sb2.data")); FileUtil.delete(new File(dataRoot, "sb2.data.gz")); }
@Test void testUnicodeString() { String s = "This is a test file\nIt only has\nthree lines!!"; char[] buf = s.toCharArray(); buf[0] = 256; s = new String(buf); try { FileUtil.writeString(dataRoot + "/test2.txt", s, "UTF-16"); } catch (Exception ex) { fail("FileUtil.writeString " + ex.toString()); } String s2 = null; try { s2 = FileUtil.readString(dataRoot + "/test2.txt", "UTF-16"); } catch (Exception ex) { fail("FileUtil.readString " + ex.toString()); } assertEquals(s, s2); try { FileUtil.delete(dataRoot + "/test2.txt"); } catch (IOException ioex) { fail("FileUtil.delete" + ioex.toString()); } }
FileUtil.delete(dataRoot + "/test.txt"); } catch (IOException ioex) { fail("FileUtil.delete" + ioex.toString());
@Test void testDirWatcher() throws IOException { DirWatcher dirWatcher = new DirWatcher(dataRoot, "*.md"); final StringBuilder sb = new StringBuilder(); dirWatcher.register(event -> sb.append(event.type().name() + ":" + event.target().getName() + "\n")); dirWatcher.start(100); File destFile = new File(dataRoot, "jodd.md"); FileUtil.writeString(destFile, "#Jodd"); ThreadUtil.sleep(600); FileUtil.writeString(destFile, "#Jodd2"); ThreadUtil.sleep(600); FileUtil.delete(destFile); ThreadUtil.sleep(600); dirWatcher.stop(); assertEquals( DirWatcherEvent.Type.CREATED + ":jodd.md\n" + DirWatcherEvent.Type.MODIFIED + ":jodd.md\n" + DirWatcherEvent.Type.DELETED + ":jodd.md\n", sb.toString()); }
@Test void testDirWatcherWithFile() throws IOException { DirWatcher dirWatcher = new DirWatcher(dataRoot) .monitor("*.md") .useWatchFile("watch.txt"); final StringBuilder sb = new StringBuilder(); dirWatcher.register( event -> sb.append(event.type().name() + ":" + event.target().getName() + "\n")); dirWatcher.start(100); File watchFile = new File(dataRoot, "watch.txt"); File destFile = new File(dataRoot, "jodd.md"); FileUtil.writeString(destFile, "#Jodd"); FileUtil.touch(watchFile); ThreadUtil.sleep(600); FileUtil.writeString(destFile, "#Jodd2"); ThreadUtil.sleep(600); FileUtil.delete(destFile); FileUtil.touch(watchFile); ThreadUtil.sleep(600); dirWatcher.stop(); assertEquals( DirWatcherEvent.Type.CREATED + ":jodd.md\n" + //DirWatcher.Event.MODIFIED + ":jodd.md\n" + DirWatcherEvent.Type.DELETED + ":jodd.md\n", sb.toString()); }
private void removeLockFile(MongodConfigBuilder builder) { final File lockFile = Paths.get(dataDirectory, "mongod.lock").toFile(); try { delete(lockFile); } catch (Exception e) { logger.warn("No lock file found for embedded mongodb or removal failed: " + e.getMessage()); } }
private void removeLockFile(MongodConfigBuilder builder) { final File lockFile = Paths.get(dataDirectory, "mongod.lock").toFile(); try { delete(lockFile); } catch (Exception e) { logger.warn("No lock file found for embedded mongodb or removal failed: " + e.getMessage()); } }
/** * @see #delete(File) */ public static void delete(final String dest) throws IOException { delete(file(dest)); }