Bundles { public static void safeMove(Path source, Path destination) throws IOException { safeMoveOrCopy(source, destination, true); }  static void closeAndSaveBundle(Bundle bundle, Path destination); static Path closeBundle(Bundle bundle); static void copyRecursively(final Path source,
			final Path destination, final CopyOption... copyOptions); static Bundle createBundle(); static Bundle createBundle(Path path); static void deleteRecursively(Path p); static Path getAnnotations(Bundle bundle); static Path getManifestPath(Bundle bundle); static String getMimeType(Bundle bundle); static URI getReference(Path path); static String getStringValue(Path path); static boolean isMissing(Path item); static boolean isReference(Path path); static boolean isValue(Path path); static Bundle openBundle(InputStream in); static Bundle openBundle(Path zip); static Bundle openBundle(URL url); static Bundle openBundleReadOnly(Path zip); static void safeCopy(Path source, Path destination); static void safeMove(Path source, Path destination); static void setMimeType(Bundle bundle, String mimetype); static Path setReference(Path path, URI ref); static void setStringValue(Path path, String string); static Path uriToBundlePath(Bundle bundle, URI uri);  }
@Test public void safeMove() throws Exception { Path tmp = Files.createTempDirectory("test"); tmp.toFile().deleteOnExit(); Path f1 = tmp.resolve("f1"); f1.toFile().deleteOnExit(); Files.createFile(f1); assertFalse(isEmpty(tmp)); try (Bundle db = Bundles.createBundle()) { Path f2 = db.getRoot().resolve("f2"); Bundles.safeMove(f1, f2); assertFalse(Files.exists(f1)); assertTrue(isEmpty(tmp)); assertEquals(Arrays.asList("f2", "mimetype"), ls(db.getRoot())); } }
@Test(expected = IOException.class) public void safeMoveFails() throws Exception { Path tmp = Files.createTempDirectory("test"); tmp.toFile().deleteOnExit(); Path f1 = tmp.resolve("f1"); f1.toFile().deleteOnExit(); Path d1 = tmp.resolve("d1"); d1.toFile().deleteOnExit(); Files.createFile(f1); Files.createDirectory(d1); Files.createFile(d1.resolve("child")); try { Bundles.safeMove(f1, d1); } finally { assertTrue(Files.exists(f1)); assertEquals(Arrays.asList("d1", "f1"), ls(tmp)); } }