org.eclipse.californium.core.coap.Response.getPayload()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中org.eclipse.californium.core.coap.Response.getPayload方法的一些代码示例,展示了Response.getPayload的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getPayload方法的具体详情如下:
包路径:org.eclipse.californium.core.coap.Response
类名称:Response
方法名:getPayload

Response.getPayload介绍

暂无

代码示例

代码示例来源:origin: eclipse/californium

/**
 * Gets the payload of this response as byte array.
 *
 * @return the payload
 */
public byte[] getPayload() {
  return response.getPayload();
}

代码示例来源:origin: eclipse/californium

/**
 * Checks for not empty payload.
 * 
 * @param response
 *            the response
 * @return true, if not empty payload
 */
protected boolean hasNonEmptyPalyoad(Response response) {
  boolean success = response.getPayload().length > 0;
  if (!success) {
    System.out.println("FAIL: Response with empty payload");
  } else {
    System.out.printf("PASS: Payload not empty \"%s\"\n",
        response.getPayloadString());
  }
  return success;
}

代码示例来源:origin: eclipse/californium

System.arraycopy(response.getPayload(), from, blockPayload, 0, length);
block.setPayload(blockPayload);

代码示例来源:origin: org.eclipse.californium/californium-core

/**
 * Gets the payload of this response as byte array.
 *
 * @return the payload
 */
public byte[] getPayload() {
  return response.getPayload();
}

代码示例来源:origin: eclipse/leshan

@Override
public void visit(DiscoverRequest request) {
  if (coapResponse.isError()) {
    // handle error response:
    lwM2mresponse = new DiscoverResponse(toLwM2mResponseCode(coapResponse.getCode()), null,
        coapResponse.getPayloadString(), coapResponse);
  } else if (coapResponse.getCode() == org.eclipse.californium.core.coap.CoAP.ResponseCode.CONTENT) {
    // handle success response:
    Link[] links;
    if (MediaTypeRegistry.APPLICATION_LINK_FORMAT != coapResponse.getOptions().getContentFormat()) {
      LOG.debug("Expected LWM2M Client [{}] to return application/link-format [{}] content but got [{}]",
          registration.getEndpoint(), MediaTypeRegistry.APPLICATION_LINK_FORMAT,
          coapResponse.getOptions().getContentFormat());
      links = new Link[] {}; // empty list
    } else {
      links = Link.parse(coapResponse.getPayload());
    }
    lwM2mresponse = new DiscoverResponse(ResponseCode.CONTENT, links, null, coapResponse);
  } else {
    // handle unexpected response:
    handleUnexpectedResponseCode(registration.getEndpoint(), request, coapResponse);
  }
}

代码示例来源:origin: org.eclipse.californium/californium-core

System.arraycopy(response.getPayload(), from, blockPayload, 0, length);
block.setPayload(blockPayload);

代码示例来源:origin: org.eclipse.leshan/leshan-client

@Override
public byte[] getPayload() {
  return response.getPayload();
}

代码示例来源:origin: org.github.leshan/leshan-client

@Override
public byte[] getPayload() {
  return response.getPayload();
}

代码示例来源: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/leshan

public CoapMessage(Response request, boolean incoming) {
  this(incoming, request.getType(), request.getMID(), request.getTokenString(), request.getOptions(), request
      .getPayload());
  this.code = request.getCode().toString();
}

代码示例来源:origin: eclipse/leshan

List<TimestampedLwM2mNode> timestampedNodes = decoder.decodeTimestampedData(coapResponse.getPayload(),
    contentFormat, observation.getPath(), model);
  byte[] payload = coapResponse.getPayload() == null ? new byte[0] : coapResponse.getPayload();
  LOG.debug(String.format("Unable to decode notification payload [%s] of observation [%s] ",
      Hex.encodeHexString(payload), observation), e);

代码示例来源:origin: org.eclipse.leshan/leshan-server-cf

private ValueResponse buildContentResponse(final LwM2mPath path, final Response coapResponse) {
  final ResponseCode code = ResponseCode.CONTENT;
  LwM2mNode content;
  try {
    content = LwM2mNodeDecoder.decode(coapResponse.getPayload(),
        ContentFormat.fromCode(coapResponse.getOptions().getContentFormat()), path);
  } catch (final InvalidValueException e) {
    final String msg = String.format("[%s] ([%s])", e.getMessage(), e.getPath().toString());
    throw new ResourceAccessException(code, path.toString(), msg, e);
  }
  return new ValueResponse(code, content);
}

代码示例来源:origin: org.eclipse.californium/californium-proxy

byte[] payload = incomingResponse.getPayload();
outgoingResponse.setPayload(payload);

代码示例来源:origin: eclipse/californium

byte[] payload = incomingResponse.getPayload();
outgoingResponse.setPayload(payload);

代码示例来源:origin: org.eclipse.leshan/leshan-server-cf

@Override
public void onResponse(Response coapResponse) {
  if (coapResponse.getCode() == CoAP.ResponseCode.CHANGED || coapResponse.getCode() == CoAP.ResponseCode.CONTENT) {
    try {
      LwM2mNode content = LwM2mNodeDecoder.decode(coapResponse.getPayload(),
          ContentFormat.fromCode(coapResponse.getOptions().getContentFormat()), path);
      ValueResponse response = new ValueResponse(ResponseCode.CHANGED, content);
      for (ObservationListener listener : listeners) {
        listener.newValue(this, response.getContent());
      }
    } catch (InvalidValueException e) {
      String msg = String.format("[%s] ([%s])", e.getMessage(), e.getPath().toString());
      LOG.debug(msg);
    }
  }
}

代码示例来源:origin: org.eclipse.leshan/leshan-server-cf

@Override
public void visit(final DiscoverRequest request) {
  switch (coapResponse.getCode()) {
  case CONTENT:
    LinkObject[] links = null;
    if (MediaTypeRegistry.APPLICATION_LINK_FORMAT != coapResponse.getOptions().getContentFormat()) {
      LOG.debug("Expected LWM2M Client [{}] to return application/link-format [{}] content but got [{}]",
          client.getEndpoint(), MediaTypeRegistry.APPLICATION_LINK_FORMAT, coapResponse.getOptions()
              .getContentFormat());
      links = new LinkObject[] {}; // empty list
    } else {
      links = LinkObject.parse(coapResponse.getPayload());
    }
    lwM2mresponse = new DiscoverResponse(fromCoapCode(coapResponse.getCode().value), links);
    break;
  case NOT_FOUND:
  case UNAUTHORIZED:
  case METHOD_NOT_ALLOWED:
    lwM2mresponse = new DiscoverResponse(fromCoapCode(coapResponse.getCode().value));
    break;
  default:
    handleUnexpectedResponseCode(client.getEndpoint(), coapRequest, coapResponse);
  }
}

代码示例来源:origin: eclipse/californium

if (!responseStatus.addBlock(response.getPayload())) {
  LOGGER.log(Level.FINE, "requested resource body exceeds max buffer size [{0}], aborting request", maxResourceBodySize);
  exchange.getRequest().cancel();

代码示例来源:origin: org.eclipse.californium/californium-core

status.addBlock(response.getPayload());

相关文章