本文整理了Java中org.eclipse.californium.core.coap.OptionSet.hasContentFormat()
方法的一些代码示例,展示了OptionSet.hasContentFormat()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OptionSet.hasContentFormat()
方法的具体详情如下:
包路径:org.eclipse.californium.core.coap.OptionSet
类名称:OptionSet
方法名:hasContentFormat
[英]Checks if the Content-Format option is present.
[中]检查内容格式选项是否存在。
代码示例来源:origin: eclipse/californium
/**
* Returns the Content-Format Identifier of the Content-Format option (see
* <a href="http://www.iana.org/assignments/core-parameters/core-parameters.xhtml#content-formats">IANA Registry</a>).
* @return the ID as int or -1 if undefined
*/
public int getContentFormat() {
return hasContentFormat() ? content_format : MediaTypeRegistry.UNDEFINED;
}
代码示例来源:origin: org.eclipse.californium/californium-core
/**
* Returns the Content-Format Identifier of the Content-Format option (see
* <a href="http://www.iana.org/assignments/core-parameters/core-parameters.xhtml#content-formats">IANA Registry</a>).
* @return the ID as int or -1 if undefined
*/
public int getContentFormat() {
return hasContentFormat() ? content_format : MediaTypeRegistry.UNDEFINED;
}
代码示例来源:origin: eclipse/californium
@Override
public void handlePOST(CoapExchange exchange) {
if (exchange.getRequestOptions().hasContentFormat()) {
exchange.respond(CHANGED, exchange.getRequestText().toUpperCase(), TEXT_PLAIN);
} else {
exchange.respond(BAD_REQUEST, "Content-Format not set");
}
}
}
代码示例来源:origin: eclipse/californium
/**
* Checks for Content-Type option.
*
* @param response
* the response
* @return true, if successful
*/
protected boolean hasContentType(Response response) {
boolean success = response.getOptions().hasContentFormat()
|| response.getPayloadSize()==0
|| !CoAP.ResponseCode.isSuccess(response.getCode());
if (!success) {
System.out.println("FAIL: Response without Content-Type");
} else {
System.out.printf("PASS: Content-Type (%s)\n",
MediaTypeRegistry.toString(response.getOptions()
.getContentFormat()));
}
return success;
}
代码示例来源:origin: org.apache.camel/camel-coap
if (options.hasContentFormat()) {
String mt = MediaTypeRegistry.toString(options.getContentFormat());
camelExchange.getIn().setHeader(org.apache.camel.Exchange.CONTENT_TYPE, mt);
代码示例来源:origin: eclipse/leshan
private LwM2mNode decodeCoapResponse(LwM2mPath path, Response coapResponse, LwM2mRequest<?> request,
String endpoint) {
// Get content format
ContentFormat contentFormat = null;
if (coapResponse.getOptions().hasContentFormat()) {
contentFormat = ContentFormat.fromCode(coapResponse.getOptions().getContentFormat());
}
// Decode payload
try {
return decoder.decode(coapResponse.getPayload(), contentFormat, path, model);
} catch (CodecException e) {
if (LOG.isDebugEnabled()) {
byte[] payload = coapResponse.getPayload() == null ? new byte[0] : coapResponse.getPayload();
LOG.debug(
String.format("Unable to decode response payload of request [%s] from client [%s] [payload:%s]",
request, endpoint, Hex.encodeHexString(payload)));
}
throw new InvalidResponseException(e, "Unable to decode response payload of request [%s] from client [%s]",
request, endpoint);
}
}
代码示例来源:origin: eclipse/californium
@Override
public void handlePUT(CoapExchange exchange) {
if (exchange.getRequestOptions().hasContentFormat()) {
storeData(exchange.getRequestPayload(), exchange.getRequestOptions().getContentFormat());
exchange.respond(CHANGED);
} else {
exchange.respond(BAD_REQUEST, "Content-Format not set");
}
}
代码示例来源:origin: eclipse/californium
@Override
public void handlePUT(CoapExchange exchange) {
if (!exchange.getRequestOptions().hasContentFormat()) {
exchange.respond(BAD_REQUEST, "Content-Format not set");
return;
}
// store payload
storeData(exchange.getRequestPayload(), exchange.getRequestOptions().getContentFormat());
// complete the request
exchange.respond(CHANGED);
}
代码示例来源:origin: eclipse/californium
@Override
public void handlePUT(CoapExchange exchange) {
if (!exchange.getRequestOptions().hasContentFormat()) {
exchange.respond(BAD_REQUEST, "Content-Format not set");
return;
}
// store payload
storeData(exchange.getRequestPayload(), exchange.getRequestOptions().getContentFormat());
// complete the request
exchange.respond(CHANGED);
}
代码示例来源:origin: eclipse/californium
if (! coapMessage.getOptions().hasContentFormat()) {
contentType = ContentType.APPLICATION_OCTET_STREAM;
} else {
代码示例来源:origin: org.eclipse.californium/californium-proxy
if (! coapMessage.getOptions().hasContentFormat()) {
contentType = ContentType.APPLICATION_OCTET_STREAM;
} else {
代码示例来源:origin: eclipse/californium
@Override
public void handlePOST(CoapExchange exchange) {
if (exchange.getRequestOptions().hasContentFormat()) {
exchange.setLocationPath( storeData(exchange.getRequestPayload(), exchange.getRequestOptions().getContentFormat()) );
exchange.respond(CREATED);
} else {
exchange.respond(BAD_REQUEST, "Content-Format not set");
}
}
代码示例来源:origin: eclipse/californium
if (uri_path_list != null) for (String str:uri_path_list)
options.add(new Option(OptionNumberRegistry.URI_PATH, str));
if (hasContentFormat())
options.add(new Option(OptionNumberRegistry.CONTENT_FORMAT, getContentFormat()));
if (hasMaxAge())
代码示例来源:origin: org.eclipse.californium/californium-core
if (uri_path_list != null) for (String str:uri_path_list)
options.add(new Option(OptionNumberRegistry.URI_PATH, str));
if (hasContentFormat())
options.add(new Option(OptionNumberRegistry.CONTENT_FORMAT, getContentFormat()));
if (hasMaxAge())
代码示例来源:origin: eclipse/leshan
if (coapResponse.getOptions().hasContentFormat()) {
contentFormat = ContentFormat.fromCode(coapResponse.getOptions().getContentFormat());
代码示例来源:origin: eclipse/californium
@Override
public void handlePUT(CoapExchange exchange) {
if (data!=null && exchange.getRequestOptions().hasIfNoneMatch()) {
exchange.respond(PRECONDITION_FAILED);
// automatically reset
data = null;
} else {
if (exchange.getRequestOptions().hasContentFormat()) {
storeData(exchange.getRequestPayload(), exchange.getRequestOptions().getContentFormat());
exchange.respond(CREATED);
} else {
exchange.respond(BAD_REQUEST, "Content-Format not set");
}
}
}
代码示例来源:origin: eclipse/californium
@Override
public void handlePUT(CoapExchange exchange) {
if (exchange.getRequestOptions().isIfMatch(etag)) {
if (exchange.getRequestOptions().hasContentFormat()) {
storeData(exchange.getRequestPayload(), exchange.getRequestOptions().getContentFormat());
exchange.setETag(etag.clone());
exchange.respond(CHANGED);
} else {
exchange.respond(BAD_REQUEST, "Content-Format not set");
}
} else if (exchange.getRequestOptions().hasIfNoneMatch() && data==null) {
storeData(exchange.getRequestPayload(), exchange.getRequestOptions().getContentFormat());
exchange.respond(CREATED);
} else {
exchange.respond(PRECONDITION_FAILED);
// automatically change now
storeData(null, UNDEFINED);
}
}
代码示例来源:origin: eclipse/leshan
if (!exchange.getRequestOptions().hasContentFormat()) {
exchange.respond(ResponseCode.BAD_REQUEST, "Content Format is mandatory");
return;
代码示例来源:origin: eclipse/leshan
LwM2mPath path = new LwM2mPath(URI);
if (!coapExchange.getRequestOptions().hasContentFormat()) {
coapExchange.respond(ResponseCode.BAD_REQUEST, "Content Format is mandatory");
return;
内容来源于网络,如有侵权,请联系作者删除!