Java 类org.apache.http.util.EntityUtilsHC4 实例源码

项目:remote-files-sync    文件:URLEncodedUtilsHC4.java   
/**
 * Returns a list of {@link NameValuePair NameValuePairs} as parsed from an {@link HttpEntity}. The encoding is
 * taken from the entity's Content-Encoding header.
 * <p>
 * This is typically used while parsing an HTTP POST.
 *
 * @param entity
 *            The entity to parse
 * @return a list of {@link NameValuePair} as built from the URI's query portion.
 * @throws IOException
 *             If there was an exception getting the entity's data.
 */
public static List <NameValuePair> parse(
        final HttpEntity entity) throws IOException {
    final ContentType contentType = ContentType.get(entity);
    if (contentType != null && contentType.getMimeType().equalsIgnoreCase(CONTENT_TYPE)) {
        final String content = EntityUtilsHC4.toString(entity, Consts.ASCII);
        if (content != null && content.length() > 0) {
            Charset charset = contentType.getCharset();
            if (charset == null) {
                charset = Charset.forName(HTTP.DEFAULT_CONTENT_CHARSET);
            }
            return parse(content, charset, QP_SEPS);
        }
    }
    return Collections.emptyList();
}
项目:Visit    文件:URLEncodedUtilsHC4.java   
/**
 * Returns a list of {@link NameValuePair NameValuePairs} as parsed from an {@link HttpEntity}. The encoding is
 * taken from the entity's Content-Encoding header.
 * <p>
 * This is typically used while parsing an HTTP POST.
 *
 * @param entity
 *            The entity to parse
 * @return a list of {@link NameValuePair} as built from the URI's query portion.
 * @throws IOException
 *             If there was an exception getting the entity's data.
 */
public static List <NameValuePair> parse(
        final HttpEntity entity) throws IOException {
    final ContentType contentType = ContentType.get(entity);
    if (contentType != null && contentType.getMimeType().equalsIgnoreCase(CONTENT_TYPE)) {
        final String content = EntityUtilsHC4.toString(entity, Consts.ASCII);
        if (content != null && content.length() > 0) {
            Charset charset = contentType.getCharset();
            if (charset == null) {
                charset = Charset.forName(HTTP.DEFAULT_CONTENT_CHARSET);
            }
            return parse(content, charset, QP_SEPS);
        }
    }
    return Collections.emptyList();
}
项目:ZTLib    文件:URLEncodedUtilsHC4.java   
/**
 * Returns a list of {@link NameValuePair NameValuePairs} as parsed from an {@link HttpEntity}. The encoding is
 * taken from the entity's Content-Encoding header.
 * <p>
 * This is typically used while parsing an HTTP POST.
 *
 * @param entity
 *            The entity to parse
 * @return a list of {@link NameValuePair} as built from the URI's query portion.
 * @throws IOException
 *             If there was an exception getting the entity's data.
 */
public static List <NameValuePair> parse(
        final HttpEntity entity) throws IOException {
    final ContentType contentType = ContentType.get(entity);
    if (contentType != null && contentType.getMimeType().equalsIgnoreCase(CONTENT_TYPE)) {
        final String content = EntityUtilsHC4.toString(entity, Consts.ASCII);
        if (content != null && content.length() > 0) {
            Charset charset = contentType.getCharset();
            if (charset == null) {
                charset = Charset.forName(HTTP.DEFAULT_CONTENT_CHARSET);
            }
            return parse(content, charset, QP_SEPS);
        }
    }
    return Collections.emptyList();
}
项目:remote-files-sync    文件:BufferedHttpEntityHC4.java   
/**
 * Creates a new buffered entity wrapper.
 *
 * @param entity   the entity to wrap, not null
 * @throws IllegalArgumentException if wrapped is null
 */
public BufferedHttpEntityHC4(final HttpEntity entity) throws IOException {
    super(entity);
    if (!entity.isRepeatable() || entity.getContentLength() < 0) {
        this.buffer = EntityUtilsHC4.toByteArray(entity);
    } else {
        this.buffer = null;
    }
}
项目:remote-files-sync    文件:BasicResponseHandlerHC4.java   
/**
 * Returns the response body as a String if the response was successful (a
 * 2xx status code). If no response body exists, this returns null. If the
 * response was unsuccessful (>= 300 status code), throws an
 * {@link HttpResponseException}.
 */
public String handleResponse(final HttpResponse response)
        throws HttpResponseException, IOException {
    final StatusLine statusLine = response.getStatusLine();
    final HttpEntity entity = response.getEntity();
    if (statusLine.getStatusCode() >= 300) {
        EntityUtilsHC4.consume(entity);
        throw new HttpResponseException(statusLine.getStatusCode(),
                statusLine.getReasonPhrase());
    }
    return entity == null ? null : EntityUtilsHC4.toString(entity);
}
项目:Visit    文件:BufferedHttpEntityHC4.java   
/**
 * Creates a new buffered entity wrapper.
 *
 * @param entity   the entity to wrap, not null
 * @throws IllegalArgumentException if wrapped is null
 */
public BufferedHttpEntityHC4(final HttpEntity entity) throws IOException {
    super(entity);
    if (!entity.isRepeatable() || entity.getContentLength() < 0) {
        this.buffer = EntityUtilsHC4.toByteArray(entity);
    } else {
        this.buffer = null;
    }
}
项目:Visit    文件:BasicResponseHandlerHC4.java   
/**
 * Returns the response body as a String if the response was successful (a
 * 2xx status code). If no response body exists, this returns null. If the
 * response was unsuccessful (>= 300 status code), throws an
 * {@link HttpResponseException}.
 */
public String handleResponse(final HttpResponse response)
        throws HttpResponseException, IOException {
    final StatusLine statusLine = response.getStatusLine();
    final HttpEntity entity = response.getEntity();
    if (statusLine.getStatusCode() >= 300) {
        EntityUtilsHC4.consume(entity);
        throw new HttpResponseException(statusLine.getStatusCode(),
                statusLine.getReasonPhrase());
    }
    return entity == null ? null : EntityUtilsHC4.toString(entity);
}
项目:ZTLib    文件:BufferedHttpEntityHC4.java   
/**
 * Creates a new buffered entity wrapper.
 *
 * @param entity   the entity to wrap, not null
 * @throws IllegalArgumentException if wrapped is null
 */
public BufferedHttpEntityHC4(final HttpEntity entity) throws IOException {
    super(entity);
    if (!entity.isRepeatable() || entity.getContentLength() < 0) {
        this.buffer = EntityUtilsHC4.toByteArray(entity);
    } else {
        this.buffer = null;
    }
}
项目:ZTLib    文件:BasicResponseHandlerHC4.java   
/**
 * Returns the response body as a String if the response was successful (a
 * 2xx status code). If no response body exists, this returns null. If the
 * response was unsuccessful (>= 300 status code), throws an
 * {@link HttpResponseException}.
 */
public String handleResponse(final HttpResponse response)
        throws HttpResponseException, IOException {
    final StatusLine statusLine = response.getStatusLine();
    final HttpEntity entity = response.getEntity();
    if (statusLine.getStatusCode() >= 300) {
        EntityUtilsHC4.consume(entity);
        throw new HttpResponseException(statusLine.getStatusCode(),
                statusLine.getReasonPhrase());
    }
    return entity == null ? null : EntityUtilsHC4.toString(entity);
}
项目:remote-files-sync    文件:CloseableHttpResponseProxy.java   
public void close() throws IOException {
    final HttpEntity entity = this.original.getEntity();
    EntityUtilsHC4.consume(entity);
}
项目:Visit    文件:CloseableHttpResponseProxy.java   
public void close() throws IOException {
    final HttpEntity entity = this.original.getEntity();
    EntityUtilsHC4.consume(entity);
}
项目:ZTLib    文件:CloseableHttpResponseProxy.java   
public void close() throws IOException {
    final HttpEntity entity = this.original.getEntity();
    EntityUtilsHC4.consume(entity);
}
项目:remote-files-sync    文件:HttpClientUtils.java   
/**
 * Unconditionally close a response.
 * <p>
 * Example Code:
 *
 * <pre>
 * HttpResponse httpResponse = null;
 * try {
 *     httpResponse = httpClient.execute(httpGet);
 * } catch (Exception e) {
 *     // error handling
 * } finally {
 *     HttpClientUtils.closeQuietly(httpResponse);
 * }
 * </pre>
 *
 * @param response
 *            the HttpResponse to release resources, may be null or already
 *            closed.
 *
 * @since 4.2
 */
public static void closeQuietly(final HttpResponse response) {
    if (response != null) {
        final HttpEntity entity = response.getEntity();
        if (entity != null) {
            try {
                EntityUtilsHC4.consume(entity);
            } catch (final IOException ex) {
            }
        }
    }
}
项目:remote-files-sync    文件:HttpClientUtils.java   
/**
 * Unconditionally close a response.
 * <p>
 * Example Code:
 *
 * <pre>
 * HttpResponse httpResponse = null;
 * try {
 *     httpResponse = httpClient.execute(httpGet);
 * } catch (Exception e) {
 *     // error handling
 * } finally {
 *     HttpClientUtils.closeQuietly(httpResponse);
 * }
 * </pre>
 *
 * @param response
 *            the HttpResponse to release resources, may be null or already
 *            closed.
 *
 * @since 4.3
 */
public static void closeQuietly(final CloseableHttpResponse response) {
    if (response != null) {
        try {
            try {
                EntityUtilsHC4.consume(response.getEntity());
            } finally {
                response.close();
            }
        } catch (final IOException ignore) {
        }
    }
}
项目:Visit    文件:HttpClientUtils.java   
/**
 * Unconditionally close a response.
 * <p>
 * Example Code:
 *
 * <pre>
 * HttpResponse httpResponse = null;
 * try {
 *     httpResponse = httpClient.execute(httpGet);
 * } catch (Exception e) {
 *     // error handling
 * } finally {
 *     HttpClientUtils.closeQuietly(httpResponse);
 * }
 * </pre>
 *
 * @param response
 *            the HttpResponse to release resources, may be null or already
 *            closed.
 *
 * @since 4.2
 */
public static void closeQuietly(final HttpResponse response) {
    if (response != null) {
        final HttpEntity entity = response.getEntity();
        if (entity != null) {
            try {
                EntityUtilsHC4.consume(entity);
            } catch (final IOException ex) {
            }
        }
    }
}
项目:Visit    文件:HttpClientUtils.java   
/**
 * Unconditionally close a response.
 * <p>
 * Example Code:
 *
 * <pre>
 * HttpResponse httpResponse = null;
 * try {
 *     httpResponse = httpClient.execute(httpGet);
 * } catch (Exception e) {
 *     // error handling
 * } finally {
 *     HttpClientUtils.closeQuietly(httpResponse);
 * }
 * </pre>
 *
 * @param response
 *            the HttpResponse to release resources, may be null or already
 *            closed.
 *
 * @since 4.3
 */
public static void closeQuietly(final CloseableHttpResponse response) {
    if (response != null) {
        try {
            try {
                EntityUtilsHC4.consume(response.getEntity());
            } finally {
                response.close();
            }
        } catch (final IOException ignore) {
        }
    }
}
项目:ZTLib    文件:HttpClientUtils.java   
/**
 * Unconditionally close a response.
 * <p>
 * Example Code:
 *
 * <pre>
 * HttpResponse httpResponse = null;
 * try {
 *     httpResponse = httpClient.execute(httpGet);
 * } catch (Exception e) {
 *     // error handling
 * } finally {
 *     HttpClientUtils.closeQuietly(httpResponse);
 * }
 * </pre>
 *
 * @param response
 *            the HttpResponse to release resources, may be null or already
 *            closed.
 *
 * @since 4.2
 */
public static void closeQuietly(final HttpResponse response) {
    if (response != null) {
        final HttpEntity entity = response.getEntity();
        if (entity != null) {
            try {
                EntityUtilsHC4.consume(entity);
            } catch (final IOException ex) {
            }
        }
    }
}
项目:ZTLib    文件:HttpClientUtils.java   
/**
 * Unconditionally close a response.
 * <p>
 * Example Code:
 *
 * <pre>
 * HttpResponse httpResponse = null;
 * try {
 *     httpResponse = httpClient.execute(httpGet);
 * } catch (Exception e) {
 *     // error handling
 * } finally {
 *     HttpClientUtils.closeQuietly(httpResponse);
 * }
 * </pre>
 *
 * @param response
 *            the HttpResponse to release resources, may be null or already
 *            closed.
 *
 * @since 4.3
 */
public static void closeQuietly(final CloseableHttpResponse response) {
    if (response != null) {
        try {
            try {
                EntityUtilsHC4.consume(response.getEntity());
            } finally {
                response.close();
            }
        } catch (final IOException ignore) {
        }
    }
}