Apache VFS URI with spaces

Apache VFS currently seems to have a problem handling file paths with spaces in them if you want to convert that path to a URI.

Here is a workaround that will at least handle that case (if not every case of wrongly encoded data):

/**
 * Convert a file object to a URI
 *
 * There is a bug in the way that apache VFS handles paths with spaces in
 * https://issues.apache.org/jira/browse/VFS-203?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12675797#action_12675797
 *
 * @param resource the resource to convert
 *
 * @return a valid URI for the file object
 *
 * @throws URISyntaxException
 */
public URI fileObjectToUri(final FileObject resource) throws URISyntaxException
{
   return new URI(resource.getName().getURI().replace(" ", "%20"));
}

Leave a Reply

Your email address will not be published. Required fields are marked *