You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-user@hadoop.apache.org by Public Network Services <pu...@gmail.com> on 2013/08/09 01:54:30 UTC

Converting a Path to a full URI String and preserving special characters

Is there a reliable way of converting an HDFS Path object into a String?

Invoking path.toUri().toString() does not work with special characters
(e.g., if there are spaces in the original path string). So, for instance,
in the following example

String address = ...; // Path string without the hdfs://.../ prefix and
with special characters
Path path = new Path(address);
String pathString = path.toString();

the string variables "address" and "pathString" are not identical.

What I am after is a way to always get the full URL (including the
hdfs://.../ prefix) from a string address converted to a path and then back
to a string, even if the original address did not include the the
hdfs://.../ prefix.

My impression was that this is done via path.toString() all the time, but I
am getting some results where this is not the case.