List of usage examples for org.apache.http.protocol HTTP DEFAULT_CONTENT_CHARSET
String DEFAULT_CONTENT_CHARSET
To view the source code for org.apache.http.protocol HTTP DEFAULT_CONTENT_CHARSET.
Click Source Link
From source file:com.kth.common.utils.etc.URLCoderUtil.java
/** URL? URL Decode. */ public static String decode(final String content) { return decode(content, HTTP.DEFAULT_CONTENT_CHARSET); }
From source file:Main.java
public static String encode(final String content, final String encoding) { try {/*from w ww .j av a 2 s . co m*/ return URLEncoder.encode(content, encoding != null ? encoding : HTTP.DEFAULT_CONTENT_CHARSET); } catch (UnsupportedEncodingException problem) { throw new IllegalArgumentException(problem); } }
From source file:com.kth.common.utils.etc.URLCoderUtil.java
/** URL? URL Decode. */ public static String decode(final String content, final String encoding) { try {/*from ww w . j av a2 s . com*/ return URLDecoder.decode(content, encoding != null ? encoding : HTTP.DEFAULT_CONTENT_CHARSET); } catch (UnsupportedEncodingException problem) { throw new IllegalArgumentException(problem); } }
From source file:org.eclipse.egit.github.core.util.UrlUtils.java
/** * Encode given url//from w ww .j a v a 2s . co m * * @param url * @return encoded url */ public static String encode(String url) { try { return URLEncoder.encode(url, HTTP.DEFAULT_CONTENT_CHARSET); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException(e); } }
From source file:com.kth.common.utils.etc.URLCoderUtil.java
/** URL? URL encode. */ public static String encode(final String content) { return encode(content, HTTP.DEFAULT_CONTENT_CHARSET); }
From source file:Main.java
public static String gzipToString(final HttpEntity entity, final String defaultCharset) throws IOException, ParseException { if (entity == null) { throw new IllegalArgumentException("HTTP entity may not be null"); }/*from ww w . j a v a 2s .c o m*/ InputStream instream = entity.getContent(); if (instream == null) { return ""; } // gzip logic start if (entity.getContentEncoding().getValue().contains("gzip")) { instream = new GZIPInputStream(instream); } // gzip logic end if (entity.getContentLength() > Integer.MAX_VALUE) { throw new IllegalArgumentException("HTTP entity too large to be buffered in memory"); } int i = (int) entity.getContentLength(); if (i < 0) { i = 4096; } String charset = EntityUtils.getContentCharSet(entity); if (charset == null) { charset = defaultCharset; } if (charset == null) { charset = HTTP.DEFAULT_CONTENT_CHARSET; } Reader reader = new InputStreamReader(instream, charset); CharArrayBuffer buffer = new CharArrayBuffer(i); try { char[] tmp = new char[1024]; int l; while ((l = reader.read(tmp)) != -1) { buffer.append(tmp, 0, l); } } finally { reader.close(); } return buffer.toString(); }
From source file:com.kth.common.utils.etc.URLCoderUtil.java
/** URL? URL Encode. */ public static String encode(final String content, final String encoding) { try {// w w w . j a v a 2s. c om return URLEncoder.encode(content, encoding != null ? encoding : HTTP.DEFAULT_CONTENT_CHARSET); } catch (UnsupportedEncodingException problem) { throw new IllegalArgumentException(problem); } }
From source file:com.google.android.feeds.ContentHandlerUtils.java
/** * Returns the character set of the content provided by the given * {@link URLConnection}.//from w w w.j ava 2 s . co m * * @throws IOException if the character set cannot be determined. */ public static String getCharSet(URLConnection connection) throws IOException { String contentType = connection.getContentType(); if (contentType != null) { HeaderValueParser parser = new BasicHeaderValueParser(); HeaderElement[] values = BasicHeaderValueParser.parseElements(contentType, parser); if (values.length > 0) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { return param.getValue(); } } } if (connection instanceof HttpURLConnection) { return HTTP.DEFAULT_CONTENT_CHARSET; } else { throw new IOException("Unabled to determine character encoding"); } }
From source file:com.guess.license.plate.Network.ThreadSafeHttpClientFactory.java
private HttpClient createHttpClient() { HttpParams httpParams = new BasicHttpParams(); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(httpParams, HTTP.DEFAULT_CONTENT_CHARSET); SchemeRegistry schemeRegistry = new SchemeRegistry(); Scheme httpScheme = new Scheme(HTTP_SCHEMA, PlainSocketFactory.getSocketFactory(), HTTP_PORT); schemeRegistry.register(httpScheme); Scheme httpsScheme = new Scheme(HTTPS_SCHEMA, PlainSocketFactory.getSocketFactory(), HTTPS_PORT); schemeRegistry.register(httpsScheme); ClientConnectionManager tsConnManager = new ThreadSafeClientConnManager(httpParams, schemeRegistry); HttpClient tmpClient = new DefaultHttpClient(tsConnManager, httpParams); HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT); HttpConnectionParams.setConnectionTimeout(tmpClient.getParams(), TIMEOUT); addUserAgent(tmpClient);/* w ww . ja va 2 s.c o m*/ return tmpClient; }