Android Header - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Header class.

This code example shows how to use the following methods:getValue
        assertTrue("Wrong response code: " + statusCode, statusCode == expectedCode);
        if (expectedPage != null) {
            assertTrue("X-CustomErrorPage(" + page + ") is " + expectedPage, page.getValue().equals(expectedPage));
        } 
        if (expectedError != null) {
            assertTrue("X-ExceptionType(" + error + ") is " + expectedError, error.getValue().equals(expectedError));
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getName, getValue
 
 
    // non-javadoc, see interface LineFormatter 
    public CharArrayBuffer formatHeader(final CharArrayBuffer buffer,
                                        final Header header) {
        Args.notNull(header, "Header");
        final CharArrayBuffer result;
 
        if (header instanceof FormattedHeader) {
            // If the header is backed by a buffer, re-use the buffer 
            result = ((FormattedHeader)header).getBuffer();
        } else { 
            result = initBuffer(buffer);
            doFormatHeader(result, header);
        } 
        return result;
 
    } // formatHeader 
 
 

6
CodeRank
This code example shows how to use the following methods:getValue
 
    private String extractKeyFromResponseIfItWasNotAlreadyProvided(String key, org.apache.http.HttpResponse response) {
        if (key == null) {
            Header locationHeader = response.getFirstHeader("Location");
            if (locationHeader != null) {
                String location = locationHeader.getValue();
                if (location != null) {
                    int indexOfLastSlash = location.lastIndexOf("/");
                    key = location.substring(indexOfLastSlash + 1);
                } 
            } 
        } 
        return key;
    } 
 
    HttpResponse executeMethod(String bucket, String key, HttpRequestBase httpMethod, RequestMeta meta) {
        return executeMethod(bucket, key, httpMethod, meta, false);
    } 
 
    private HttpRequestBase createStoreHttpMethod(String key, String url) {
6
CodeRank
This code example shows how to use the following methods:getValue
	static String getHeader(HttpResponse response, String key) {
		Header header = response.getFirstHeader(key);
		if(header == null)
			return null; 
		else 
			return header.getValue();
	} 
	 
	/// read all http response body as a string 
	static String getBodyAsString(HttpResponse response) {
		try { 
	        ByteArrayOutputStream baos = new ByteArrayOutputStream();
	        byte[] buf = new byte[2048];
	        InputStream is = response.getEntity().getContent();
	        for(int i = 0; i != -1; i = is.read(buf))
	        	baos.write(buf, 0, i);
	        return Utilities.getUTF8String(baos.toByteArray());
        } catch (Exception e) {
        	return null; 
        } 
5
CodeRank
This code example shows how to use the following methods:getValue
		if (httpEntity == null)
			throw new SearchLibException("No content"); 
		Header header = httpEntity.getContentType();
		if (header == null)
			throw new SearchLibException("No content type"); 
		if (!header.getValue().startsWith("text/xml"))
			throw new SearchLibException("No XML content"); 
		return new XPathParser(httpEntity.getContent());
	} 
 
	public void close() { 
		try { 
			if (httpEntity != null) {
				EntityUtils.consume(httpEntity);
				httpEntity = null;
			} 
		} catch (IOException e) {
			Logging.warn(e.getMessage(), e);
		} 
		httpEntity = null;
5
CodeRank
This code example shows how to use the following methods:getValue
		if (responseStream == null)
			return responseStream;
		Header header = entity.getContentEncoding();
		if (header == null)
			return responseStream;
		String contentEncoding = header.getValue();
		if (contentEncoding == null)
			return responseStream;
		if (contentEncoding.contains("gzip"))
			responseStream = new GZIPInputStream(responseStream);
		return responseStream;
	} 
 
	/** 
	 * Release resources associated with this client. You must call this, or 
	 * significant resources (sockets and memory) may be leaked. 
	 */ 
	public void close() { 
		if (mLeakedException != null) {
			getConnectionManager().shutdown();
5
CodeRank
This code example shows how to use the following methods:getValue
    } 
 
    @Override 
    public String getCharacterEncoding() {
        Header header = entity.getContentEncoding();
        return header == null ? null : header.getValue();
    } 
 
    @Override 
    public String getContentType() {
        Header header = entity.getContentType();
        return header == null ? null : header.getValue();
    } 
 
    @Override 
    public int getContentLength() { 
        return (int) entity.getContentLength();
    } 
 
    @Override 
4
CodeRank
This code example shows how to use the following methods:getValue
    HttpResponse response = client.execute(head);
    int status = response.getStatusLine().getStatusCode();
    if (status == 301 || status == 302) {
      Header redirect = response.getFirstHeader("Location");
      if (redirect != null) {
        String location = redirect.getValue();
        if (location != null) {
          return location;
        } 
      } 
    } 
    return uri;
  } 
 
  private static boolean isRedirector(String uri) {
    for (String redirectorHost : REDIRECTOR_HOSTS) {
      if (uri.startsWith(redirectorHost)) {
        return true; 
      } 
    } 
5
CodeRank
This code example shows how to use the following methods:getValue
 
        HttpRequestInterceptor interceptor = new RequestAcceptEncoding();
        interceptor.process(request, context);
        Header header = request.getFirstHeader("Accept-Encoding");
        Assert.assertNotNull(header);
        Assert.assertEquals("gzip,deflate", header.getValue());
    } 
 
    @Test 
    public void testAcceptEncodingAlreadyPResent() throws Exception { 
        HttpRequest request = new BasicHttpRequest("GET", "/");
        request.addHeader("Accept-Encoding", "stuff");
        HttpContext context = new BasicHttpContext();
 
        HttpRequestInterceptor interceptor = new RequestAcceptEncoding();
        interceptor.process(request, context);
        Header header = request.getFirstHeader("Accept-Encoding");
        Assert.assertNotNull(header);
        Assert.assertEquals("stuff", header.getValue());
    } 
4
CodeRank
This code example shows how to use the following methods:getValue
 
    @Override 
    public void process(HttpResponse response, HttpContext context)
            throws HttpException, IOException { 
        Header header = response.getFirstHeader(HTTP.CONN_DIRECTIVE);
        if (header == null || !HTTP.CONN_KEEP_ALIVE.equals(header.getValue())) {
            super.process(response, context);
        } 
    } 
     
} 
4
CodeRank

Related Android Header Questions & Answers:

See Code Examples for Android Header Methods: