当前位置: 首页>>代码示例>>Java>>正文


Java MediaType.parse方法代码示例

本文整理汇总了Java中com.google.common.net.MediaType.parse方法的典型用法代码示例。如果您正苦于以下问题:Java MediaType.parse方法的具体用法?Java MediaType.parse怎么用?Java MediaType.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.net.MediaType的用法示例。


在下文中一共展示了MediaType.parse方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setContentType

import com.google.common.net.MediaType; //导入方法依赖的package包/类
@Override
public void setContentType(String type) {
    if (isCommitted()) {
        return;
    }
    if (hasWriter()) {
        return;
    }
    if (null == type) {
        contentType = null;
        return;
    }
    MediaType mediaType = MediaType.parse(type);
    Optional<Charset> charset = mediaType.charset();
    if (charset.isPresent()) {
        setCharacterEncoding(charset.get().name());
    }
    contentType = mediaType.type() + '/' + mediaType.subtype();
}
 
开发者ID:geeker-lait,项目名称:tasfe-framework,代码行数:20,代码来源:NettyHttpServletResponse.java

示例2: setContentType

import com.google.common.net.MediaType; //导入方法依赖的package包/类
@Override
    public void setContentType(String type) {
        if (isCommitted()) {
            return;
        }
//        if (hasWriter()) {
//            return;
//        }
        if (null == type) {
            contentType = null;
            return;
        }
        MediaType mediaType = MediaType.parse(type);
        Optional<Charset> charset = mediaType.charset();
        if (charset.isPresent()) {
            setCharacterEncoding(charset.get().name());
        }
        contentType = mediaType.type() + '/' + mediaType.subtype();
    }
 
开发者ID:paullyphang,项目名称:nebo,代码行数:20,代码来源:NettyHttpServletResponse.java

示例3: getMetadata

import com.google.common.net.MediaType; //导入方法依赖的package包/类
/**
 * Helper method that connects to the given URL and returns the response as
 * a String
 * 
 * @param url
 *            the URL to connect to
 * @return the response content as a String
 */
protected String getMetadata(String url) throws MCRPersistenceException {
    try {
        URLConnection connection = getConnection(url);
        connection.setConnectTimeout(getConnectTimeout());
        String contentType = connection.getContentType();
        Charset charset = StandardCharsets.ISO_8859_1; //defined by RFC 2616 (sec 3.7.1)
        if (contentType != null) {
            MediaType mediaType = MediaType.parse(contentType);
            mediaType.charset().or(StandardCharsets.ISO_8859_1);
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
        forwardData(connection, out);

        return new String(out.toByteArray(), charset);
    } catch (IOException exc) {
        String msg = "Could not get metadata from Audio/Video Store URL: " + url;
        throw new MCRPersistenceException(msg, exc);
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:28,代码来源:MCRAudioVideoExtender.java

示例4: isAcceptableMediaType

import com.google.common.net.MediaType; //导入方法依赖的package包/类
private boolean isAcceptableMediaType(KatharsisInvokerContext invokerContext) {
	String acceptHeader = invokerContext.getRequestHeader("Accept");

	if (acceptHeader != null) {
		String[] accepts = acceptHeader.split(",");
		MediaType acceptableType;

		for (String mediaTypeItem : accepts) {
			acceptableType = MediaType.parse(mediaTypeItem.trim());

			if (JsonApiMediaType.isCompatibleMediaType(acceptableType)) {
				return true;
			}
		}
	}

	return false;
}
 
开发者ID:katharsis-project,项目名称:katharsis-framework,代码行数:19,代码来源:KatharsisInvokerV2.java

示例5: isAcceptableMediaType

import com.google.common.net.MediaType; //导入方法依赖的package包/类
private boolean isAcceptableMediaType(KatharsisInvokerContext invokerContext) {
    String acceptHeader = invokerContext.getRequestHeader("Accept");

    if (acceptHeader != null) {
        String[] accepts = acceptHeader.split(",");
        MediaType acceptableType;

        for (String mediaTypeItem : accepts) {
            acceptableType = MediaType.parse(mediaTypeItem.trim());

            if (JsonApiMediaType.isCompatibleMediaType(acceptableType)) {
                return true;
            }
        }
    }

    return false;
}
 
开发者ID:katharsis-project,项目名称:katharsis-framework,代码行数:19,代码来源:KatharsisInvoker.java

示例6: isAcceptableMediaType

import com.google.common.net.MediaType; //导入方法依赖的package包/类
private boolean isAcceptableMediaType(HttpServletRequest servletRequest) {
    String acceptHeader = servletRequest.getHeader(HttpHeaders.ACCEPT);

    if (acceptHeader != null) {
        String[] accepts = acceptHeader.split(",");
        MediaType acceptableType;

        for (String mediaTypeItem : accepts) {
            try {
                acceptableType = MediaType.parse(mediaTypeItem.trim());

                if (JsonApiMediaType.isCompatibleMediaType(acceptableType)) {
                    return true;
                }
            } catch (Exception e) {
                continue;
            }
        }
    }

    return false;
}
 
开发者ID:katharsis-project,项目名称:katharsis-framework,代码行数:23,代码来源:KatharsisFilterV2.java

示例7: getBody

import com.google.common.net.MediaType; //导入方法依赖的package包/类
public static Body getBody(final BodyContainer container, final String contentType) {
    final MediaType parsedContentType = MediaType.parse(contentType);
    return container.getBodies().stream()
            .filter(body -> body.getContentTypes().stream().filter(mediaType -> parsedContentType.is(mediaType)).findFirst().isPresent())
            .findFirst()
            .orElse(null);
}
 
开发者ID:vrapio,项目名称:rest-modeling-framework,代码行数:8,代码来源:ModelHelper.java

示例8: isValidImageMimeType

import com.google.common.net.MediaType; //导入方法依赖的package包/类
private boolean isValidImageMimeType(String imageMimeType) {
	// Here 'MediaType' of Google Guava library is 'MimeType' of Apache James mime4j
	MediaType mediaType = null;
	try {
		mediaType = MediaType.parse(imageMimeType);
	} catch (IllegalArgumentException e) {
		LOGGER.error(e.getMessage());
	}
	return (mediaType != null);
}
 
开发者ID:ram-sharma-6453,项目名称:email-mime-parser,代码行数:11,代码来源:Email.java

示例9: findContentType

import com.google.common.net.MediaType; //导入方法依赖的package包/类
private MediaType findContentType( final ScriptValue value, final ScriptValue body )
{
    final String type = ( value != null ) ? value.getValue( String.class ) : null;
    if ( type != null )
    {
        return MediaType.parse( type );
    }

    return new BodySerializer().findType( body );
}
 
开发者ID:purplejs,项目名称:purplejs,代码行数:11,代码来源:ScriptToResponse.java

示例10: provideContentType

import com.google.common.net.MediaType; //导入方法依赖的package包/类
@Provides
@Header("Content-Type")
static MediaType provideContentType(HttpServletRequest req) {
  try {
    return MediaType.parse(req.getContentType());
  } catch (IllegalArgumentException | NullPointerException e) {
    throw new UnsupportedMediaTypeException("Bad Content-Type header", e);
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:10,代码来源:RequestModule.java

示例11: getContentType

import com.google.common.net.MediaType; //导入方法依赖的package包/类
@Override
public MediaType getContentType()
{
    final String itemContentType = this.part.getContentType();
    return itemContentType != null ? MediaType.parse( itemContentType ) : null;
}
 
开发者ID:purplejs,项目名称:purplejs,代码行数:7,代码来源:MultipartItemImpl.java


注:本文中的com.google.common.net.MediaType.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。