Android HeaderElement - 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 HeaderElement class.

This code example shows how to use the following methods:getName, getParameterByName
            final String mimeType, final String charset) throws UnsupportedCharsetException {
        return create(mimeType, charset != null ? Charset.forName(charset) : null);
    } 
 
    private static ContentType create(final HeaderElement helem) {
        String mimeType = helem.getName();
        String charset = null;
        NameValuePair param = helem.getParameterByName("charset");
        if (param != null) {
            charset = param.getValue();
        } 
        return create(mimeType, charset);
    } 
 
    /** 
     * Parses textual representation of <code>Content-Type</code> value. 
     * 
     * @param s text 
     * @return content type 
     * @throws ParseException if the given text does not represent a valid 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getName, getParameterByName
        Header h = entity.getContentType();
        if (h != null) {
            HeaderElement[] elems = h.getElements();
            if (elems.length > 0) {
                HeaderElement elem = elems[0];
                contentType = elem.getName();
                NameValuePair param = elem.getParameterByName("charset");
                if (param != null) {
                    charset = param.getValue();
                } 
            } 
        } 
 
        if (contentType != null && contentType.equalsIgnoreCase(CONTENT_TYPE)) {
            final String content = EntityUtils.toString(entity, HTTP.ASCII);
            if (content != null && content.length() > 0) {
                result = new ArrayList <NameValuePair>();
                org.apache.http.client.utils.URLEncodedUtils.parse(result, new Scanner(content), charset);
            } 
        } 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getName, getValue
        elem = hei.nextElement();
        Assert.assertEquals("The two header values must be equal",
                "value1", elem.getName());
        elem = hei.nextElement();
        Assert.assertEquals("The two header values must be equal",
                "cookie1", elem.getName());
        Assert.assertEquals("The two header values must be equal",
                "1", elem.getValue());
 
        elem = hei.nextElement();
        Assert.assertEquals("The two header values must be equal",
                "cookie2", elem.getName());
        Assert.assertEquals("The two header values must be equal",
                "2", elem.getValue());
    } 
 
    @Test 
    public void testFringeCases() { 
        final Header[] headers = new Header[]{
                new BasicHeader("Name", null),
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getName, getParameterByName
        HeaderElement[] elems = header.getElements();
        Assert.assertNotNull(elems);
        Assert.assertEquals(1, elems.length);
 
        HeaderElement elem = elems[0];
        Assert.assertEquals("multipart/form-data", elem.getName());
        NameValuePair p1 = elem.getParameterByName("boundary");
        Assert.assertNotNull(p1);
 
        String boundary = p1.getValue();
        Assert.assertNotNull(boundary);
 
        Assert.assertTrue(boundary.length() >= 30);
        Assert.assertTrue(boundary.length() <= 40);
 
        NameValuePair p2 = elem.getParameterByName("charset");
        Assert.assertNull(p2);
    } 
 
    @Test 
    public void testRepeatable() throws Exception { 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getName, getParameters
            final String mimeType, final String charset) throws UnsupportedCharsetException {
        return create(mimeType, !TextUtils.isBlank(charset) ? Charset.forName(charset) : null);
    } 
 
    private static ContentType create(final HeaderElement helem) {
        final String mimeType = helem.getName();
        final NameValuePair[] params = helem.getParameters();
        return new ContentType(mimeType, params != null && params.length > 0 ? params : null);
    } 
 
    /** 
     * Parses textual representation of <code>Content-Type</code> value. 
     * 
     * @param s text 
     * @return content type 
     * @throws ParseException if the given text does not represent a valid 
     * <code>Content-Type</code> value. 
     * @throws UnsupportedCharsetException Thrown when the named charset is not available in 
     * this instance of the Java virtual machine 
     */ 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getName
        if (entity != null) {
            Header ceheader = entity.getContentEncoding();
            if (ceheader != null) {
                HeaderElement[] codecs = ceheader.getElements();
                for (HeaderElement codec : codecs) {
                    String codecname = codec.getName().toLowerCase(Locale.US);
                    if ("gzip".equals(codecname) || "x-gzip".equals(codecname)) {
                        response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                        if (context != null) context.setAttribute(UNCOMPRESSED, true);  
                        return; 
                    } else if ("deflate".equals(codecname)) {
                        response.setEntity(new DeflateDecompressingEntity(response.getEntity()));
                        if (context != null) context.setAttribute(UNCOMPRESSED, true);
                        return; 
                    } else if ("identity".equals(codecname)) {
 
                        /* Don't need to transform the content - no-op */ 
                        return; 
                    } else { 
                        throw new HttpException("Unsupported Content-Coding: " + codec.getName());

4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android HeaderElement Questions & Answers:

See Code Examples for Android HeaderElement Methods: