org.json.simple.parser.ContainerFactory#org.json.simple.parser.JSONParser源码实例Demo

下面列出了org.json.simple.parser.ContainerFactory#org.json.simple.parser.JSONParser 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Builds URL params from input JSON string
 *
 * @param builder
 * @param jsonStr
 * @return
 * @throws ParseException
 */
public URIBuilder setParams(URIBuilder builder, String jsonStr) throws ParseException {

    if (jsonStr != null && !"".equals(jsonStr)) {
        try {
            JSONParser parser = new JSONParser();
            JSONObject json = (JSONObject) parser.parse(jsonStr);
            json.keySet().forEach((Key) -> {
                builder.setParameter(Key.toString(), (String) json.get(Key));
            });
        } catch (Exception ex) {
            DLogger.LogE(ex.getMessage());
            LOG.log(Level.SEVERE, ex.getMessage(), ex);
        }

    }

    return builder;
}
 
源代码2 项目: BedrockConnect   文件: UIComponents.java
public static ArrayList<String> getFormData(String data) {
    JSONParser parser = new JSONParser();

    // If no server data
    if(data == null)
        return new ArrayList<>();

    try {
        JSONArray obj = (JSONArray) parser.parse(data);
        ArrayList<String> strings = new ArrayList<>();
        for(int i=0;i<obj.size();i++) {
            strings.add(obj.get(i).toString());
        }
        return strings;
    } catch(ParseException e) {
        System.out.println(e.toString());
    }

    return null;
}
 
源代码3 项目: cellery-security   文件: CellStsUtils.java
public static void buildCellStsConfiguration() throws CelleryCellSTSException {

        try {
            String configFilePath = CellStsUtils.getConfigFilePath();
            String content = new String(Files.readAllBytes(Paths.get(configFilePath)), StandardCharsets.UTF_8);
            JSONObject config = (JSONObject) new JSONParser().parse(content);

            CellStsConfiguration.getInstance()
                    .setCellName(getMyCellName())
                    .setStsEndpoint((String) config.get(Constants.Configs.CONFIG_STS_ENDPOINT))
                    .setUsername((String) config.get(Constants.Configs.CONFIG_AUTH_USERNAME))
                    .setPassword((String) config.get(Constants.Configs.CONFIG_AUTH_PASSWORD))
                    .setGlobalJWKEndpoint((String) config.get(Constants.Configs.CONFIG_GLOBAL_JWKS))
                    .setSignatureValidationEnabled(Boolean.parseBoolean(String.valueOf(config.get
                            (Constants.Configs.CONFIG_SIGNATURE_VALIDATION_ENABLED))))
                    .setAudienceValidationEnabled(Boolean.parseBoolean(String.valueOf(config.get
                            (Constants.Configs.CONFIG_AUDIENCE_VALIDATION_ENABLED))))
                    .setIssuerValidationEnabled(Boolean.parseBoolean(String.valueOf(config.get
                            (Constants.Configs.CONFIG_ISSUER_VALIDATION_ENABLED))))
                    .setSTSOPAQueryPrefix((String) config.get(Constants.Configs.CONFIG_OPA_PREFIX))
                    .setAuthorizationEnabled(Boolean.parseBoolean(String.valueOf(config.get
                            (Constants.Configs.CONFIG_AUTHORIZATION_ENABLED))));
        } catch (ParseException | IOException e) {
            throw new CelleryCellSTSException("Error while setting up STS configurations", e);
        }
    }
 
源代码4 项目: Explvs-AIO   文件: RSBuddyPriceGuide.java
private static Optional<Integer> getPrice(final int itemID, final String type) {
    try {
        URL url = new URL("http://api.rsbuddy.com/grandExchange?a=guidePrice&i=" + itemID);
        URLConnection con = url.openConnection();
        con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");

        try (InputStreamReader inputStreamReader = new InputStreamReader(con.getInputStream());
             BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
            JSONParser jsonParser = new JSONParser();
            JSONObject itemJSON = (JSONObject) jsonParser.parse(bufferedReader);

            int price = new Long((long) itemJSON.get(type)).intValue();

            System.out.println("Got RSBuddy price");
            return Optional.of(price);
        }
    } catch (Exception e) {
        System.out.println("Failed to get RSBuddy price");
    }
    return Optional.empty();
}
 
源代码5 项目: Explvs-AIO   文件: LoadoutPanel.java
private Optional<URL> getIcon(final int itemID) {
    try {
        URL url = new URL("http://services.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=" + itemID);
        URLConnection con = url.openConnection();
        con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");

        try (InputStreamReader inputStreamReader = new InputStreamReader(con.getInputStream());
             BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
            JSONParser jsonParser = new JSONParser();
            JSONObject json = (JSONObject) jsonParser.parse(bufferedReader);

            JSONObject itemJSON = (JSONObject) json.get("item");
            String iconURL = (String) itemJSON.get("icon");

            return Optional.of(new URL(iconURL));
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Failed to get icon from RuneScape api");
    }
    return Optional.empty();
}
 
源代码6 项目: soltix   文件: ParserASTJSON.java
public AST parse(InputStream input) throws Exception {
    JSONParser jsonParser = new JSONParser();
    JSONObject jsonObject = (JSONObject)jsonParser.parse(
            new InputStreamReader(input, "UTF-8"));

    AST ast = new AST();

    if (!Configuration.skipASTProcessing) {
        // Process JSON object to build AST
        JSONObjectToAST(ast, jsonObject, 0);
    } else {
        // For debugging: only print, don't interpret
        printJSONObject(jsonObject, 0);
    }
    return ast;
}
 
源代码7 项目: hop   文件: JsonRowMeta.java
public static IRowMeta fromJson(String rowMetaJson) throws ParseException, HopPluginException {
  JSONParser parser = new JSONParser();
  JSONObject jRowMeta = (JSONObject) parser.parse( rowMetaJson );

  IRowMeta rowMeta = new RowMeta(  );

  JSONArray jValues = (JSONArray) jRowMeta.get("values");
  for (int v=0;v<jValues.size();v++) {
    JSONObject jValue = (JSONObject) jValues.get( v );
    String name = (String) jValue.get("name");
    long type = (long)jValue.get("type");
    long length = (long)jValue.get("length");
    long precision = (long)jValue.get("precision");
    String conversionMask = (String) jValue.get("conversionMask");
    IValueMeta valueMeta = ValueMetaFactory.createValueMeta( name, (int)type, (int)length, (int)precision );
    valueMeta.setConversionMask( conversionMask );
    rowMeta.addValueMeta( valueMeta );
  }

  return rowMeta;

}
 
源代码8 项目: singleton   文件: MultComponentService.java
@SuppressWarnings({"unchecked" })
private TranslationDTO getTranslation(TranslationDTO translationDTO)
		throws ParseException, DataException {
	List<String> locales = translationDTO.getLocales();
	List<String> components = translationDTO.getComponents();
	List<String> bundles = multipleComponentsDao.get2JsonStrs(
			translationDTO.getProductName(), translationDTO.getVersion(),
			components, locales);
	JSONArray ja = new JSONArray();
	for (int i = 0; i < bundles.size(); i++) {
		String s = (String) bundles.get(i);
		if (s.equalsIgnoreCase("")) {
			continue;
		}
		JSONObject jo = (JSONObject) new JSONParser().parse(s);
		ja.add(jo);
	}
	translationDTO.setBundles(ja);
	return translationDTO;
}
 
源代码9 项目: VoxelGamesLibv2   文件: MojangUtil.java
/**
 * Tries to fetch the current display name for the user
 *
 * @param id the id of the user to check
 * @return the current display name of that user
 * @throws IOException           if something goes wrong
 * @throws VoxelGameLibException if the user has no display name
 */
@Nonnull
public static String getDisplayName(@Nonnull UUID id) throws IOException, VoxelGameLibException {
    URL url = new URL(NAME_HISTORY_URL.replace("%1", id.toString().replace("-", "")));
    System.out.println(url.toString());
    Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(url.openStream())));
    if (scanner.hasNext()) {
        String json = scanner.nextLine();
        try {
            JSONArray jsonArray = (JSONArray) new JSONParser().parse(json);
            if (json.length() > 0) {
                return (String) ((JSONObject) jsonArray.get(0)).get("name");
            }
        } catch (ParseException ignore) {
        }
    }

    throw new VoxelGameLibException("User has no name! " + id);
}
 
源代码10 项目: singleton   文件: SingleComponentDTO.java
/**
 * Get the ordered SingleComponentDTO from one JSON string
 *
 * @param jsonStr One JSON string can convert to a SingleComponentDTO object
 * @return SingleComponentDTO
 */
@SuppressWarnings("unchecked")
public static SingleComponentDTO getSingleComponentDTOWithLinkedMessages(String jsonStr)
        throws ParseException {
    JSONParser parser = new JSONParser();
    ContainerFactory containerFactory = getContainerFactory();
    Map<String, Object> messages = new LinkedHashMap<String, Object>();
    Map<String, Object> bundle = null;
    bundle = (Map<String, Object>) parser.parse(jsonStr, containerFactory);
    if (bundle == null) {
        return null;
    }
    SingleComponentDTO baseComponentMessagesDTO = new SingleComponentDTO();
    baseComponentMessagesDTO.setId(Long.parseLong(bundle.get(ConstantsKeys.ID) == null ? "0" : bundle.get(ConstantsKeys.ID).toString()));
    baseComponentMessagesDTO.setComponent((String) bundle.get(ConstantsKeys.COMPONENT));
    baseComponentMessagesDTO.setLocale((String) bundle.get(ConstantsKeys.lOCALE));
    messages = (Map<String, Object>) bundle.get(ConstantsKeys.MESSAGES);
    baseComponentMessagesDTO.setMessages(messages);
    return baseComponentMessagesDTO;
}
 
源代码11 项目: kettle-beam   文件: JsonRowMeta.java
public static RowMetaInterface fromJson(String rowMetaJson) throws ParseException, KettlePluginException {
  JSONParser parser = new JSONParser();
  JSONObject jRowMeta = (JSONObject) parser.parse( rowMetaJson );

  RowMetaInterface rowMeta = new RowMeta(  );

  JSONArray jValues = (JSONArray) jRowMeta.get("values");
  for (int v=0;v<jValues.size();v++) {
    JSONObject jValue = (JSONObject) jValues.get( v );
    String name = (String) jValue.get("name");
    long type = (long)jValue.get("type");
    long length = (long)jValue.get("length");
    long precision = (long)jValue.get("precision");
    String conversionMask = (String) jValue.get("conversionMask");
    ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta( name, (int)type, (int)length, (int)precision );
    valueMeta.setConversionMask( conversionMask );
    rowMeta.addValueMeta( valueMeta );
  }

  return rowMeta;

}
 
源代码12 项目: Explvs-AIO   文件: RSBuddyPriceGuide.java
private static Optional<Integer> getPrice(final int itemID, final String type) {
    try {
        URL url = new URL("http://api.rsbuddy.com/grandExchange?a=guidePrice&i=" + itemID);
        URLConnection con = url.openConnection();
        con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");

        try (InputStreamReader inputStreamReader = new InputStreamReader(con.getInputStream());
             BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
            JSONParser jsonParser = new JSONParser();
            JSONObject itemJSON = (JSONObject) jsonParser.parse(bufferedReader);

            int price = new Long((long) itemJSON.get(type)).intValue();

            System.out.println("Got RSBuddy price");
            return Optional.of(price);
        }
    } catch (Exception e) {
        System.out.println("Failed to get RSBuddy price");
    }
    return Optional.empty();
}
 
源代码13 项目: Explvs-AIO   文件: LoadoutPanel.java
private Optional<URL> getIcon(final int itemID) {
    try {
        URL url = new URL("http://services.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=" + itemID);
        URLConnection con = url.openConnection();
        con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");

        try (InputStreamReader inputStreamReader = new InputStreamReader(con.getInputStream());
             BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
            JSONParser jsonParser = new JSONParser();
            JSONObject json = (JSONObject) jsonParser.parse(bufferedReader);

            JSONObject itemJSON = (JSONObject) json.get("item");
            String iconURL = (String) itemJSON.get("icon");

            return Optional.of(new URL(iconURL));
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Failed to get icon from RuneScape api");
    }
    return Optional.empty();
}
 
源代码14 项目: JFoolNLTK   文件: Vocab.java
private void parseJson(String content) throws ParseException {
    JSONParser parser = new JSONParser();
    Object obj = parser.parse(content);
    JSONObject jsonObject = (JSONObject) obj;

    Map<String, Integer> wordMap = parseStrMap((JSONObject) jsonObject.get("word_map"));
    Map<String, Integer> charMap = parseStrMap((JSONObject) jsonObject.get("char_map"));

    Map<Integer, String> segMap = parseIdMap((JSONObject) jsonObject.get("seg_map"));
    Map<Integer, String> posMap = parseIdMap((JSONObject) jsonObject.get("pos_map"));
    Map<Integer, String> nerMap = parseIdMap((JSONObject) jsonObject.get("ner_map"));

    charToId.setLabelToid(charMap);
    wordToId.setLabelToid(wordMap);
    idToSeg.setIdTolabel(segMap);
    idToPos.setIdTolabel(posMap);
    idToNer.setIdTolabel(nerMap);
}
 
源代码15 项目: proxylive   文件: ChannelURLService.java
private JSONObject getJSONResponse(URL url) throws IOException, ParseException {
    JSONParser jsonParser = new JSONParser();
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setReadTimeout(10000);
    if (url.getUserInfo() != null) {
        String basicAuth = "Basic " + new String(Base64.getEncoder().encode(url.getUserInfo().getBytes()));
        connection.setRequestProperty("Authorization", basicAuth);
    }
    connection.setRequestMethod("GET");
    connection.connect();
    if (connection.getResponseCode() != 200) {
        throw new IOException("Error on open stream:" + url);
    }
    JSONObject returnObject = (JSONObject) jsonParser.parse(new InputStreamReader(connection.getInputStream(), "UTF-8"));
    connection.disconnect();
    return returnObject;
}
 
源代码16 项目: netbeans   文件: LibraryProvider.java
/**
 * Update a library returned by {@link #findLibraries(java.lang.String)}.
 * The full library data is fetched and the {@code versions} property is
 * filled.
 *
 * @param library to be updated
 */
public void updateLibraryVersions(Library library) {
    Objects.nonNull(library);
    if(library.getVersions() != null && library.getVersions().length > 0) {
        return;
    }
    Library cachedLibrary = getCachedLibrary(library.getName());
    if(cachedLibrary != null) {
        library.setVersions(cachedLibrary.getVersions());
        return;
    }
    String data = readUrl(getLibraryDataUrl(library.getName()));
    if(data != null) {
        try {
            JSONParser parser = new JSONParser();
            JSONObject libraryData = (JSONObject)parser.parse(data);
            updateLibrary(library, libraryData);
            entryCache.put(library.getName(), new WeakReference<>(library));
        } catch (ParseException ex) {
            Logger.getLogger(LibraryProvider.class.getName()).log(Level.INFO, null, ex);
        }
    }
}
 
源代码17 项目: netbeans   文件: LibraryProvider.java
/**
 * Load the full data for the supplied library. All fields are populated,
 * including the {@code versions} property.
 *
 * @param libraryName
 * @return
 */
public Library loadLibrary(String libraryName) {
    Library cachedLibrary = getCachedLibrary(libraryName);
    if(cachedLibrary != null) {
        return cachedLibrary;
    }
    String data = readUrl(getLibraryDataUrl(libraryName));
    if (data != null) {
        try {
            JSONParser parser = new JSONParser();
            JSONObject libraryData = (JSONObject) parser.parse(data);
            Library library = createLibrary(libraryData);
            entryCache.put(library.getName(), new WeakReference<>(library));
            return library;
        } catch (ParseException ex) {
            Logger.getLogger(LibraryProvider.class.getName()).log(Level.INFO, null, ex);
        }
    }
    return null;
}
 
源代码18 项目: netbeans   文件: LibraryProvider.java
/**
 * Parses the given JSON result of the search.
 *
 * @param data search result.
 *
 * @return libraries returned in the search result.
 */
Library[] parse(String data) {
    Library[] libraries = null;
    try {
        JSONParser parser = new JSONParser();
        JSONObject searchResult = (JSONObject) parser.parse(data);
        JSONArray libraryArray = (JSONArray) searchResult.get(PROPERTY_RESULT);
        libraries = new Library[libraryArray.size()];
        for (int i = 0; i < libraries.length; i++) {
            JSONObject libraryData = (JSONObject) libraryArray.get(i);
            libraries[i] = createLibrary(libraryData);
        }
    } catch (ParseException pex) {
        Logger.getLogger(LibraryProvider.class.getName()).log(Level.INFO, null, pex);
    }
    return libraries;
}
 
源代码19 项目: netbeans   文件: ServerConnection.java
private void received(Listener listener, String tools, String message) throws ParseException, IOException {
    //System.out.println("RECEIVED: tools: '"+tools+"', message: '"+message+"'");
    fireReceived(message);
    LOG.log(Level.FINE, "RECEIVED: {0}, {1}", new Object[]{tools, message});
    if (message.isEmpty()) {
        return ;
    }
    JSONParser parser = new JSONParser();
    JSONObject obj = (JSONObject) parser.parse(message, containerFactory);
    V8Request request = JSONReader.getRequest(obj);
    ResponseProvider rp = listener.request(request);
    if (V8Command.Disconnect.equals(request.getCommand())) {
        try {
            closeCurrentConnection();
        } catch (IOException ioex) {}
    }
    if (rp != null) {
        rp.sendTo(this);
    }
}
 
public static JSONObject doExecuteJSONRequest(RemoteConnectorRequest request, RemoteConnectorService service) throws ParseException, IOException, AuthenticationException
{
    // Set as JSON
    request.setContentType(MimetypeMap.MIMETYPE_JSON);
    
    // Perform the request
    RemoteConnectorResponse response = service.executeRequest(request);
    
    // Parse this as JSON
    JSONParser parser = new JSONParser();
    String jsonText = response.getResponseBodyAsString();
    Object json = parser.parse(jsonText);
    
    // Check it's the right type and return
    if (json instanceof JSONObject)
    {
        return (JSONObject)json;
    }
    else
    {
        throw new ParseException(0, json);
    }
}
 
@Test
public void shouldReturnServerErrorAndReasonWhenMisconfigured() throws ParseException {
    ApiGatewayProxyRequest request = new ApiGatewayProxyRequestBuilder()
            .withHttpMethod(METHOD)
            .build();
    LambdaProxyHandler<Configuration> handlerWithFailingConguration = new TestLambdaProxyHandlerWithFailingConguration();
    handlerWithFailingConguration.registerMethodHandler(METHOD, c -> methodHandler);

    ApiGatewayProxyResponse actual = handlerWithFailingConguration.handleRequest(request, context);

    assertThat(actual).isNotNull();
    assertThat(actual.getStatusCode()).isEqualTo(INTERNAL_SERVER_ERROR.getStatusCode());
    JSONParser jsonParser = new JSONParser();
    JSONObject jsonObject = (JSONObject) jsonParser.parse(actual.getBody());
    assertThat(jsonObject.keySet()).contains("message", "cause");
    assertThat((String) jsonObject.get("message")).contains("This service is mis-configured. Please contact your system administrator.");
    assertThat((String) jsonObject.get("cause")).contains("NullPointerException");
}
 
源代码22 项目: cellery-security   文件: CellStsUtils.java
public static void readUnsecuredContexts() throws CelleryCellSTSException {

        String configFilePath = CellStsUtils.getUnsecuredPathsConfigPath();
        String content = null;
        try {
            content = new String(Files.readAllBytes(Paths.get(configFilePath)), StandardCharsets.UTF_8);
            JSONArray config = (JSONArray) new JSONParser().parse(content);
            List unsecuredContexts = config.subList(0, config.size());
            CellStsConfiguration.getInstance().setUnsecuredAPIS(unsecuredContexts);
        } catch (IOException | ParseException e) {
            throw new CelleryCellSTSException("Error while reading unsecured contexts from config file", e);
        }
    }
 
源代码23 项目: Explvs-AIO   文件: VersionChecker.java
private static Optional<JSONObject> getLatestGitHubReleaseJSON() {
    try {
        URL url = new URL(GITHUB_API_LATEST_RELEASE_URL);
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setRequestMethod("GET");

        try (InputStreamReader inputStreamReader = new InputStreamReader(con.getInputStream());
             BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
            return Optional.of((JSONObject) (new JSONParser().parse(bufferedReader)));
        }
    } catch (IOException | ParseException e) {
        e.printStackTrace();
    }
    return Optional.empty();
}
 
源代码24 项目: Explvs-AIO   文件: ItemGuide.java
public static Map<String, Integer> getAllGEItems() {
    if (allGEItems.isEmpty()) {

        File summaryFile = Paths.get(System.getProperty("user.home"), "OSBot", "Data", "explv_aio_rsbuddy_summary.json").toFile();

        try {
            if (!summaryFile.exists()) {
                System.out.println("Downloading summary JSON from RSBuddy");
                URL website = new URL("https://rsbuddy.com/exchange/summary.json");
                ReadableByteChannel rbc = Channels.newChannel(website.openStream());
                FileOutputStream fos = new FileOutputStream(summaryFile);
                fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
            }

            try (FileReader fileReader = new FileReader(summaryFile)) {
                JSONObject jsonObject = (JSONObject) (new JSONParser().parse(fileReader));
                for (Object value : jsonObject.values()) {
                    JSONObject item = (JSONObject) value;
                    allGEItems.put((String) item.get("name"), new Long((long) item.get("id")).intValue());
                }
            }
        } catch (IOException | ParseException e) {
            e.printStackTrace();
        }
    }
    return allGEItems;
}
 
源代码25 项目: Explvs-AIO   文件: OSRSPriceGuide.java
public static Optional<Integer> getPrice(final int itemID) {
    try {
        URL url = new URL("http://services.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=" + itemID);
        URLConnection con = url.openConnection();
        con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");

        try (InputStreamReader inputStreamReader = new InputStreamReader(con.getInputStream());
             BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
            JSONParser jsonParser = new JSONParser();
            JSONObject json = (JSONObject) jsonParser.parse(bufferedReader);

            JSONObject itemJSON = (JSONObject) json.get("item");
            JSONObject currentPriceData = (JSONObject) itemJSON.get("current");

            Object currentPriceObj = currentPriceData.get("price");

            int currentPrice;

            if (currentPriceObj instanceof String) {
                currentPrice = parsePriceStr((String) currentPriceData.get("price"));
            } else if (currentPriceObj instanceof Long) {
                currentPrice = ((Long) currentPriceObj).intValue();
            } else {
                currentPrice = (int) currentPriceObj;
            }

            return Optional.of(currentPrice);
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Failed to get price from RuneScape api");
    }
    return Optional.empty();
}
 
源代码26 项目: Explvs-AIO   文件: ConfigManager.java
public Optional<JSONObject> readConfig(final File file) {
    if (!file.exists()) {
        return Optional.empty();
    }
    try (FileReader fileReader = new FileReader(file)) {
        JSONObject jsonObject = (JSONObject) (new JSONParser().parse(fileReader));
        return Optional.of(jsonObject);
    } catch (IOException | ParseException e) {
        e.printStackTrace();
    }
    return Optional.empty();
}
 
源代码27 项目: soltix   文件: ProfilingLogRecording.java
public void loadEventLog(String path) throws Exception {
    BufferedReader br = new BufferedReader(new FileReader(path));
    String line;

    recordedResultList = new ArrayList<ProfilingEvent>();
    while ((line = br.readLine()) != null) {
        JSONParser jsonParser = new JSONParser();
        JSONObject jsonObject = (JSONObject)jsonParser.parse(line);

        ProfilingEvent event = ProfilingEvent.fromJSON(ast, jsonObject);
        if (event == null) {
            continue;
        }

        recordedResultList.add(event);

        if (!event.getIsOrdinaryUserEvent()) {
            /*
            // A log for multiple contracts must be allowed at least for inter-contract
            // calls
            if (contract != null) {
                if (contract != event.getContract()) {
                    throw new Exception("Event log contains events from more than one contract");
                }
            } else*/ {
                contract = event.getContract();
                // Infer the containing function of this first event as well
                firstEventFunction = ast.getFunctionByStatementId(event.getStatementID());
            }
        }
    }
    currentReplayIndex = 0;

    // Finalize environment variables
    for (ProfilingEvent eventData : recordedResultList) {
        if (eventData.getStatement() != null) {
            eventData.getStatement().getVariableEnvironment().finishAddingValues();
        }
    }
}
 
源代码28 项目: singleton   文件: JSONUtils.java
/**
 * Convert Json string to Map<String, Object>
 * 
 * @param json
 * @return Map<String, Object> obj
 */
@SuppressWarnings("unchecked")
public static Map<String, Object> getMapFromJson(String json) {
	JSONParser parser = new JSONParser();
	ContainerFactory containerFactory = getContainerFactory();
	Map<String, Object> result = null;
	if (!StringUtils.isEmpty(json)) {
		try {
			result = (Map<String, Object>) parser.parse(json, containerFactory);
		} catch (ParseException e) {
			logger.error(e.getMessage(), e);
		}
	}
	return result;
}
 
源代码29 项目: SZZUnleashed   文件: GitParser.java
/**
 * Use this method to use already found big fixing changes.
 *
 * @param path the path to the json file where the changes are stored.
 */
public Set<RevCommit> readBugFixCommits(String path) throws IOException, GitAPIException {
  if (repo == null) return Collections.emptySet();

  this.issues = new Issues();

  JSONParser commitParser = new JSONParser();
  try {
    JSONObject object = (JSONObject) commitParser.parse(new FileReader(path));

    this.issues.revisions = new HashSet<>();
    this.issues.dates = new HashMap<>();

    for (Object issue : object.keySet()) {
      Map<String, String> issueInfo = (Map<String, String>) object.get(issue);

      String rev = issueInfo.get("hash");
      RevCommit revCommit = this.repo.parseCommit(this.repo.resolve(rev));

      Map<String, String> dates = new HashMap<>();

      dates.put("resolutiondate", issueInfo.get("resolutiondate"));
      dates.put("commitdate", issueInfo.get("commitdate"));
      dates.put("creationdate", issueInfo.get("creationdate"));

      this.issues.dates.put(rev, dates);
      this.issues.revisions.add(revCommit);
    }

  } catch (FileNotFoundException | ParseException e) {
    return Collections.emptySet();
  }

  this.logger.info(String.format("Found %d number of commits.", this.issues.revisions.size()));

  if (this.issues.revisions.size() == 0) return Collections.emptySet();
  return this.issues.revisions;
}
 
源代码30 项目: BPR   文件: DatasetUtil.java
/**
 * Convert the original Yelp Challenge datasets into .raw file for lexicon construction.
 * The .raw data is used by the tool thuir-sentires.jar.
 * The format is <DOC>review_text</DOC>
 * @param inputfileDir
 * @param dataset
 * @throws IOException
 * @throws ParseException
 * @throws java.text.ParseException
 */
public void ConvertJsonToRawFile(String inputfileDir, String dataset) throws IOException, ParseException, java.text.ParseException {
	String inputfileName = inputfileDir + dataset + ".json";
	String outputfileName = inputfileDir + dataset + ".raw";
	System.out.println("\nConverting to .raw file: " + inputfileName);
	
	reader = new BufferedReader(new InputStreamReader(new FileInputStream(inputfileName)));
	PrintWriter writer = new PrintWriter (new FileOutputStream(outputfileName));
	
	String line;
	JSONParser parser=new JSONParser();
	int count = 0;
	while ((line = reader.readLine()) != null) {
		JSONObject obj = (JSONObject) parser.parse(line);
		// Parse review words.
		String review = (String) obj.get("text");
		// Output to the .raw file.
		writer.println("<DOC>");
		writer.println(review);
		writer.println("</DOC>");
		if (count++ % 10000 == 0)
			System.out.print(".");
	}
	
	System.out.println("\nGenerated .raw file" + outputfileName);
	reader.close();
	writer.close();
}