本文整理汇总了Java中org.springframework.util.MimeTypeUtils.parseMimeType方法的典型用法代码示例。如果您正苦于以下问题:Java MimeTypeUtils.parseMimeType方法的具体用法?Java MimeTypeUtils.parseMimeType怎么用?Java MimeTypeUtils.parseMimeType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.util.MimeTypeUtils
的用法示例。
在下文中一共展示了MimeTypeUtils.parseMimeType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: read
import org.springframework.util.MimeTypeUtils; //导入方法依赖的package包/类
public void read(String mimeType, InputStream is) throws IOException {
Assert.hasText(mimeType, "MimeType string is null or empty.");
Assert.notNull(is, "InputStream is null or empty.");
MimeType mimeTypeObj = MimeTypeUtils.parseMimeType(mimeType);
if(MimeTypeUtils.APPLICATION_JSON.equals(mimeTypeObj)) {
Assert.hasText(mimeType, "MimeType '" + mimeType + "' is not supported.");
}
AppConfigObject aco = objectMapper.readValue(is, AppConfigObject.class);
final String version = aco.getVersion();
if(!VERSION.equals(version)) {
throw new RuntimeException("Unsupported version of config: " + version);
}
ConfigReadContext ctx = new ConfigReadContext();
Map<String, Object> map = aco.getData();
Assert.notNull(map, "config has empty map");
for(Map.Entry<String, Object> oe : map.entrySet()) {
String name = oe.getKey();
ReConfigurableAdapter ca = adapters.get(name);
Assert.notNull(ca, "Can not find adapter with name: " + name);
Object value = oe.getValue();
Assert.notNull(value, "Config object is null for name: " + name);
ca.setConfig(ctx, value);
}
}
示例2: updateSimpMessageHeadersFromStompHeaders
import org.springframework.util.MimeTypeUtils; //导入方法依赖的package包/类
void updateSimpMessageHeadersFromStompHeaders() {
if (getNativeHeaders() == null) {
return;
}
String value = getFirstNativeHeader(STOMP_DESTINATION_HEADER);
if (value != null) {
super.setDestination(value);
}
value = getFirstNativeHeader(STOMP_CONTENT_TYPE_HEADER);
if (value != null) {
super.setContentType(MimeTypeUtils.parseMimeType(value));
}
StompCommand command = getCommand();
if (StompCommand.MESSAGE.equals(command)) {
value = getFirstNativeHeader(STOMP_SUBSCRIPTION_HEADER);
if (value != null) {
super.setSubscriptionId(value);
}
}
else if (StompCommand.SUBSCRIBE.equals(command) || StompCommand.UNSUBSCRIBE.equals(command)) {
value = getFirstNativeHeader(STOMP_ID_HEADER);
if (value != null) {
super.setSubscriptionId(value);
}
}
else if (StompCommand.CONNECT.equals(command)) {
protectPasscode();
}
}
示例3: write
import org.springframework.util.MimeTypeUtils; //导入方法依赖的package包/类
/**
*/
public void write(String mimeType, OutputStream os) throws IOException {
Assert.hasText(mimeType, "MimeType string is null or empty.");
Assert.notNull(os, "OutputStream is null or empty.");
MimeType mimeTypeObj = MimeTypeUtils.parseMimeType(mimeType);
if(MimeTypeUtils.APPLICATION_JSON.equals(mimeTypeObj)) {
Assert.hasText(mimeType, "MimeType '" + mimeType + "' is not supported.");
}
AppConfigObject aco = new AppConfigObject();
aco.setDate(LocalDateTime.now());
aco.setVersion(VERSION);
Map<String, Object> map = new HashMap<>();
aco.setData(map);
ConfigWriteContext ctx = ConfigWriteContext.builder()
.mimeType(mimeTypeObj)
.build();
for(ConcurrentMap.Entry<String, ReConfigurableAdapter> cae : adapters.entrySet()) {
ReConfigurableAdapter ca = cae.getValue();
Object o = ca.getConfig(ctx);
if(o == null) {
continue;
}
String name = cae.getKey();
map.put(name, o);
}
objectMapper.writeValue(os, aco);
}
示例4: isValidContentType
import org.springframework.util.MimeTypeUtils; //导入方法依赖的package包/类
/**
* Indicates whether the content type represented by the given string
* is a valid, known content type.
*
* @param contentType the content type string.
* @return true if the content is valid, false if not.
*/
public static boolean isValidContentType( String contentType )
{
try
{
MimeTypeUtils.parseMimeType( contentType );
}
catch ( InvalidMimeTypeException ignored )
{
return false;
}
return true;
}
示例5: isValidContentType
import org.springframework.util.MimeTypeUtils; //导入方法依赖的package包/类
private boolean isValidContentType( String contentType )
{
try
{
MimeTypeUtils.parseMimeType( contentType );
}
catch ( InvalidMimeTypeException e )
{
return false;
}
return true;
}
示例6: getContentType
import org.springframework.util.MimeTypeUtils; //导入方法依赖的package包/类
/**
* Return the content-type header value.
*/
public MimeType getContentType() {
String value = getFirst(CONTENT_TYPE);
return (StringUtils.hasLength(value) ? MimeTypeUtils.parseMimeType(value) : null);
}
示例7: deserialize
import org.springframework.util.MimeTypeUtils; //导入方法依赖的package包/类
@Override
public MimeType deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
String mimeString = p.readValueAs(String.class);
return MimeTypeUtils.parseMimeType(mimeString);
}
示例8: parse
import org.springframework.util.MimeTypeUtils; //导入方法依赖的package包/类
/***************************************************************************
* *
* Static builder *
* *
**************************************************************************/
public static MimeType parse(String mimeType){
org.springframework.util.MimeType spring = MimeTypeUtils.parseMimeType(mimeType);
return new MimeType(spring.getType(), spring.getSubtype());
}