Changeset 31337
- Timestamp:
- 2017-01-23T21:24:31+13:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/hathitrust/wcsa/vol-checker/src/org/hathitrust/extractedfeatures/VolumeCheck.java
r31336 r31337 2 2 3 3 import java.io.BufferedInputStream; 4 import java.io.BufferedOutputStream; 4 5 import java.io.BufferedReader; 6 import java.io.FileInputStream; 5 7 import java.io.FileReader; 6 8 import java.io.IOException; 7 9 import java.io.InputStream; 8 10 import java.io.InputStreamReader; 11 import java.io.OutputStream; 9 12 import java.io.PrintWriter; 10 13 import java.io.UnsupportedEncodingException; 14 import java.nio.file.Files; 15 import java.nio.file.Path; 16 import java.nio.file.Paths; 11 17 import java.util.ArrayList; 12 18 import java.util.HashMap; … … 28 34 protected static int HASHMAP_INIT_SIZE = 13800000; 29 35 protected static HashMap<String,Boolean> id_check_ = null; 30 31 public VolumeCheck() {32 33 }34 36 35 37 protected static final String file_ext = ".json.bz2"; 38 39 public VolumeCheck() 40 {} 36 41 37 42 protected static String full_filename_to_tail(String full_filename) … … 148 153 } 149 154 150 protected voiddoRsyncDownload(String full_json_filename)155 protected BufferedInputStream doRsyncDownload(String full_json_filename) 151 156 { 152 157 String json_filename_tail = full_filename_to_tail(full_json_filename); 153 //String cmd = "rsync -av data.analytics.hathitrust.org::features/" + full_json_filename + "."; 154 155 156 Runtime rt = Runtime.getRuntime(); 157 String[] command = {"rsync","-av","data.analytics.hathitrust.org::features/" + full_json_filename, "."}; 158 158 159 BufferedInputStream bis = null; 160 161 Runtime runtime = Runtime.getRuntime(); 162 String[] rsync_command = {"rsync","-av","data.analytics.hathitrust.org::features/" + full_json_filename, "."}; 159 163 160 164 try { 161 Process proc = rt.exec(command); 162 165 Process proc = runtime.exec(rsync_command); 166 proc.waitFor(); 167 System.err.println("*** Rsync finished"); 168 169 FileInputStream fis = new FileInputStream(json_filename_tail); 170 bis = new BufferedInputStream(fis); 171 172 //Path json_filename_path = Paths.get(json_filename_tail); 173 //byte[] bz_bytes = Files.readAllBytes(json_filename_path); 174 175 176 //response.setContentType("application/json"); 177 163 178 /* 164 179 BufferedReader stdInput = new BufferedReader(new … … 182 197 */ 183 198 184 proc.waitFor(); 185 System.err.println("*** Rsync finished"); 186 199 200 //return bz_bytes; 187 201 //System.out.println("Done."); 188 202 … … 191 205 e.printStackTrace(); 192 206 } 207 208 return bis; 193 209 194 210 } … … 197 213 */ 198 214 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 199 PrintWriter pw = response.getWriter();215 200 216 201 217 String cgi_ids = request.getParameter("ids"); … … 205 221 if (cgi_ids != null) { 206 222 response.setContentType("application/json"); 207 223 PrintWriter pw = response.getWriter(); 224 208 225 String[] ids = cgi_ids.split(","); 209 226 int ids_len = ids.length; … … 226 243 else if (cgi_id != null) { 227 244 response.setContentType("application/json"); 228 245 PrintWriter pw = response.getWriter(); 246 229 247 String id = cgi_id; 230 248 boolean exists = id_check_.get(id); … … 242 260 String full_json_filename = id_to_pairtree_filename(download_id); 243 261 244 doRsyncDownload(full_json_filename); 245 262 BufferedInputStream bis = doRsyncDownload(full_json_filename); 263 264 if (bis == null) { 265 response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Rsync failed"); 266 } 267 else { 268 String json_filename_tail = full_filename_to_tail(full_json_filename); 269 270 response.setContentType("application/x-bzip2"); 271 response.setHeader("Content-Disposition", "attachment; filename=\"" + json_filename_tail + "\""); 272 273 274 //InputStream is=request.getInputStream(); 275 OutputStream os=response.getOutputStream(); 276 BufferedOutputStream bos = new BufferedOutputStream(os); 277 278 byte[] buf = new byte[1024]; 279 280 //int num_bytes; 281 while (true) { 282 int num_bytes = bis.read(buf); 283 if (num_bytes == -1) { 284 break; 285 } 286 bos.write(buf,0,num_bytes); 287 } 288 /* 289 for (int nChunk = bis.read(buf); nChunk!=-1; nChunk = bis.read(buf)) 290 { 291 os.write(buf, 0, nChunk); 292 } 293 */ 294 295 //OutputStream os = response.getOutputStream() 296 297 //os.write(bz_bytes); 298 299 bis.close(); 300 } 246 301 } 247 302 } 248 303 else { 249 304 PrintWriter pw = response.getWriter(); 305 250 306 pw.append("General Info: Number of HTRC Volumes in check-list = " + id_check_.size()); 251 307
Note:
See TracChangeset
for help on using the changeset viewer.