當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。