Example usage for javax.json JsonReader readArray

List of usage examples for javax.json JsonReader readArray

Introduction

In this page you can find the example usage for javax.json JsonReader readArray.

Prototype

JsonArray readArray();

Source Link

Document

Returns a JSON array that is represented in the input source.

Usage

From source file:io.hakbot.util.JsonUtil.java

/**
 * Creates a JsonArray from a json-formatted string
 *///from   ww  w.  j a  va  2 s  .c o m
public static JsonArray toJsonArray(String jsonString) {
    JsonReader jsonReader = Json.createReader(new StringReader(jsonString));
    return jsonReader.readArray();
}

From source file:com.dhenton9000.jersey.client.BasicTests.java

@Test
public void testConfigReponseFilter() {
    ClientConfig config = new ClientConfig();
    config.register(ResponseFilter.class);
    Client client = ClientBuilder.newClient(config);
    WebTarget target = client.target(getBaseURI());
    Response response = target.path("restaurant").request().accept(MediaType.APPLICATION_JSON)
            .get(Response.class);
    if (response.getStatus() != 200) {
        fail("status problem for request " + response.getStatus());
    }/*from ww w.ja  v a 2  s .  co m*/

    InputStream jsonStringResponse = response.readEntity(InputStream.class);
    JsonReader myreader = Json.createReader(jsonStringResponse);
    JsonArray restaurants = myreader.readArray();
    assertTrue(restaurants.size() > 5);
    assertTrue(ResponseFilter.gotHit);
    ResponseFilter.gotHit = false;

}

From source file:com.dhenton9000.jersey.client.BasicTests.java

/**
 * this demonstrates writing headers to the request
 *//*  w  w  w  .j  a v a 2 s. c om*/
@Test
public void testConfigRequestFilter() {
    ClientConfig config = new ClientConfig();
    config.register(RequestFilter.class);
    Client client = ClientBuilder.newClient(config);
    WebTarget target = client.target(getBaseURI());
    Response response = target.path("restaurant").request().accept(MediaType.APPLICATION_JSON)
            .get(Response.class);
    if (response.getStatus() != 200) {
        fail("status problem for request " + response.getStatus());
    }

    InputStream jsonStringResponse = response.readEntity(InputStream.class);
    JsonReader myreader = Json.createReader(jsonStringResponse);
    JsonArray restaurants = myreader.readArray();
    assertTrue(restaurants.size() > 5);
    assertTrue(RequestFilter.gotHit);
    RequestFilter.gotHit = false;

}

From source file:de.pangaea.fixo3.CreateFixO3.java

private void run() throws OWLOntologyCreationException, OWLOntologyStorageException, NoSuchAlgorithmException,
        IOException {/*ww  w .j av a 2 s .  c  o m*/
    m = new OntologyManager(FIXO3.ns);
    m.addVersion("1.0");
    m.addDate("2016-11-23");
    m.addCreator("Markus Stocker");
    m.addSeeAlso("http://www.fixo3.eu/");
    m.addImport(Schema.ns, IRI.create(schemaFile));
    m.addImport(SSN.ns);
    m.addImport(EYP.ns, IRI.create(eypFile));

    m.addClass(OceanObservatory);
    m.addLabel(OceanObservatory, "Ocean Observatory");
    m.addSubClass(OceanObservatory, Platform);

    m.addClass(FixedPointOceanObservatory);
    m.addLabel(FixedPointOceanObservatory, "Fixed-Point Ocean Observatory");
    m.addSubClass(FixedPointOceanObservatory, OceanObservatory);

    JsonReader jr = Json.createReader(new FileReader(new File(fixO3ObservatoriesFile)));
    JsonArray ja = jr.readArray();

    for (JsonObject jo : ja.getValuesAs(JsonObject.class)) {
        addFixedOceanObservatory(jo);
    }

    m.save(fixO3File);
    m.saveInferred(fixO3InferredFile);
}

From source file:org.ocelotds.marshalling.ArgumentServices.java

public List getJavaResultFromSpecificUnmarshallerIterable(String json, IJsonMarshaller marshaller)
        throws JsonUnmarshallingException {
    try {//from   ww w. jav a 2  s.com
        List result = new ArrayList<>();
        JsonReader createReader = Json.createReader(new StringReader(json));
        JsonArray readArray = createReader.readArray();
        for (JsonValue jsonValue : readArray) {
            result.add(marshaller.toJava(jsonValue.toString()));
        }
        return result;
    } catch (Throwable t) {
        throw new JsonUnmarshallingException(t.getMessage());
    }
}

From source file:at.porscheinformatik.sonarqube.licensecheck.maven.MavenDependencyScanner.java

@Override
public List<Dependency> scan(File moduleDir, String mavenProjectDependencies) {
    JsonReader jsonReader = Json.createReader(new StringReader(mavenProjectDependencies));
    Set<Dependency> dependencies = new HashSet<>();

    parseDependencyJson(dependencies, jsonReader.readArray());

    loadLicenses(dependencies);// www .  j a  va2 s . co  m

    mapAdditionalLicenses(dependencies);

    jsonReader.close();

    return new ArrayList<>(dependencies);
}

From source file:de.pangaea.fixo3.CreateEsonetYellowPages.java

private void run() throws OWLOntologyCreationException, OWLOntologyStorageException, FileNotFoundException {
    m = new OntologyManager(ns);
    m.addTitle("ESONET Yellow Pages Ontology");
    m.addVersion("1.0");
    m.addDate("2016-11-23");
    m.addCreator("Markus Stocker");
    m.addSeeAlso("http://www.esonetyellowpages.com/");
    m.addImport(SSN.ns);/*from  w w w  .  jav a 2 s .c o m*/

    m.addSubClass(Frequency, MeasurementProperty);
    m.addLabel(Frequency, "Frequency");
    m.addSubClass(ProfilingRange, MeasurementProperty);
    m.addLabel(ProfilingRange, "Profiling Range");
    m.addSubClass(CellSize, MeasurementProperty);
    m.addLabel(CellSize, "Cell Size");
    m.addSubClass(OperatingDepth, MeasurementProperty);
    m.addLabel(OperatingDepth, "Operating Depth");
    m.addSubClass(TemperatureRange, MeasurementProperty);
    m.addLabel(TemperatureRange, "Temperature Range");
    m.addSubClass(MeasuringRange, MeasurementProperty);
    m.addLabel(MeasuringRange, "Measuring Range");

    m.addClass(WaterCurrent);
    m.addLabel(WaterCurrent, "Water Current");
    m.addSubClass(WaterCurrent, FeatureOfInterest);

    m.addClass(CarbonDioxide);
    m.addLabel(CarbonDioxide, "Carbon Dioxide");
    m.addSubClass(CarbonDioxide, FeatureOfInterest);

    m.addClass(Speed);
    m.addLabel(Speed, "Speed");
    m.addSubClass(Speed, Property);
    m.addObjectSome(Speed, isPropertyOf, WaterCurrent);

    m.addClass(PartialPressure);
    m.addLabel(PartialPressure, "Partial Pressure");
    m.addSubClass(PartialPressure, Property);
    m.addObjectSome(PartialPressure, isPropertyOf, CarbonDioxide);

    m.addClass(DopplerEffect);
    m.addSubClass(DopplerEffect, Stimulus);
    m.addLabel(DopplerEffect, "Doppler Effect");
    m.addComment(DopplerEffect,
            "The Doppler effect (or the Doppler shift) is the change in frequency of a wave (or other periodic event) for an observer moving relative to its source.");
    m.addSource(DopplerEffect, IRI.create("https://en.wikipedia.org/wiki/Doppler_effect"));
    m.addObjectAll(DopplerEffect, isProxyFor, Speed);

    m.addClass(Infrared);
    m.addSubClass(Infrared, Stimulus);
    m.addLabel(Infrared, "Infrared");
    m.addComment(Infrared, "Infrared (IR) is an invisible radiant energy.");
    m.addSource(Infrared, IRI.create("https://en.wikipedia.org/wiki/Infrared"));
    m.addObjectAll(Infrared, isProxyFor, PartialPressure);

    m.addClass(AcousticDopplerCurrentProfiler);
    m.addLabel(AcousticDopplerCurrentProfiler, "Acoustic Doppler Current Profiler");
    m.addSource(AcousticDopplerCurrentProfiler,
            IRI.create("https://en.wikipedia.org/wiki/Acoustic_Doppler_current_profiler"));
    m.addComment(AcousticDopplerCurrentProfiler,
            "An acoustic Doppler current profiler (ADCP) is a hydroacoustic current meter similar to a sonar, attempting to measure water current velocities over a depth range using the Doppler effect of sound waves scattered back from particles within the water column.");
    m.addObjectAll(AcousticDopplerCurrentProfiler, detects, DopplerEffect);
    m.addObjectAll(AcousticDopplerCurrentProfiler, observes, Speed);
    m.addSubClass(AcousticDopplerCurrentProfiler, HydroacousticCurrentMeter);

    m.addClass(PartialPressureOfCO2Analyzer);
    m.addLabel(PartialPressureOfCO2Analyzer, "Partial Pressure of CO2 Analyzer");
    m.addObjectAll(PartialPressureOfCO2Analyzer, detects, Infrared);
    m.addObjectAll(PartialPressureOfCO2Analyzer, observes, PartialPressure);
    m.addSubClass(PartialPressureOfCO2Analyzer, SensingDevice);

    m.addClass(HydroacousticCurrentMeter);
    m.addLabel(HydroacousticCurrentMeter, "Hydroacoustic Current Meter");
    m.addSubClass(HydroacousticCurrentMeter, SensingDevice);

    JsonReader jr = Json.createReader(new FileReader(new File(eypDevicesFile)));
    JsonArray ja = jr.readArray();

    for (JsonObject jo : ja.getValuesAs(JsonObject.class)) {
        String name = jo.getString("name");
        String label = jo.getString("label");
        String comment = jo.getString("comment");
        String seeAlso = jo.getString("seeAlso");
        JsonArray equivalentClasses = jo.getJsonArray("equivalentClasses");
        JsonArray subClasses = jo.getJsonArray("subClasses");

        addDeviceType(name, label, comment, seeAlso, equivalentClasses, subClasses);
    }

    m.save(eypFile);
    m.saveInferred(eypInferredFile);
}

From source file:io.bibleget.BibleGetAbout.java

private void prepareDynamicInformation() throws ClassNotFoundException {
    bibleGetDB = BibleGetDB.getInstance();
    jList1 = new VersionsSelect();
    versionLangs = jList1.getVersionLangs();
    versionCount = jList1.getVersionCount();

    String langsSupported;//from w  w  w.j  a va2 s .co  m
    List<String> langsLocalized = new ArrayList<>();
    booksLangs = 0;
    booksStr = "";
    if (bibleGetDB != null) {
        //System.out.println("oh good, biblegetDB is not null!");
        langsSupported = bibleGetDB.getMetaData("LANGUAGES");
        //System.out.println(langsSupported);
        JsonReader jsonReader = Json.createReader(new StringReader(langsSupported));
        JsonArray bibleVersionsObj = jsonReader.readArray();
        booksLangs = bibleVersionsObj.size();
        for (JsonValue jsonValue : bibleVersionsObj) {
            //System.out.println(jsonValue.toString());
            langsLocalized.add(BibleGetI18N.localizeLanguage(jsonValue.toString()));
        }
        booksStr = StringUtils.join(langsLocalized, ", ");
    } else {
        //System.out.println("Looks like biblegetDB is null :/");
    }

}

From source file:edu.harvard.hms.dbmi.bd2k.irct.ri.i2b2transmart.I2B2TranSMARTResourceImplementation.java

public List<Entity> searchObservationOnly(String searchTerm, String strategy, SecureSession session,
        String onlObs) {//  w w w. ja v a 2  s .c  o m
    List<Entity> entities = new ArrayList<Entity>();

    try {
        URI uri = new URI(this.transmartURL.split("://")[0], this.transmartURL.split("://")[1].split("/")[0],
                "/" + this.transmartURL.split("://")[1].split("/")[1] + "/textSearch/findPaths",
                "oblyObs=" + onlObs + "&term=" + searchTerm, null);

        HttpClient client = createClient(session);
        HttpGet get = new HttpGet(uri);
        HttpResponse response = client.execute(get);
        JsonReader reader = Json.createReader(response.getEntity().getContent());
        JsonArray arrayResults = reader.readArray();

        for (JsonValue val : arrayResults) {
            JsonObject returnObject = (JsonObject) val;

            Entity returnedEntity = new Entity();
            returnedEntity
                    .setPui("/" + this.resourceName + converti2b2Path(returnObject.getString("conceptPath")));

            if (!returnObject.isNull("text")) {
                returnedEntity.getAttributes().put("text", returnObject.getString("text"));
            }
            entities.add(returnedEntity);
        }

    } catch (URISyntaxException | JsonException | IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return entities;
}

From source file:edu.harvard.hms.dbmi.bd2k.irct.ri.i2b2transmart.I2B2TranSMARTResourceImplementation.java

@Override
public Result runQuery(SecureSession session, Query query, Result result) throws ResourceInterfaceException {
    result = super.runQuery(session, query, result);

    if (result.getResultStatus() != ResultStatus.ERROR) {
        String resultInstanceId = result.getResourceActionId();
        String resultId = resultInstanceId.split("\\|")[2];
        try {/* w  w w. ja  v a2  s.  c o m*/
            // Wait for it to be either ready or fail
            result = checkForResult(session, result);
            while ((result.getResultStatus() != ResultStatus.ERROR)
                    && (result.getResultStatus() != ResultStatus.COMPLETE)) {
                Thread.sleep(3000);
                result = checkForResult(session, result);
            }
            if (result.getResultStatus() == ResultStatus.ERROR) {
                return result;
            }
            result.setResultStatus(ResultStatus.RUNNING);
            // Loop through the select clauses to build up the select string
            String gatherAllEncounterFacts = "false";
            Map<String, String> aliasMap = new HashMap<String, String>();

            for (ClauseAbstract clause : query.getClauses().values()) {
                if (clause instanceof SelectClause) {
                    SelectClause selectClause = (SelectClause) clause;
                    String pui = convertPUItoI2B2Path(selectClause.getParameter().getPui());
                    aliasMap.put(pui, selectClause.getAlias());

                } else if (clause instanceof WhereClause) {
                    WhereClause whereClause = (WhereClause) clause;
                    String encounter = whereClause.getStringValues().get("ENCOUNTER");
                    if ((encounter != null) && (encounter.equalsIgnoreCase("yes"))) {
                        gatherAllEncounterFacts = "true";
                    }
                }

            }

            if (!aliasMap.isEmpty()) {

                ResultSet rs = (ResultSet) result.getData();
                if (rs.getSize() == 0) {
                    rs = createInitialDataset(result, aliasMap, gatherAllEncounterFacts);
                    result.setData(rs);
                }

                // Loop through the columns submitting and appending to the
                // rows every 10
                List<String> parameterList = new ArrayList<String>();
                int counter = 0;
                String parameters = "";
                for (String param : aliasMap.keySet()) {
                    if (counter == 10) {
                        parameterList.add(parameters);
                        counter = 0;
                        parameters = "";
                    }
                    if (!parameters.equals("")) {
                        parameters += "|";
                    }
                    parameters += param;
                }
                if (!parameters.equals("")) {
                    parameterList.add(parameters);
                }

                for (String parameter : parameterList) {
                    // Call the tranSMART API to get the dataset
                    String url = this.transmartURL + "/ClinicalData/retrieveClinicalData?rid=" + resultId
                            + "&conceptPaths=" + URLEncoder.encode(parameter, "UTF-8")
                            + "&gatherAllEncounterFacts=" + gatherAllEncounterFacts;
                    HttpClient client = createClient(session);
                    HttpGet get = new HttpGet(url);
                    try {
                        HttpResponse response = client.execute(get);
                        JsonReader reader = Json.createReader(response.getEntity().getContent());
                        JsonArray arrayResults = reader.readArray();
                        // Convert the dataset to Tabular format
                        result = convertJsonToResultSet(result, arrayResults, aliasMap,
                                gatherAllEncounterFacts);
                    } catch (JsonException e) {
                    }
                }

            }
            // Set the status to complete
            result.setResultStatus(ResultStatus.COMPLETE);
        } catch (InterruptedException | UnsupportedOperationException | IOException | ResultSetException
                | PersistableException e) {
            result.setResultStatus(ResultStatus.ERROR);
            result.setMessage(e.getMessage());
        }
    }
    return result;
}