source: other-projects/hathitrust/wcsa/extracted-features-solr/trunk/solr-ingest/src/main/java/org/hathitrust/extractedfeatures/JSONClusterFileIO.java@ 31226

Last change on this file since 31226 was 31089, checked in by davidb, 7 years ago

Change in way the JSON file is read in. Motivation was a out-of-memory error, but now looks like it might not have been needed. That said, the JSON files are all done as single lines, so reading in the file constantly checking for a new-line char that will never appear is probably about the same as the new explicity character by character one

  • Property svn:executable set to *
File size: 782 bytes
Line 
1package org.hathitrust.extractedfeatures;
2
3import java.io.BufferedReader;
4
5import org.json.JSONObject;
6
7public class JSONClusterFileIO extends ClusterFileIO {
8
9 protected static JSONObject readJSONFile(String filename)
10 {
11 JSONObject json_obj = null;
12
13 try {
14 StringBuilder sb = new StringBuilder();
15
16 String str;
17 BufferedReader br = ClusterFileIO.getBufferedReaderForCompressedFile(filename);
18
19 int cp;
20 while ((cp = br.read()) != -1) {
21 sb.append((char) cp);
22 }
23
24 /*
25 while ((str = br.readLine()) != null) {
26 sb.append(str);
27 }
28 */
29
30 br.close();
31
32 json_obj = new JSONObject(sb.toString());
33 }
34 catch (Exception e) {
35 e.printStackTrace();
36 }
37
38 return json_obj;
39 }
40
41}
Note: See TracBrowser for help on using the repository browser.