private JarJarURLConnection(URL url) throws IOException { super(url); final String file = url.getFile(); URL inner = new URL(file); // this is same as // connection = inner.openConnection() // we just cache the connection in URLJarCollector // because we need to be able to close it to release jar files connection = URLJarCollector.openConnection(inner); }
public static synchronized URLConnection openConnection(URL url) throws IOException { // Logger.logMessage("Open connection to URL: " + url); final URLConnection urlConnection = url.openConnection(); if (sunJVM) { registerConnection(urlConnection); urlConnection.setUseCaches(true); } else { urlConnection.setUseCaches(false); } return urlConnection; }
URLJarCollector.closeJarURLConnection(jar.toURI().toURL()); } catch (MalformedURLException e) { Logger.logError(e); URLJarCollector.gc();
public void refresh(String friendlyUrl) { if (!updateItemRoot(friendlyUrl, true)) { refresh(true); } URLJarCollector.gc(); }
protected void initializeBattle() { URLJarCollector.enableGc(false); roundNum = 0; totalTurns = 0; // Notify that the battle is now running synchronized (isRunning) { isRunning.set(true); isRunning.notifyAll(); } }
public static synchronized void gc() { if (sunJVM) { // Close all JarURLConnections if garbage collection is enabled if (enabled) { synchronized (urlsToClean) { for (URL url : urlsToClean) { closeJarURLConnection(url); } urlsToClean.clear(); } } // Bug fix [2867326] - Lockup on start if too many bots in robots dir (cont'd). // Remove all cache entries to temporary jar cache files created // for connections using the jarjar protocol that get stuck up. for (Iterator<?> it = fileCache.keySet().iterator(); it.hasNext();) { Object urlJarFile = it.next(); final JarFile jarFile = (JarFile) fileCache.get(urlJarFile); String filename = jarFile.getName(); filename = filename.substring(filename.lastIndexOf(File.separatorChar) + 1).toLowerCase(); if (filename.startsWith("jar_cache")) { it.remove(); synchronized (urlCache) { urlCache.remove(jarFile); } } } } }
public boolean refresh(boolean force) { boolean refreshed = update(getRobotsDirectory(), getDevelDirectories(), force); if (refreshed) { setStatus("Saving robot database"); save(); } setStatus(""); URLJarCollector.gc(); return refreshed; }
public void reload(boolean rebuild) { // Bug fix [2867326] - Lockup on start if too many bots in robots dir (cont'd). URLJarCollector.enableGc(true); URLJarCollector.gc(); if (rebuild) { Logger.logMessage("Rebuilding robot database..."); repository = new Repository(); } else if (repository == null) { setStatus("Reading robot database"); repository = load(); if (repository == null) { setStatus("Building robot database"); repository = new Repository(); } } refresh(true); setStatus(""); }
private void htmlURLFromPropertiesURL() { try { htmlURL = new URL(itemUrl.toString().replaceAll("\\.team", ".html")); // test that html file exists final URLConnection conn = URLJarCollector.openConnection(htmlURL); conn.getInputStream().close(); } catch (IOException ignored) { // doesn't exist htmlURL = null; } }
private boolean isInvalidURL(URL url) { if (url != null) { InputStream is = null; try { URLConnection conn = URLJarCollector.openConnection(url); is = conn.getInputStream(); return false; } catch (IOException e) { return true; } finally { FileUtil.cleanupStream(is); } } return true; }
private boolean loadProperties() { if (!isPropertiesLoaded && propertiesURL != null) { InputStream ios = null; try { URLConnection con = URLJarCollector.openConnection(propertiesURL); ios = con.getInputStream(); properties.load(ios); isPropertiesLoaded = true; return true; } catch (IOException e) { return false; } finally { FileUtil.cleanupStream(ios); } } return false; }
private boolean loadProperties() { if (itemUrl != null) { InputStream ios = null; try { final URLConnection connection = URLJarCollector.openConnection(itemUrl); ios = connection.getInputStream(); properties.load(ios); return true; } catch (IOException e) { Logger.logError(e); } finally { FileUtil.cleanupStream(ios); } } return false; }
private void visitItems(List<IRepositoryItem> repositoryItems) { String root = jarPath; InputStream is = null; BufferedInputStream bis = null; JarInputStream jarIS = null; try { URLConnection con = URLJarCollector.openConnection(rootURL); is = con.getInputStream(); bis = new BufferedInputStream(is); jarIS = new JarInputStream(bis); readJarStream(repositoryItems, root, jarIS); } catch (Exception e) { Logger.logError(rootURL + " is probably corrupted (" + e.getClass().getName() + " " + e.getMessage() + ")"); } finally { FileUtil.cleanupStream(jarIS); FileUtil.cleanupStream(bis); FileUtil.cleanupStream(is); } }
URLConnection connection = URLJarCollector.openConnection(url);
public static void extractJar(URL url) { File dest = FileUtil.getRobotsDir(); InputStream is = null; BufferedInputStream bis = null; JarInputStream jarIS = null; try { final URLConnection con = URLJarCollector.openConnection(url); is = con.getInputStream(); bis = new BufferedInputStream(is); jarIS = new JarInputStream(bis); JarEntry entry = jarIS.getNextJarEntry(); while (entry != null) { if (entry.isDirectory()) { File dir = new File(dest, entry.getName()); if (!dir.exists() && !dir.mkdirs()) { Logger.logError("Cannot create dir: " + dir); } } else { extractFile(dest, jarIS, entry); } entry = jarIS.getNextJarEntry(); } } catch (IOException e) { Logger.logError(e); } finally { FileUtil.cleanupStream(jarIS); FileUtil.cleanupStream(bis); FileUtil.cleanupStream(is); } }