Package org.wiztools.restclient.bean

Examples of org.wiztools.restclient.bean.ContentTypeBean


     */
    @Test
    public void testGetContentType_String() {
        System.out.println("getContentType");
        String header = "application/vnd.mnet.staticwebspaces+xml;version=1;charset=UTF-8";
        ContentType expResult = new ContentTypeBean("application/vnd.mnet.staticwebspaces+xml", Charsets.UTF_8);
        ContentType result = HttpUtil.getContentType(header);
        assertEquals(expResult, result);
    }   
View Full Code Here


    public static final Charset DEFAULT_CHARSET = Charsets.UTF_8;
   
    public static ContentType getContentType(String header) {
        final String[] arr = header.split("\\s*;\\s*");
        if(arr.length == 1) {
            return new ContentTypeBean(header, null);
        }
        else {
            final String contentType = arr[0];
            for(int i=1; i<arr.length; i++) {
                final String headerPart = arr[i];
                if(headerPart.contains("charset=")) {
                    Pattern p = Pattern.compile("charset=(.+)");
                    Matcher m = p.matcher(headerPart);
                    if(m.matches()) {
                        Charset charset = Charset.forName(m.group(1));
                        return new ContentTypeBean(contentType, charset);
                    }
                }
            }
            return new ContentTypeBean(contentType, null);
        }
    }
View Full Code Here

    }
   
    @Override
    public ContentType getContentType() {
        if(StringUtil.isNotEmpty(jd.getContentType())) {
            return new ContentTypeBean(jd.getContentType(), jd.getCharset());
        }
        else {
            return null;
        }
    }
View Full Code Here

TOP

Related Classes of org.wiztools.restclient.bean.ContentTypeBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.