java.net.http.HttpResponse.BodyHandlers#com.eclipsesource.json.JsonArray源码实例Demo

下面列出了java.net.http.HttpResponse.BodyHandlers#com.eclipsesource.json.JsonArray 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: box-java-sdk   文件: BoxFolder.java
/**
 * Gets information about all of the collaborations for this folder.
 *
 * @return a collection of information about the collaborations for this folder.
 */
public Collection<BoxCollaboration.Info> getCollaborations() {
    BoxAPIConnection api = this.getAPI();
    URL url = GET_COLLABORATIONS_URL.build(api.getBaseURL(), this.getID());

    BoxAPIRequest request = new BoxAPIRequest(api, url, "GET");
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJSON = JsonObject.readFrom(response.getJSON());

    int entriesCount = responseJSON.get("total_count").asInt();
    Collection<BoxCollaboration.Info> collaborations = new ArrayList<BoxCollaboration.Info>(entriesCount);
    JsonArray entries = responseJSON.get("entries").asArray();
    for (JsonValue entry : entries) {
        JsonObject entryObject = entry.asObject();
        BoxCollaboration collaboration = new BoxCollaboration(api, entryObject.get("id").asString());
        BoxCollaboration.Info info = collaboration.new Info(entryObject);
        collaborations.add(info);
    }

    return collaborations;
}
 
源代码2 项目: box-java-sdk   文件: BoxWebHook.java
/**
 * Setter for {@link #getTriggers()}.
 *
 * @param triggers
 *            {@link #getTriggers()}
 * @return itself
 */
public Info setTriggers(Set<BoxWebHook.Trigger> triggers) {
    validateTriggers(this.target.getType(), triggers);

    JsonArray oldValue;
    if (this.triggers != null) {
        oldValue = toJsonArray(CollectionUtils.map(this.triggers, TRIGGER_TO_VALUE));
    } else {
        oldValue = null;
    }
    JsonArray newValue = toJsonArray(CollectionUtils.map(triggers, TRIGGER_TO_VALUE));

    if (!newValue.equals(oldValue)) {
        this.triggers = Collections.unmodifiableSet(triggers);
        this.addPendingChange(JSON_KEY_TRIGGERS, newValue);
    }

    return this;
}
 
public synchronized boolean isSendingOperationComplete(String opID)
    throws WalletCallException, IOException, InterruptedException
{
	JsonArray response = this.executeCommandAndGetJsonArray(
		"z_getoperationstatus", wrapStringParameter("[\"" + opID + "\"]"));
	JsonObject jsonStatus = response.get(0).asObject();

	String status = jsonStatus.getString("status", "ERROR");

	Log.info("Operation " + opID + " status is " + response + ".");

	if (status.equalsIgnoreCase("success") ||
		status.equalsIgnoreCase("error") ||
		status.equalsIgnoreCase("failed"))
	{
		return true;
	} else if (status.equalsIgnoreCase("executing") || status.equalsIgnoreCase("queued"))
	{
		return false;
	} else
	{
		throw new WalletCallException("Unexpected status response from wallet: " + response.toString());
	}
}
 
public synchronized String getSuccessfulOperationTXID(String opID)
       throws WalletCallException, IOException, InterruptedException
{
	String TXID = null;
	JsonArray response = this.executeCommandAndGetJsonArray(
		"z_getoperationstatus", wrapStringParameter("[\"" + opID + "\"]"));
	JsonObject jsonStatus = response.get(0).asObject();
	JsonValue  opResultValue = jsonStatus.get("result"); 
	
	if (opResultValue != null)
	{
		JsonObject opResult = opResultValue.asObject();
		if (opResult.get("txid") != null)
		{
			TXID = opResult.get("txid").asString();
		}
	}
	
	return TXID;
}
 
源代码5 项目: forecastio-lib-java   文件: ForecastIO.java
public ForecastIO(String LATITUDE, String LONGITUDE, String API_KEY){	

		if (API_KEY.length()==32) {
			this.ForecastIOApiKey = API_KEY;
			this.forecast = new JsonObject();
			this.currently = new JsonObject();
			this.minutely = new JsonObject();
			this.hourly = new JsonObject();
			this.daily = new JsonObject();
			this.flags = new JsonObject();
			this.alerts = new JsonArray();
			this.timeURL = null;
			this.excludeURL = null;
			this.extend = false;
			this.unitsURL = UNITS_AUTO;
			this.langURL = LANG_ENGLISH;
			this.proxy_to_use = null;

			getForecast(LATITUDE, LONGITUDE);
		}
		else {
			System.err.println("The API Key doesn't seam to be valid.");
		}

	}
 
源代码6 项目: onos   文件: FlowsResourceTest.java
@Override
public boolean matchesSafely(JsonArray json) {
    boolean flowFound = false;

    for (int jsonFlowIndex = 0; jsonFlowIndex < json.size();
         jsonFlowIndex++) {

        final JsonObject jsonFlow = json.get(jsonFlowIndex).asObject();

        final String flowId = Long.toString(flow.id().value());
        final String jsonFlowId = jsonFlow.get("id").asString();
        if (jsonFlowId.equals(flowId)) {
            flowFound = true;

            //  We found the correct flow, check attribute values
            assertThat(jsonFlow, matchesFlow(flow, APP_ID.name()));
        }
    }
    if (!flowFound) {
        reason = "Flow with id " + flow.id().toString() + " not found";
        return false;
    } else {
        return true;
    }
}
 
源代码7 项目: r2cloud   文件: MetricsController.java
@Override
public ModelAndView doGet(IHTTPSession session) {
	ModelAndView result = new ModelAndView();
	JsonArray array = new JsonArray();
	for (Entry<String, Metric> cur : metrics.getRegistry().getMetrics().entrySet()) {
		JsonObject curObject = new JsonObject();
		curObject.add("id", cur.getKey());
		curObject.add("url", signed.sign("/api/v1/admin/static/rrd/" + cur.getKey() + ".rrd"));
		if (cur.getValue() instanceof FormattedGauge<?>) {
			curObject.add("format", ((FormattedGauge<?>) cur.getValue()).getFormat().toString());
		}
		array.add(curObject);
	}
	result.setData(array.toString());
	return result;
}
 
源代码8 项目: box-android-sdk   文件: BoxRequest.java
protected void parseHashMapEntry(JsonObject jsonBody, Map.Entry<String, Object> entry) {
    Object obj = entry.getValue();
    if (obj instanceof BoxJsonObject) {
        jsonBody.add(entry.getKey(), parseJsonObject(obj));
    } else if (obj instanceof Double) {
        jsonBody.add(entry.getKey(), Double.toString((Double) obj));
    } else if (obj instanceof Enum || obj instanceof Boolean) {
        jsonBody.add(entry.getKey(), obj.toString());
    } else if (obj instanceof JsonArray) {
        jsonBody.add(entry.getKey(), (JsonArray) obj);
    } else if (obj instanceof Long) {
        jsonBody.add(entry.getKey(), JsonValue.valueOf((Long)obj));
    } else if (obj instanceof Integer) {
        jsonBody.add(entry.getKey(), JsonValue.valueOf((Integer)obj));
    } else if (obj instanceof Float) {
        jsonBody.add(entry.getKey(), JsonValue.valueOf((Float)obj));
    } else if (obj instanceof String) {
        jsonBody.add(entry.getKey(), (String) obj);
    } else {
        BoxLogUtils.e("Unable to parse value " + obj, new RuntimeException("Invalid value"));
    }

}
 
源代码9 项目: onos   文件: GroupsResourceTest.java
/**
 * Tests the result of a rest api GET for a device.
 */
@Test
public void testGroupsSingleDevice() {
    setupMockGroups();
    final Set<Group> groups = new HashSet<>();
    groups.add(group5);
    groups.add(group6);
    expect(mockGroupService.getGroups(anyObject()))
            .andReturn(groups).anyTimes();
    replay(mockGroupService);
    replay(mockDeviceService);
    final WebTarget wt = target();
    final String response = wt.path("groups/" + deviceId3).request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("groups"));
    final JsonArray jsonGroups = result.get("groups").asArray();
    assertThat(jsonGroups, notNullValue());
    assertThat(jsonGroups, hasGroup(group5));
    assertThat(jsonGroups, hasGroup(group6));
}
 
源代码10 项目: JWT4B   文件: Config.java
private static String generateDefaultConfigFile() {
	JsonObject configJO = new JsonObject();
	
	JsonArray jwtKeywordsJA = new JsonArray();
	for (String jwtKeyword : jwtKeywords) {
		jwtKeywordsJA.add(jwtKeyword);
	}
	
	JsonArray tokenKeywordsJA = new JsonArray();
	for (String tokenKeyword : tokenKeywords) {
		tokenKeywordsJA.add(tokenKeyword);
	}
	
	configJO.add("resetEditor", true);
	configJO.add("highlightColor", highlightColor);
	configJO.add("interceptComment", interceptComment);
	configJO.add("jwtKeywords",jwtKeywordsJA);
	configJO.add("tokenKeywords",tokenKeywordsJA);
	
	configJO.add("cveAttackModePublicKey", cveAttackModePublicKey);
	configJO.add("cveAttackModePrivateKey", cveAttackModePrivateKey);
	
	return configJO.toString(WriterConfig.PRETTY_PRINT);
}
 
源代码11 项目: box-java-sdk   文件: BoxTask.java
/**
 * Gets any assignments for this task.
 * @return a list of assignments for this task.
 */
public List<BoxTaskAssignment.Info> getAssignments() {
    URL url = GET_ASSIGNMENTS_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID());
    BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJSON = JsonObject.readFrom(response.getJSON());

    int totalCount = responseJSON.get("total_count").asInt();
    List<BoxTaskAssignment.Info> assignments = new ArrayList<BoxTaskAssignment.Info>(totalCount);
    JsonArray entries = responseJSON.get("entries").asArray();
    for (JsonValue value : entries) {
        JsonObject assignmentJSON = value.asObject();
        BoxTaskAssignment assignment = new BoxTaskAssignment(this.getAPI(), assignmentJSON.get("id").asString());
        BoxTaskAssignment.Info info = assignment.new Info(assignmentJSON);
        assignments.add(info);
    }

    return assignments;
}
 
源代码12 项目: onos   文件: GroupsResourceTest.java
/**
 * Tests the result of the rest api GET when there are active groups.
 */
@Test
public void testGroupsPopulatedArray() {
    setupMockGroups();
    replay(mockGroupService);
    replay(mockDeviceService);
    final WebTarget wt = target();
    final String response = wt.path("groups").request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("groups"));
    final JsonArray jsonGroups = result.get("groups").asArray();
    assertThat(jsonGroups, notNullValue());
    assertThat(jsonGroups, hasGroup(group1));
    assertThat(jsonGroups, hasGroup(group2));
    assertThat(jsonGroups, hasGroup(group3));
    assertThat(jsonGroups, hasGroup(group4));
}
 
源代码13 项目: onos   文件: MulticastRouteResourceTest.java
/**
 * Tests the results of the REST API GET when there are active mcastroutes.
 */
@Test
public void testMcastRoutePopulatedArray() {
    initMcastRouteMocks();
    final Set<McastRoute> mcastRoutes = ImmutableSet.of(route1, route2, route3);
    expect(mockMulticastRouteService.getRoutes()).andReturn(mcastRoutes).anyTimes();
    replay(mockMulticastRouteService);

    final WebTarget wt = target();
    final String response = wt.path("mcast").request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("routes"));
    final JsonArray jsonMcastRoutes = result.get("routes").asArray();
    assertThat(jsonMcastRoutes, notNullValue());
    assertThat(jsonMcastRoutes, hasMcastRoute(route1));
    assertThat(jsonMcastRoutes, hasMcastRoute(route2));
    assertThat(jsonMcastRoutes, hasMcastRoute(route3));
}
 
源代码14 项目: onos   文件: MappingsWebResourceTest.java
/**
 * Tests the result of the rest api GET when there are active mappings.
 */
@Test
public void testMappingsPopulateArray() {
    setupMockMappings();
    expect(mockMappingService.getAllMappingEntries(anyObject()))
            .andReturn(mappingEntries).once();
    replay(mockMappingService);
    final WebTarget wt = target();
    final String response = wt.path(PREFIX + "/" + DATABASE).request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("mappings"));
    final JsonArray jsonMappings = result.get("mappings").asArray();
    assertThat(jsonMappings, notNullValue());
    assertThat(jsonMappings, hasMapping(mapping1));
    assertThat(jsonMappings, hasMapping(mapping2));
    assertThat(jsonMappings, hasMapping(mapping3));
    assertThat(jsonMappings, hasMapping(mapping4));
}
 
源代码15 项目: REST-Sample-Code   文件: SyncLeads.java
private JsonObject buildRequest() {
	JsonObject requestBody = new JsonObject(); //JsonObject container for the request body
	//add optional params
	if (action != null){
		requestBody.add("action", action);
	}
	if (lookupField != null){
		requestBody.add("lookupField", lookupField);
	}
	//assemble the input from leads into a JsonArray
	JsonArray input = new JsonArray();
	int i;
	for (i = 0; i < leads.length; i++){
		input.add(leads[i]);
	}
	//add our array to the input parameter of the body
	requestBody.add("input", input);
	return requestBody;
}
 
源代码16 项目: box-java-sdk   文件: BoxFile.java
/**
 * Gets a list of any comments on this file.
 *
 * @return a list of comments on this file.
 */
public List<BoxComment.Info> getComments() {
    URL url = GET_COMMENTS_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID());
    BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJSON = JsonObject.readFrom(response.getJSON());

    int totalCount = responseJSON.get("total_count").asInt();
    List<BoxComment.Info> comments = new ArrayList<BoxComment.Info>(totalCount);
    JsonArray entries = responseJSON.get("entries").asArray();
    for (JsonValue value : entries) {
        JsonObject commentJSON = value.asObject();
        BoxComment comment = new BoxComment(this.getAPI(), commentJSON.get("id").asString());
        BoxComment.Info info = comment.new Info(commentJSON);
        comments.add(info);
    }

    return comments;
}
 
源代码17 项目: REST-Sample-Code   文件: RequestCampaign.java
private JsonObject buildRequest(){
JsonObject jo = new JsonObject();//parent object
JsonObject input = new JsonObject();//inut object to hold arrays of tokens and leads
JsonArray leads = new JsonArray();
int i;
for (i = 0; i < leadIds.length; i++) {
	leads.add(leadIds[i]);
}
input.add("leads", leads);
//assemble array of tokens and add to input if present
if (tokens != null){
	JsonArray tokensArray = new JsonArray();
	for (JsonObject jsonObject : tokens) {
		tokensArray.add(jsonObject);
		}
	input.add("tokens", tokensArray);
	}
//add input as a member of the parent
jo.add("input", input);
return jo;
}
 
源代码18 项目: IrScrutinizer   文件: IrdbImporter.java
private static void setupManufacturers(boolean verbose) throws IOException {
    ArrayList<String> newManufacturers = new ArrayList<>(1024);
    String path = String.format(urlFormatBrands, 1);
    for (int index = 1; index <= 100 && !path.isEmpty(); index++) {
        JsonObject o = getJsonObject(path, verbose);
        JsonValue meta = o.get("meta");
        JsonObject metaObject = meta.asObject();
        path = metaObject.get("next").asString();
        if (verbose)
            System.err.println("Read page " + metaObject.get("page").asInt());
        JsonArray objects = o.get("objects").asArray();
        for (JsonValue val : objects) {
            JsonObject obj = val.asObject();
            String brand = obj.get("brand").asString();
            if (!newManufacturers.contains(brand))
                newManufacturers.add(brand);
        }
    }
    manufacturers = newManufacturers;
}
 
源代码19 项目: box-java-sdk   文件: BoxUser.java
/**
 * Gets information about all of the group memberships for this user.
 * Does not support paging.
 *
 * <p>Note: This method is only available to enterprise admins.</p>
 *
 * @return a collection of information about the group memberships for this user.
 */
public Collection<BoxGroupMembership.Info> getMemberships() {
    BoxAPIConnection api = this.getAPI();
    URL url = USER_MEMBERSHIPS_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID());

    BoxAPIRequest request = new BoxAPIRequest(api, url, "GET");
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJSON = JsonObject.readFrom(response.getJSON());

    int entriesCount = responseJSON.get("total_count").asInt();
    Collection<BoxGroupMembership.Info> memberships = new ArrayList<BoxGroupMembership.Info>(entriesCount);
    JsonArray entries = responseJSON.get("entries").asArray();
    for (JsonValue entry : entries) {
        JsonObject entryObject = entry.asObject();
        BoxGroupMembership membership = new BoxGroupMembership(api, entryObject.get("id").asString());
        BoxGroupMembership.Info info = membership.new Info(entryObject);
        memberships.add(info);
    }

    return memberships;
}
 
源代码20 项目: IrScrutinizer   文件: CommandFusionImporter.java
Remote parseRemote(JsonObject jsonObject) {
    JsonObject remoteInfo = (JsonObject) jsonObject.get("RemoteInfo");
    JsonArray remoteFunctions = (JsonArray) jsonObject.get("RemoteFunctions");

    Map<String, Command> commands = new LinkedHashMap<>(8);
    for (JsonValue c : remoteFunctions) {
        Command command = parseCommand((JsonObject) c);
        if (command != null)
            commands.put(command.getName(), command);
    }
    String name = remoteInfo.getString("RemoteID", null);
    String deviceClass = remoteInfo.getString("DeviceFamily", null);
    String manufacturer = remoteInfo.getString("Manufacturer", null);
    String model = remoteInfo.getString("DeviceModel", null);
    String remoteName = remoteInfo.getString("RemoteModel", null);
    Map<String, String> notes = new HashMap<>(1);
    notes.put("Description", remoteInfo.getString("Description", null));

    Remote remote = new Remote(new Remote.MetaData(name, null, manufacturer, model, deviceClass, remoteName),
            null /* String comment */, notes, commands,
            null /* HashMap<String,HashMap<String,String>> applicationParameters*/);
    return remote;
}
 
源代码21 项目: onos   文件: MetersResourceTest.java
/**
 * Tests the result of a rest api GET for a device with meter id.
 */
@Test
public void testMeterSingleDeviceWithId() {
    setupMockMeters();

    expect(mockMeterService.getMeter(anyObject(), anyObject()))
            .andReturn(meter5).anyTimes();
    replay(mockMeterService);
    replay(mockDeviceService);

    final WebTarget wt = target();
    final String response = wt.path("meters/" + deviceId3.toString()
            + "/" + meter5.id().id()).request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("meters"));
    final JsonArray jsonMeters = result.get("meters").asArray();
    assertThat(jsonMeters, notNullValue());
    assertThat(jsonMeters, hasMeter(meter5));
}
 
源代码22 项目: forecastio-lib-java   文件: ForecastIO.java
public ForecastIO(String LATITUDE, String LONGITUDE, String PROXYNAME, int PROXYPORT, String API_KEY){	

		if (API_KEY.length()==32) {
			this.ForecastIOApiKey = API_KEY;
			this.forecast = new JsonObject();
			this.currently = new JsonObject();
			this.minutely = new JsonObject();
			this.hourly = new JsonObject();
			this.daily = new JsonObject();
			this.flags = new JsonObject();
			this.alerts = new JsonArray();
			this.timeURL = null;
			this.excludeURL = null;
			this.extend = false;
			this.unitsURL = UNITS_AUTO;
			this.langURL = LANG_ENGLISH;
			this.proxy_to_use = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXYNAME, PROXYPORT));

			getForecast(LATITUDE, LONGITUDE);
		}
		else {
			System.err.println("The API Key doesn't seam to be valid.");
		}

	}
 
源代码23 项目: box-java-sdk   文件: MetadataTemplate.java
/**
 * Gets the Json Array representation of the given list of strings.
 * @param keys List of strings
 * @return the JsonArray represents the list of keys
 */
private static JsonArray getJsonArray(List<String> keys) {
    JsonArray array = new JsonArray();
    for (String key : keys) {
        array.add(key);
    }

    return array;
}
 
源代码24 项目: box-java-sdk   文件: BoxRetentionPolicy.java
/**
 * Used to create a new retention policy with optional parameters.
 * @param api the API connection to be used by the created user.
 * @param name the name of the retention policy.
 * @param type the type of the retention policy. Can be "finite" or "indefinite".
 * @param length the duration in days that the retention policy will be active for after being assigned to content.
 * @param action the disposition action can be "permanently_delete" or "remove_retention".
 * @param optionalParams the optional parameters.
 * @return the created retention policy's info.
 */
private static BoxRetentionPolicy.Info createRetentionPolicy(BoxAPIConnection api, String name, String type,
                                                             int length, String action,
                                                             RetentionPolicyParams optionalParams) {
    URL url = RETENTION_POLICIES_URL_TEMPLATE.build(api.getBaseURL());
    BoxJSONRequest request = new BoxJSONRequest(api, url, "POST");
    JsonObject requestJSON = new JsonObject()
            .add("policy_name", name)
            .add("policy_type", type)
            .add("disposition_action", action);
    if (!type.equals(TYPE_INDEFINITE)) {
        requestJSON.add("retention_length", length);
    }
    if (optionalParams != null) {
        requestJSON.add("can_owner_extend_retention", optionalParams.getCanOwnerExtendRetention());
        requestJSON.add("are_owners_notified", optionalParams.getAreOwnersNotified());

        List<BoxUser.Info> customNotificationRecipients = optionalParams.getCustomNotificationRecipients();
        if (customNotificationRecipients.size() > 0) {
            JsonArray users = new JsonArray();
            for (BoxUser.Info user : customNotificationRecipients) {
                JsonObject userJSON = new JsonObject()
                        .add("type", "user")
                        .add("id", user.getID());
                users.add(userJSON);
            }
            requestJSON.add("custom_notification_recipients", users);
        }
    }
    request.setBody(requestJSON.toString());
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
    BoxRetentionPolicy createdPolicy = new BoxRetentionPolicy(api, responseJSON.get("id").asString());
    return createdPolicy.new Info(responseJSON);
}
 
源代码25 项目: onos   文件: LinksResourceTest.java
/**
 * Tests the result of the rest api GET of links for a specific device.
 */
@Test
public void testLinksByDevice() {
    expect(mockLinkService.getDeviceLinks(isA(DeviceId.class)))
            .andReturn(ImmutableSet.of(link2))
            .anyTimes();

    replay(mockLinkService);

    WebTarget wt = target();
    String response = wt
            .path("links")
            .queryParam("device", "src2")
            .request()
            .get(String.class);
    assertThat(response, containsString("{\"links\":["));

    JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("links"));

    JsonArray jsonLinks = result.get("links").asArray();
    assertThat(jsonLinks, notNullValue());
    assertThat(jsonLinks.size(), is(1));

    assertThat(jsonLinks, hasLink(link2));
}
 
public synchronized String[] getWalletAllPublicAddresses()
	throws WalletCallException, IOException, InterruptedException
{
	JsonArray jsonReceivedOutputs = executeCommandAndGetJsonArray("listreceivedbyaddress", "0", "true");

	Set<String> addresses = new HashSet<>();
	for (int i = 0; i < jsonReceivedOutputs.size(); i++)
	{
	   	JsonObject outp = jsonReceivedOutputs.get(i).asObject();
	   	addresses.add(outp.getString("address", "ERROR!"));
	}

	return addresses.toArray(new String[0]);
   }
 
public synchronized String getMemoField(String acc, String txID)
	throws WalletCallException, IOException, InterruptedException
{
	JsonArray jsonTransactions = this.executeCommandAndGetJsonArray(
		"z_listreceivedbyaddress", wrapStringParameter(acc));
		
       for (int i = 0; i < jsonTransactions.size(); i++)
       {
           if (jsonTransactions.get(i).asObject().getString("txid",  "ERROR!").equals(txID))
           {
           	if (jsonTransactions.get(i).asObject().get("memo") == null)
           	{
           		return null;
           	}
           	
               String memoHex = jsonTransactions.get(i).asObject().getString("memo", "ERROR!");
               String decodedMemo = Util.decodeHexMemo(memoHex);
               
               // Return only if not null - sometimes multiple incoming transactions have the same ID
               // if we have loopback send etc.
               if (decodedMemo != null)
               {
               	return decodedMemo;
               }
           }
       }

       return null;
}
 
private JsonArray executeCommandAndGetJsonArray(String command1, String command2, String command3)
	throws WalletCallException, IOException, InterruptedException
{
	JsonValue response = this.executeCommandAndGetJsonValue(command1, command2, command3);

	if (response.isArray())
	{
		return response.asArray();
	} else
	{
		throw new WalletCallException("Unexpected non-array response from wallet: " + response.toString());
	}
}
 
源代码29 项目: box-java-sdk   文件: Metadata.java
/**
 * Adds a new metadata value of array type.
 * @param path the path to the field.
 * @param values the collection of values.
 * @return the metadata object for chaining.
 */
public Metadata add(String path, List<String> values) {
    JsonArray arr = new JsonArray();
    for (String value : values) {
        arr.add(value);
    }
    this.values.add(this.pathToProperty(path), arr);
    this.addOp("add", path, arr);
    return this;
}
 
源代码30 项目: onos   文件: IntentsResourceTest.java
private boolean checkFlowTreatment(FlowEntry flow, JsonObject jsonFlow) {

            if (flow.treatment() != null) {
                JsonObject jsonTreatment =
                        jsonFlow.get(TREATMENT).asObject();
                JsonArray jsonInstructions =
                        jsonTreatment.get(INSTRUCTIONS).asArray();

                if (flow.treatment().immediate().size() !=
                        jsonInstructions.size()) {
                    reason = "instructions array size of " +
                            flow.treatment().immediate().size();

                    return false;
                }
                for (Instruction instruction :
                        flow.treatment().immediate()) {
                    boolean instructionFound = false;
                    for (int instructionIndex = 0;
                         instructionIndex < jsonInstructions.size();
                         instructionIndex++) {
                        String jsonType =
                                jsonInstructions.get(instructionIndex)
                                        .asObject().get(TYPE).asString();

                        String instructionType =
                                instruction.type().name();

                        if (jsonType.equals(instructionType)) {
                            instructionFound = true;
                        }
                    }
                    if (!instructionFound) {
                        reason = INSTRUCTIONS + SPACE + instruction;
                        return false;
                    }
                }
            }
            return true;
        }