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

x33g5p2x  于2022-01-26 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(67)

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

OptionSet.addLocationPath介绍

[英]Adds a path segment to the Location-Path options. Returns the current OptionSet object for a fluent API.
[中]将路径段添加到位置路径选项中。返回fluent API的当前OptionSet对象。

代码示例

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

/**
 * Sets the complete relative Location-Path.
 * Returns the current OptionSet object for a fluent API.
 * @param path the Location-Path to set
 * @return this OptionSet
 */
public OptionSet setLocationPath(String path) {
  final String slash = "/";
  
  // remove leading slash
  if (path.startsWith(slash)) {
    path = path.substring(slash.length());
  }
  
  clearLocationPath();
  
  for (String segment : path.split(slash)) {
    // empty path segments are allowed (e.g., /test vs /test/)
    addLocationPath(segment);
  }
  return this;
}

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

/**
 * Sets the complete relative Location-Path.
 * Returns the current OptionSet object for a fluent API.
 * @param path the Location-Path to set
 * @return this OptionSet
 */
public OptionSet setLocationPath(String path) {
  final String slash = "/";
  
  // remove leading slash
  if (path.startsWith(slash)) {
    path = path.substring(slash.length());
  }
  
  clearLocationPath();
  
  for (String segment : path.split(slash)) {
    // empty path segments are allowed (e.g., /test vs /test/)
    addLocationPath(segment);
  }
  return this;
}

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

@Test
public void testLocationOptions() {
  OptionSet options = new OptionSet();
  
  options.setLocationPath("/foo/bar");
  Assert.assertEquals("Uri-Path", "foo/bar", options.getLocationPathString());
  options.setLocationPath("foo/bar");
  Assert.assertEquals("Uri-Path", "foo/bar", options.getLocationPathString());
  options.setLocationPath("//foo/bar");
  Assert.assertEquals("Uri-Path", "/foo/bar", options.getLocationPathString());
  options.setLocationPath("/foo//bar");
  Assert.assertEquals("Uri-Path", "foo//bar", options.getLocationPathString());
  
  options.clearLocationPath();
  options.addLocationPath("foo");
  options.addLocationPath("bar");
  Assert.assertEquals("Uri-Path", "foo/bar", options.getLocationPathString());
  options.clearLocationPath();
  options.addLocationPath("foo");
  options.addLocationPath("");
  options.addLocationPath("bar");
  Assert.assertEquals("Uri-Path", "foo//bar", options.getLocationPathString());
}

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

@Test public void testUTF8Encoding() {
    Response response = new Response(ResponseCode.CONTENT);
    response.setType(Type.NON);
    response.setMID(expectedMid);
    response.setToken(new byte[] {});
    response.getOptions().addLocationPath("ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ").addLocationPath("γλώσσα")
        .addLocationPath("пустынных").addLocationQuery("ვეპხის=யாமறிந்த").addLocationQuery("⠊⠀⠉⠁⠝=⠑⠁⠞⠀⠛⠇⠁⠎⠎");
    response.setPayload("⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑");

    RawData rawData = serializer.serializeResponse(response);

    Response result = (Response) parser.parseMessage(rawData);
    assertEquals("ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ/γλώσσα/пустынных", response.getOptions().getLocationPathString());
    assertEquals("ვეპხის=யாமறிந்த&⠊⠀⠉⠁⠝=⠑⠁⠞⠀⠛⠇⠁⠎⠎", response.getOptions().getLocationQueryString());
    assertEquals("⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑", result.getPayloadString());
    assertEquals(response.getMID(), result.getMID());
  }
}

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

@Test
  public void testToString() {
    OptionSet options = new OptionSet();
    options.addETag(new byte[] {1, 2, 3});
    options.addETag(new byte[] {(byte)0xBE, (byte)0xEF});
    options.addLocationPath("abc");
    options.setUriPath("/this/is/a/test");
    
    Assert.assertEquals("{\"ETag\":[0x010203,0xbeef], \"Location-Path\":\"abc\", \"Uri-Path\":[\"this\",\"is\",\"a\",\"test\"]}", options.toString());

    options.setMaxAge(77);
    
    Assert.assertEquals("{\"ETag\":[0x010203,0xbeef], \"Location-Path\":\"abc\", \"Uri-Path\":[\"this\",\"is\",\"a\",\"test\"], \"Max-Age\":77}", options.toString());
  }
}

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

case OptionNumberRegistry.IF_NONE_MATCH:  setIfNoneMatch(true); break;
case OptionNumberRegistry.URI_PORT:       setUriPort(option.getIntegerValue()); break;
case OptionNumberRegistry.LOCATION_PATH:  addLocationPath(option.getStringValue()); break;
case OptionNumberRegistry.URI_PATH:       addUriPath(option.getStringValue()); break;
case OptionNumberRegistry.CONTENT_FORMAT: setContentFormat(option.getIntegerValue()); break;

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

case OptionNumberRegistry.IF_NONE_MATCH:  setIfNoneMatch(true); break;
case OptionNumberRegistry.URI_PORT:       setUriPort(option.getIntegerValue()); break;
case OptionNumberRegistry.LOCATION_PATH:  addLocationPath(option.getStringValue()); break;
case OptionNumberRegistry.URI_PATH:       addUriPath(option.getStringValue()); break;
case OptionNumberRegistry.CONTENT_FORMAT: setContentFormat(option.getIntegerValue()); break;

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

@Test public void testResponseParsing() {
  Response response = new Response(ResponseCode.CONTENT);
  response.setType(Type.NON);
  response.setMID(expectedMid);
  response.setToken(new byte[] { 22, -1, 0, 78, 100, 22 });
  response.getOptions().addETag(new byte[] { 1, 0, 0, 0, 0, 1 })
      .addLocationPath("/one/two/three/four/five/six/seven/eight/nine/ten")
      .addOption(new Option(57453, "Arbitrary".hashCode())).addOption(new Option(19205, "Arbitrary1"))
      .addOption(new Option(19205, "Arbitrary2")).addOption(new Option(19205, "Arbitrary3"));
  RawData rawData = serializer.serializeResponse(response);
  Response result = (Response) parser.parseMessage(rawData);
  assertEquals(response.getMID(), result.getMID());
  assertArrayEquals(response.getToken(), result.getToken());
  assertEquals(response.getOptions().asSortedList(), result.getOptions().asSortedList());
}

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

@Test
public void testArbitraryOptions() {
  OptionSet options = new OptionSet();
  options.addETag(new byte[] {1, 2, 3});
  options.addLocationPath("abc");
  options.addOption(new Option(7));
  options.addOption(new Option(43));
  options.addOption(new Option(33));
  options.addOption(new Option(17));
  // Check that options are in the set
  Assert.assertTrue(options.hasOption(OptionNumberRegistry.ETAG));
  Assert.assertTrue(options.hasOption(OptionNumberRegistry.LOCATION_PATH));
  Assert.assertTrue(options.hasOption(7));
  Assert.assertTrue(options.hasOption(17));
  Assert.assertTrue(options.hasOption(33));
  Assert.assertTrue(options.hasOption(43));
  
  // Check that others are not
  Assert.assertFalse(options.hasOption(19));
  Assert.assertFalse(options.hasOption(53));
  
  // Check that we can remove options
  options.clearETags();
  Assert.assertFalse(options.hasOption(OptionNumberRegistry.ETAG));
}

相关文章

微信公众号

最新文章

更多