Google Data APIs Client Library (1.41.1)



com.google.gdata.util.httputil
Class FastURLEncoder

java.lang.Object
  extended by com.google.gdata.util.httputil.FastURLEncoder

public class FastURLEncoder
extends java.lang.Object

This class has been deprecated; use CharEscapers.uriEscaper(), CharEscapers.cppUriEscaper() or create your own custom PercentEscaper.

Almost every use of FastURLEncoder can now be replaced with an instance of the PercentEscaper class, which is much faster.

In most cases it should be possible to use the static instances available from CharEscapers but it is also possible to create your own escaper with custom behaviour.

See Deprecating FastURLEncoder for more information.

Note that the new uriEscaper only escapes using UTF-8 encoding and while no examples of other encodings were found when preparing this class for deprecation, it's possible that some instance were missed. If you have a valid reason to escape URIs via an encoding other than UTF-8 please let the java-libraries-team know.

FastURLEncoder is intended as a replacement for the slow and inefficient java.net.URLEncoder. There are a few differences though:

It is possible that URLEncoder is doing really complicated stuff for a reason and that I just don't understand why. If you are unsure of FastURLEncoder just call FastURLEncoder.setVerifyAgainstJava(true). This will run both versions and verify that the outputs are the same. Of course this will be slow but it is useful for testing. I wouldn't be surprised if the two differ for non-latin1, non-utf-8 encodings.

FastURLEncoder requires jdk 1.5.

See Also:
URLEncoder

Field Summary
static java.util.BitSet CPLUSPLUS_COMPAT_SAFE_OCTETS
          Deprecated. Use CharEscapers.cppUriEscaper()
 
Method Summary
static java.util.BitSet createSafeOctetBitSet()
          Deprecated. Use CharEscapers.uriEscaper(). or create an instance of PercentEscaper. See FastURLEncoder for more details.
static java.lang.String encode(java.lang.String s)
          Deprecated. Use CharEscapers.uriEscaper().
static void encode(java.lang.String s, java.lang.Appendable out)
          Deprecated. Use CharEscapers.uriEscaper(). See FastURLEncoder for more details.
static java.lang.String encode(java.lang.String s, java.util.BitSet safeOctets, boolean plusForSpace)
          Deprecated. Use CharEscapers.uriEscaper(). or create an instance of PercentEscaper. See FastURLEncoder for more details.
static java.lang.String encode(java.lang.String s, java.lang.String encoding)
          Deprecated. Use CharEscapers.uriEscaper(). See FastURLEncoder for more details.
static void encode(java.lang.String s, java.lang.String encoding, java.lang.Appendable out)
          Deprecated. Use CharEscapers.uriEscaper(). See FastURLEncoder for more details.
static java.lang.String encode(java.lang.String s, java.lang.String encoding, java.util.BitSet safeOctets, boolean plusForSpace)
          Deprecated. Use CharEscapers.uriEscaper() or create an instance of PercentEscaper. See FastURLEncoder for more details.
static boolean encode(java.lang.String s, java.lang.String encoding, java.util.BitSet safeOctets, boolean plusForSpace, java.lang.Appendable out)
          Deprecated. Use CharEscapers.uriEscaper() or create an instance of PercentEscaper. See FastURLEncoder for more details.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CPLUSPLUS_COMPAT_SAFE_OCTETS

@Deprecated
public static final java.util.BitSet CPLUSPLUS_COMPAT_SAFE_OCTETS
Deprecated. Use CharEscapers.cppUriEscaper()
These octets mimic the ones escaped by the C++ webutil/url URL class -- the kGoogle1Escape set. To produce the same escaping as C++, use this BitSet with the plusForSpace option.

Method Detail

encode

@Deprecated
public static java.lang.String encode(java.lang.String s,
                                                 java.lang.String encoding,
                                                 java.util.BitSet safeOctets,
                                                 boolean plusForSpace)
                               throws java.io.UnsupportedEncodingException
Deprecated. Use CharEscapers.uriEscaper() or create an instance of PercentEscaper. See FastURLEncoder for more details.

URL-escapes s by encoding it with the specified character encoding, and then escaping all octets not included in safeOctets.

Parameters:
s - String to encode.
encoding - character encoding to use (e.g., "UTF-8")
safeOctets - set of octets that should not be escaped.
plusForSpace - whether octet 0x20, i.e. "space", should be encoded as a plus sign rather than "%20". Note that this parameter is effectively ignored if 0x20 is in safeOctets.
Returns:
the encoded version of s. Will return s itself if no encoding is necessary.
Throws:
java.io.UnsupportedEncodingException - if encoding is not supported.

encode

@Deprecated
public static boolean encode(java.lang.String s,
                                        java.lang.String encoding,
                                        java.util.BitSet safeOctets,
                                        boolean plusForSpace,
                                        java.lang.Appendable out)
                      throws java.io.UnsupportedEncodingException,
                             java.io.IOException
Deprecated. Use CharEscapers.uriEscaper() or create an instance of PercentEscaper. See FastURLEncoder for more details.

URL-escapes s by encoding it with the specified character encoding, escaping all octets not included in safeOctets, and then outputting the result to an Appendable.

Parameters:
s - String to encode.
encoding - character encoding to use (e.g., "UTF-8")
safeOctets - set of octets that should not be escaped.
plusForSpace - whether octet 0x20, i.e. "space", should be encoded as a plus sign rather than "%20". Note that this parameter is effectively ignored if 0x20 is in safeOctets.
out - the Appendable destination for the encoded string.
Returns:
true if s did need escaping, false otherwise. In other words, this returns false only if s was output to out verbatim.
Throws:
java.io.UnsupportedEncodingException - if encoding is not supported.
java.io.IOException - if out does so when appended to.

encode

@Deprecated
public static java.lang.String encode(java.lang.String s,
                                                 java.lang.String encoding)
                               throws java.io.UnsupportedEncodingException
Deprecated. Use CharEscapers.uriEscaper(). See FastURLEncoder for more details.

This should be a direct replacement for java.net.URLEncoder.encode().

Parameters:
s - String to encode.
encoding - character encoding to use (e.g., "UTF-8")
Throws:
java.io.UnsupportedEncodingException
See Also:
URLEncoder.encode(String, String)

encode

@Deprecated
public static void encode(java.lang.String s,
                                     java.lang.String encoding,
                                     java.lang.Appendable out)
                   throws java.io.UnsupportedEncodingException,
                          java.io.IOException
Deprecated. Use CharEscapers.uriEscaper(). See FastURLEncoder for more details.

This should be a direct replacement for java.net.URLEncoder.encode(), but appends its output to an Appendable.

Parameters:
s - String to encode.
encoding - character encoding to use (e.g., "UTF-8")
out - the Appendable destination for the encoded string.
Throws:
java.io.UnsupportedEncodingException - if encoding is not supported.
java.io.IOException - if out does so when appended to.
See Also:
URLEncoder.encode(String, String)

encode

@Deprecated
public static java.lang.String encode(java.lang.String s)
Deprecated. Use CharEscapers.uriEscaper().

Shortcut for encode(s, "UTF-8"). This is very similiar to java.net.URLEncoder.encode() except that it uses UTF-8 instead of the platform's default encoding.

Parameters:
s - String to encode.
See Also:
URLEncoder.encode(String)

encode

@Deprecated
public static void encode(java.lang.String s,
                                     java.lang.Appendable out)
                   throws java.io.IOException
Deprecated. Use CharEscapers.uriEscaper(). See FastURLEncoder for more details.

Shortcut for encode(s, "UTF-8", out). This is very similiar to java.net.URLEncoder.encode() except that it uses UTF-8 instead of the platform's default encoding.

Parameters:
s - String to encode.
out - the Appendable destination for the encoded string.
Throws:
java.io.IOException
See Also:
URLEncoder.encode(String)

encode

@Deprecated
public static java.lang.String encode(java.lang.String s,
                                                 java.util.BitSet safeOctets,
                                                 boolean plusForSpace)
Deprecated. Use CharEscapers.uriEscaper(). or create an instance of PercentEscaper. See FastURLEncoder for more details.

Shortcut for encode(s, "UTF-8"). This is very similiar to java.net.URLEncoder.encode() except that it uses UTF-8 instead of the platform's default encoding.

Parameters:
s - String to encode.
safeOctets - set of octets that should not be escaped.
plusForSpace - whether octet 0x20, i.e., "space", should be encoded as a plus sign rather than "%20". Note that this parameter is effectively ignored if 0x20 is in safeOctets.
See Also:
URLEncoder.encode(String)

createSafeOctetBitSet

@Deprecated
public static java.util.BitSet createSafeOctetBitSet()
Deprecated. Use CharEscapers.uriEscaper(). or create an instance of PercentEscaper. See FastURLEncoder for more details.

Instead of retrieving this set to add your own safe characters, simply provide your additional safe characters to the PercentEscaper.PercentEscaper(String, boolean) constructor. If you don't need to add your own safe characters, just use CharEscapers.uriEscaper().

Returns:
a BitSet suitable for passing to encode(String,String,BitSet,boolean) or encode(String,BitSet,boolean). It defaults to containing the octets that would not be escaped by URLEncoder.encode(String). Callers can edit the result for specialized purposes.