Java Reference
In-Depth Information
Normalization
Normalization istheprocessofremovingunnecessary“.”and“..”pathsegmentsfroma
hierarchicalURI'spathcomponent.Each“.”segmentisremoved.A“..”segmentisre-
movedonlywhenit'sprecededbyanon-“..”segment.Normalizationhasnoeffectupon
opaque URIs.
URI declares a URI normalize() method for normalizing a URI. This method
returns a new URI object that contains the normalized equivalent of its caller's URI.
Listing 9-11 presents an application that lets you experiment with normalize() .
Listing 9-11. Normalizing URIs
import java.net.URI;
import java.net.URISyntaxException;
class Normalize
{
public static void main(String[] args) throws URISyn-
taxException
{
if (args.length != 1)
{
System.err.println("usage: java normalize uri");
return;
}
URI uri = new URI(args[0]);
System.out.println("normalized
uri
=
"+uri.normalize());
}
}
Compile Listing9-11 ( javac Normalize.java )andruntheapplicationasfol-
lows: java Normalize a/b/../c/./d .Youshouldobservethefollowingout-
put, which shows that b isn't part of a normalized URI:
Normalized URI = a/c/d
Search WWH ::




Custom Search