2 *******************************************************************
4 * Copyright 2016 Samsung Electronics All Rights Reserved.
6 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 package org.iotivity.cloud.base.protocols.coap;
24 import java.nio.charset.StandardCharsets;
25 import java.util.ArrayList;
26 import java.util.List;
28 import org.iotivity.cloud.base.protocols.coap.enums.CoapMethod;
30 public class CoapRequest extends CoapMessage {
31 public CoapRequest(CoapMethod method) {
32 this.code = method.getCode();
35 public CoapMethod getRequestMethod() {
36 return CoapMethod.valueOf(code);
39 public void setUriPath(String path) {
40 if (uri_path == null) {
41 uri_path = new ArrayList<byte[]>();
45 String[] pathSegments = path.split("/");
46 for (String pathSegment : pathSegments) {
47 if (pathSegment.length() == 0)
49 uri_path.add(pathSegment.getBytes(StandardCharsets.UTF_8));
53 public String getUriPath() {
54 if (uri_path == null) {
57 StringBuilder path = new StringBuilder();
58 int nItem = uri_path.size();
59 for (byte[] pathSegment : uri_path) {
60 path.append(new String(pathSegment, StandardCharsets.UTF_8));
65 return path.toString();
68 public List<String> getUriPathSegments() {
69 List<String> segments = new ArrayList<String>();
70 if (uri_path != null) {
71 for (byte[] pathSegment : uri_path) {
72 segments.add(new String(pathSegment, StandardCharsets.UTF_8));
78 public void setUriQuery(String query) {
79 if (uri_query == null) {
80 uri_query = new ArrayList<byte[]>();
82 String[] querySegments = query.split("&");
83 for (String querySegment : querySegments) {
84 uri_query.add(querySegment.getBytes(StandardCharsets.UTF_8));
88 public String getUriQuery() {
89 if (uri_query == null) {
92 StringBuilder uriQuery = new StringBuilder();
93 int nItem = uri_query.size();
94 for (byte[] querySegment : uri_query) {
95 uriQuery.append(new String(querySegment, StandardCharsets.UTF_8));
100 return uriQuery.toString();
103 public List<String> getUriQuerySegments() {
104 List<String> segments = new ArrayList<String>();
105 for (byte[] querySegment : uri_query) {
106 segments.add(new String(querySegment, StandardCharsets.UTF_8));
111 public void clearUriPath() {
115 public void setAccept(byte[] accepts) {