users@jersey.java.net

Re: [Jersey] .toASCIIString instead of .toString

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 17 Jun 2008 11:54:40 +0200

Hi Max,

Nice catch, we should fix those. A bit of context to remind ourselves:
these are associated with the Bookmark example.

Paul.

Max Scheffler wrote:
> Hi there,
>
> I found some code snippets in the jersey examples which look like the
> following:
>
> URI userUri = ub.
> path(userEntity.getUserid()).
> build();
> uriArray.put(userUri.toString());
>
> which means nothing else than using the .toString method from the URI class.
>
> I found the .toASCIIString() method of URI. The JavaDoc of this method
> tells us:
>
> Returns the content of this URI as a US-ASCII string.
>
> If this URI does not contain any characters in the other category then
> an invocation of this method will return the same value as an
> invocation of the toString method. Otherwise this method works as if
> by invoking that method and then encoding the result.
>
> @return The string form of this URI, encoded as needed
> so that it only contains characters in the US-ASCII
> charset
>
> IMHO is the .toASCIIString() method the more right one to generate a
> String from a URI.
>
> To prove that I'm right i wrote this little test:
>
> public static void main ( String[] args ) throws URISyntaxException {
> URI uri = new URI( "http://www.example.org/дц" );
> System.out.println( uri.toString() );
> System.out.println( uri.toASCIIString() );
> }
>
> Which returns the following to me:
>
> http://www.example.org/?
> http://www.example.org/%C3%A4%C3%B6
>
> Greetings
> Max

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109