本文整理汇总了Java中javax.ws.rs.core.MediaType.getType方法的典型用法代码示例。如果您正苦于以下问题:Java MediaType.getType方法的具体用法?Java MediaType.getType怎么用?Java MediaType.getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.MediaType
的用法示例。
在下文中一共展示了MediaType.getType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setCharacterEncoding
import javax.ws.rs.core.MediaType; //导入方法依赖的package包/类
@Override
public void setCharacterEncoding(final String charset) {
final String type;
final String subType;
final Map<String, String> parameters;
final MediaType prevMediaType = getMediaType();
if (prevMediaType != null) {
type = prevMediaType.getType();
subType = prevMediaType.getSubtype();
parameters = new HashMap<>(prevMediaType.getParameters());
} else {
type = "text";
subType = "html";
parameters = new HashMap<>();
}
parameters.put(MediaType.CHARSET_PARAMETER, charset);
setContentType(new MediaType(type, subType, parameters).toString());
}
示例2: getKey
import javax.ws.rs.core.MediaType; //导入方法依赖的package包/类
public static String getKey(MediaType mediaType) {
if (mediaType == null) {
return MediaType.WILDCARD;
}
return mediaType.getType() + "/" + mediaType.getSubtype(); // key does not contain any charset
}
示例3: handleGet
import javax.ws.rs.core.MediaType; //导入方法依赖的package包/类
/**
* Returns RDF data from a graph in the repository.
*
* @see RDFStreamingOutput
* @param req JAX-RS {@link Request} object
* @param def the "default" query parameter
* @param graphString the "graph" query parameter
* @return RDF data as HTTP response
*/
private Response handleGet(
Request req,
String def,
String graphString) {
// select matching MIME-Type for response based on HTTP headers
final Variant variant = req.selectVariant(rdfResultVariants);
final MediaType mt = variant.getMediaType();
final String mtstr = mt.getType() + "/" + mt.getSubtype();
final RDFFormat format = getRDFFormat(mtstr);
StreamingOutput stream;
RepositoryConnection conn = null;
try {
// return data as RDF stream
conn = getConnection();
if (graphString != null) {
Resource ctx = vf.createURI(graphString);
if (conn.size(ctx) == 0) {
return Response.status(Response.Status.NOT_FOUND).build();
}
stream = new RDFStreamingOutput(conn, format, ctx);
} else {
stream = new RDFStreamingOutput(conn, format);
}
} catch (RepositoryException ex) {
// server error
close(conn, ex);
throw new WebApplicationException(ex);
}
return Response.ok(stream).build();
}
示例4: isWriteable
import javax.ws.rs.core.MediaType; //导入方法依赖的package包/类
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
String mediaTypeString = mediaType.getType()+'/'+mediaType.getSubtype();
return Model.class.isAssignableFrom(type) && supportedMediaTypes.contains(mediaTypeString);
}