org.semanticdesktop.aperture.util
Class HttpClientUtil

java.lang.Object
  extended by org.semanticdesktop.aperture.util.HttpClientUtil

public class HttpClientUtil
extends Object

Utility methods for clients dealing with HTTP communication.


Constructor Summary
HttpClientUtil()
           
 
Method Summary
static String formUrlDecode(String string)
          Decodes an url-encoded string.
static String formUrlEncode(String s)
          Encodes a string according to RFC 3986 : Uniform Resource locators (URL).
static String formUrlEncode(String string, String charsToLeave)
          Does the same as HttpClientUtil.formUrlEncode (i.e.
static void formUrlEncode(String s, StringBuilder buffer)
          Encodes a string according to RFC 3986 : Uniform Resource locators (URL).
static InputStream getInputStream(URLConnection conn)
          Gets the InputStream for reading the response from a server.
static void setAcceptGZIPEncoding(URLConnection conn)
          Sets a request property on the supplied connection indicating that a server can respond with gzip-encoded data if it wants to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpClientUtil

public HttpClientUtil()
Method Detail

formUrlEncode

public static void formUrlEncode(String s,
                                 StringBuilder buffer)
Encodes a string according to RFC 3986 : Uniform Resource locators (URL). According to this spec, any characters outside the range 0x20 - 0x7E must be escaped because they are not printable characters. Within the range a number of characters are deemed unsafe or are marked as reserved. In short: According to the spec only the alphanumerics and the special characters from -._~, can be left unencoded.

Parameters:
s - The String to encode.
buffer - The buffer to store the encoded String in.

formUrlEncode

public static String formUrlEncode(String s)
Encodes a string according to RFC 3986 : Uniform Resource locators (URL). According to this spec, any characters outside the range 0x20 - 0x7E must be escaped because they are not printable characters. Within the range a number of characters are deemed unsafe or are marked as reserved. In short: According to the spec only the alphanumerics and the special characters from -._~, can be left unencoded.

Parameters:
s - The String to encode.
Returns:
An encoded version of the specified String.

formUrlEncode

public static String formUrlEncode(String string,
                                   String charsToLeave)
Does the same as HttpClientUtil.formUrlEncode (i.e. RFC 1738) except for some characters that are to be left as they are.

Parameters:
string - the string to be encoded
charsToLeave - a string containing characters that will not be escaped. An example value is "/" useful for slashes, that are to be left alone in imap folder uris according to RFC 2192
Returns:
the encoded folder name

formUrlDecode

public static String formUrlDecode(String string)
Decodes an url-encoded string. This method basically substitutes all '+' signs with a space and all '%'-escape sequences with proper character values - according to the UTF16 encoding.

Parameters:
string - the string to be decoded
Returns:
the decoded version

setAcceptGZIPEncoding

public static void setAcceptGZIPEncoding(URLConnection conn)
Sets a request property on the supplied connection indicating that a server can respond with gzip-encoded data if it wants to.


getInputStream

public static InputStream getInputStream(URLConnection conn)
                                  throws IOException
Gets the InputStream for reading the response from a server. This method handles any encoding-related decoding of the data, e.g. gzip.

Throws:
IOException


Copyright © 2010 Aperture Development Team. All Rights Reserved.