public void syncFileResource(ResourceUri resourceUri, Consumer<String> resourceGenerator)
            throws IOException {
        Path targetPath = new Path(resourceUri.getUri());
        String localPath;
        boolean remote = isRemotePath(targetPath);
        if (remote) {
            localPath = getResourceLocalPath(targetPath).getPath();
        } else {
            localPath = getURLFromPath(targetPath).getPath();
        }
        resourceGenerator.accept(localPath);
        if (remote) {
            if (exists(targetPath)) {
                // FileUtils#copy will not do copy if targetPath already exists
                targetPath.getFileSystem().delete(targetPath, false);
            }
            FileUtils.copy(new Path(localPath), targetPath, false);
        }
    }
@Test
    public void testSyncFileResource() throws Exception {
        String targetUri = tempFolder.getAbsolutePath() + "foo/bar.txt";
        ResourceUri resource = new ResourceUri(ResourceType.FILE, targetUri);
        resourceManager.syncFileResource(
                resource,
                path -> {
                    try {
                        FileUtils.copy(new Path(file.getPath()), new Path(path), false);
                    } catch (IOException e) {
                        fail("Test failed.", e);
                    }
                });
        assertThat(FileUtils.readFileUtf8(new File(targetUri))).isEqualTo("Hello World");

        // test overwrite
        resourceManager.syncFileResource(
                resource,
                path -> {
                    try {
                        Files.write(
                                new File(targetUri).toPath(),
                                "Bye Bye".getBytes(StandardCharsets.UTF_8),
                                StandardOpenOption.CREATE,
                                StandardOpenOption.TRUNCATE_EXISTING,
                                StandardOpenOption.WRITE);
                    } catch (IOException e) {
                        fail("Test failed.", e);
                    }
                });
        assertThat(FileUtils.readFileUtf8(new File(targetUri))).isEqualTo("Bye Bye");
    }