public String encode(final Path file) {
        final String encoded = URIEncoder.encode(file.getAbsolute());
        if(file.isDirectory()) {
            if(file.isRoot()) {
                return encoded;
            }
            return String.format("%s/", encoded);
        }
        return encoded;
    }
@Test
    public void testEncode() {
        assertEquals("/", new DAVPathEncoder().encode(new Path("/", EnumSet.of(Path.Type.directory))));
        assertEquals("/dav/", new DAVPathEncoder().encode(new Path("/dav", EnumSet.of(Path.Type.directory))));
        assertEquals("/dav", new DAVPathEncoder().encode(new Path("/dav", EnumSet.of(Path.Type.file))));
        assertEquals("/dav/file%20path", new DAVPathEncoder().encode(new Path("/dav/file path", EnumSet.of(Path.Type.file))));
    }