IoSupport { public static synchronized <A> A locked(File file, Function<File, A> f) throws NotFoundException, IOException { final Effect0 key = acquireLock(file); try { return f.apply(file); } finally { key.apply(); } } private  IoSupport(); static String getSystemTmpDir(); static boolean closeQuietly(final Closeable s); static boolean closeQuietly(final StreamHelper s); static boolean closeQuietly(final Process process); static void writeUTF8File(URL file, String contents); static void writeUTF8File(File file, String contents); static void writeUTF8File(String filename, String contents); @Deprecated static String readFileFromURL(URL url); @Deprecated static String readFileFromURL(URL url, TrustedHttpClient trustedClient); static Properties loadPropertiesFromUrl(final URL url); static Properties loadPropertiesFromStream(final InputStream stream); static Option<String> loadTxtFromClassPath(final String resource, final Class<?> clazz); @Deprecated static A withStream(InputStream s, Function<InputStream, A> f); static A withResource(B b, Function<B, A> f); static A withResource(B b, Fn<? super B, ? extends A> f); static Option<InputStream> openClassPathResource(String resource, Class<?> clazz); static Option<InputStream> openClassPathResource(String resource); static Option<File> classPathResourceAsFile(String resource); static Option<String> loadFileFromClassPathAsString(String resource, Class<?> clazz); static Option<String> loadFileFromClassPathAsString(String resource); static Option<A> withFile(File file, Function2<InputStream, File, A> f); @Deprecated static Either<Err, A> withStream(Function0<InputStream> s, Function<Exception, Err> toErr,
          Function<InputStream, A> f); static Either<Err, A> withResource(Function0<B> r,
          Function<Exception, Err> toErr, Function<B, A> f); @Deprecated static A withStream(OutputStream s, Function<OutputStream, A> f); static Function0<InputStream> fileInputStream(final File a); static File file(String... pathElems); static synchronized A locked(File file, Function<File, A> f); static A serializeDeserialize(final A a); static final Function<InputStream, String> readToString; }
@Test public void testDeleteLockedFile() throws Exception { final File dst = testFolder.newFile("test.tmp"); final File src = new File(this.getClass().getResource("/dublincore.xml").toURI()); locked(dst, new Effect.X<File>() { @Override protected void xrun(File file) throws IOException { file.delete(); FileSupport.copy(src, file); } }); assertTrue(dst.isFile()); assertEquals(src.length(), dst.length()); }