Note that there are some explanatory texts on larger screens.

plurals
  1. POReading data from an API
    primarykey
    data
    text
    <p>I have written a function to read some data from an external API. What my function does is , it calls that API while reading a file from the disk. I want to optimize my code for large size of a file (35000 records). Could you please suggest me on this. </p> <p>Following is my code. </p> <pre><code>public void readCSVFile() { try { br = new BufferedReader(new FileReader(getFileName())); while ((line = br.readLine()) != null) { String[] splitLine = line.split(cvsSplitBy); String campaign = splitLine[0]; String adGroup = splitLine[1]; String url = splitLine[2]; long searchCount = getSearchCount(url); StringBuilder sb = new StringBuilder(); sb.append(campaign + ","); sb.append(adGroup + ","); sb.append(searchCount + ","); writeToFile(sb, getNewFileName()); } } catch (Exception e) { e.printStackTrace(); } } private long getSearchCount(String url) { long recordCount = 0; try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet( "api.com/querysearch?q=" + url); getRequest.addHeader("accept", "application/json"); HttpResponse response = httpClient.execute(getRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } BufferedReader br = new BufferedReader(new InputStreamReader( (response.getEntity().getContent()))); String output; while ((output = br.readLine()) != null) { try { JSONObject json = (JSONObject) new JSONParser() .parse(output); JSONObject result = (JSONObject) json.get("result"); recordCount = (long) result.get("count"); System.out.println(url + "=" + recordCount); } catch (Exception e) { System.out.println(e.getMessage()); } } httpClient.getConnectionManager().shutdown(); } catch (Exception e) { e.getStackTrace(); } return recordCount; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload