316 } 317 318 private RepositoryCatalog catalog() 319 throws IOException 320 { 321 if (!catFile.exists()) 322 throw new IOException("No catalog yet"); 323 if (cat == null) 324 cat = RepositoryCatalog.load(new FileInputStream(catFile)); 325 return cat; 326 } 327 328 @Override 329 protected void gatherLocalModuleIds(String moduleName, 330 Set<ModuleId> mids) 331 throws IOException 332 { 333 catalog().gatherModuleIds(moduleName, mids); 334 } 335 336 @Override 337 protected void gatherLocalDeclaringModuleIds(Set<ModuleId> mids) 338 throws IOException 339 { 340 catalog().gatherDeclaringModuleIds(mids); 341 } 342 343 @Override 344 protected ModuleInfo readLocalModuleInfo(ModuleId mid) 345 throws IOException 346 { 347 byte[] bs = catalog().readModuleInfoBytes(mid); 348 return jms.parseModuleInfo(bs); 349 } 350 351 @Override 352 public InputStream fetch(ModuleId mid) throws IOException { 353 ModuleMetaData mmd = fetchMetaData(mid); 354 URI u = uri.resolve(mid.toString() + mmd.getType().getFileNameSuffix()); 355 if (tracing) 356 trace(1, "fetching module %s", u); 357 358 // special case file protocol for faster access 359 if (u.getScheme().equalsIgnoreCase("file")) { 360 return Files.newInputStream(Paths.get(u)); 361 } else { 362 URLConnection uc = u.toURL().openConnection(); 363 if (uc instanceof HttpURLConnection) { 364 HttpURLConnection http = (HttpURLConnection)uc; 365 http.setInstanceFollowRedirects(true); 366 http.connect(); 367 int rc = http.getResponseCode(); 368 if (tracing) 369 trace(2, "response: %s", http.getResponseMessage()); 370 if (rc != HttpURLConnection.HTTP_OK) 371 throw new IOException(u + ": " + http.getResponseMessage()); 372 } 373 return uc.getInputStream(); 374 } 375 } 376 377 @Override 378 public ModuleMetaData fetchMetaData(ModuleId mid) throws IOException { 379 RepositoryCatalog.Entry e = catalog().get(mid); 380 if (e == null) 381 throw new IllegalArgumentException(mid.toString()); 382 return new ModuleMetaData(e.type, e.csize, e.usize); 383 } 384 385 386 /** 387 * Attempts to delete {@code f}. If the delete fails then the exception is 388 * added as a suppressed exception to the given exception. 389 */ 390 private static void deleteAfterException(File f, Exception x) { 391 try { 392 Files.deleteIfExists(f.toPath()); 393 } catch (IOException x2) { 394 x.addSuppressed(x2); 395 } 396 } 397 } | 316 } 317 318 private RepositoryCatalog catalog() 319 throws IOException 320 { 321 if (!catFile.exists()) 322 throw new IOException("No catalog yet"); 323 if (cat == null) 324 cat = RepositoryCatalog.load(new FileInputStream(catFile)); 325 return cat; 326 } 327 328 @Override 329 protected void gatherLocalModuleIds(String moduleName, 330 Set<ModuleId> mids) 331 throws IOException 332 { 333 catalog().gatherModuleIds(moduleName, mids); 334 } 335 336 /** 337 * Find all module views and aliases with the given name and module 338 * architecture in this catalog. 339 */ 340 public List<ModuleId> findlocalModuleIds(String moduleName, 341 ModuleArchitecture modArch) 342 throws IOException 343 { 344 Set<ModuleId> mids = new HashSet<>(); 345 gatherLocalModuleIds(moduleName, modArch, mids); 346 List<ModuleId> rv = new ArrayList<>(mids); 347 Collections.sort(rv); 348 return rv; 349 } 350 351 protected void gatherLocalModuleIds(String moduleName, 352 ModuleArchitecture modArch, 353 Set<ModuleId> mids) 354 throws IOException 355 { 356 catalog().gatherModuleIds(moduleName, modArch, mids); 357 } 358 359 @Override 360 protected void gatherLocalDeclaringModuleIds(Set<ModuleId> mids) 361 throws IOException 362 { 363 catalog().gatherDeclaringModuleIds(mids); 364 } 365 366 @Override 367 protected ModuleInfo readLocalModuleInfo(ModuleId mid) 368 throws IOException 369 { 370 byte[] bs = catalog().readModuleInfoBytes(mid); 371 return jms.parseModuleInfo(bs); 372 } 373 374 @Override 375 public InputStream fetch(ModuleId mid) throws IOException { 376 ModuleFileMetaData mfmd = fetchMetaData(mid); 377 URI u = uri.resolve(mid.toString() + mfmd.getType().getFileNameSuffix()); 378 if (tracing) 379 trace(1, "fetching module %s", u); 380 381 // special case file protocol for faster access 382 if (u.getScheme().equalsIgnoreCase("file")) { 383 return Files.newInputStream(Paths.get(u)); 384 } else { 385 URLConnection uc = u.toURL().openConnection(); 386 if (uc instanceof HttpURLConnection) { 387 HttpURLConnection http = (HttpURLConnection)uc; 388 http.setInstanceFollowRedirects(true); 389 http.connect(); 390 int rc = http.getResponseCode(); 391 if (tracing) 392 trace(2, "response: %s", http.getResponseMessage()); 393 if (rc != HttpURLConnection.HTTP_OK) 394 throw new IOException(u + ": " + http.getResponseMessage()); 395 } 396 return uc.getInputStream(); 397 } 398 } 399 400 @Override 401 public ModuleFileMetaData fetchMetaData(ModuleId mid) throws IOException { 402 RepositoryCatalog.Entry e = catalog().get(mid); 403 if (e == null) 404 throw new IllegalArgumentException(mid.toString()); 405 return new ModuleFileMetaData(e.type, e.modArch, e.csize, e.usize); 406 } 407 408 409 /** 410 * Attempts to delete {@code f}. If the delete fails then the exception is 411 * added as a suppressed exception to the given exception. 412 */ 413 private static void deleteAfterException(File f, Exception x) { 414 try { 415 Files.deleteIfExists(f.toPath()); 416 } catch (IOException x2) { 417 x.addSuppressed(x2); 418 } 419 } 420 } |