本文整理汇总了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();
}
示例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();
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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 );
}
示例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);
}
}
示例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;
}