// if is present a conversion for the content-type, then add
// a new option
for (int coapContentType : coapContentTypes) {
if (coapContentType != MediaTypeRegistry.UNDEFINED) {
// create the option
Option option = new Option(optionNumber, coapContentType);
optionList.add(option);
}
}
}
} else if (optionNumber == OptionRegistry.MAX_AGE) {
int maxAge = 0;
if (!headerValue.contains("no-cache")) {
headerValue = headerValue.split(",")[0];
if (headerValue != null) {
int index = headerValue.indexOf('=');
try {
maxAge = Integer.parseInt(headerValue.substring(index + 1).trim());
} catch (NumberFormatException e) {
LOGGER.warning("Cannot convert cache control in max-age option");
continue;
}
}
}
// create the option
Option option = new Option(optionNumber, maxAge);
// option.setValue(headerValue.getBytes(Charset.forName("ISO-8859-1")));
optionList.add(option);
} else {
// create the option
Option option = new Option(optionNumber);
switch (OptionNumberRegistry.getFormatByNr(optionNumber)) {
case INTEGER:
option.setIntegerValue(Integer.parseInt(headerValue));
break;
case OPAQUE:
option.setValue(headerValue.getBytes(ISO_8859_1));
break;
case STRING:
default:
option.setStringValue(headerValue);
break;
}
// option.setValue(headerValue.getBytes(Charset.forName("ISO-8859-1")));
optionList.add(option);
}