Returns a {@code Runnable} that will remove the file system with the given {@code URI} from the
system provider's cache when called.
334141
private static Runnable removeFileSystemRunnable(URI uri) {
    if (Jimfs.systemProvider == null) {
      // TODO(cgdecker): Use Runnables.doNothing() when it's out of @Beta
      return DO_NOTHING;
    }

    // We have to invoke the SystemJimfsFileSystemProvider.removeFileSystemRunnable(URI)
    // method reflectively since the system-loaded instance of it may be a different class
    // than the one we'd get if we tried to cast it and call it like normal here.
    try {
      Method method =
          Jimfs.systemProvider.getClass().getDeclaredMethod("removeFileSystemRunnable", URI.class);
      return (Runnable) method.invoke(null, uri);
    } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
      throw new RuntimeException(
          "Unable to get Runnable for removing the FileSystem from the cache when it is closed", e);
    }
  }
1046330
@Deprecated
  public static Parser<?> runnable(final Runnable runnable) {
    return new Parser<Object>() {      
      @Override boolean apply(ParseContext ctxt) {
        runnable.run();
        return true;
      }
      
      @Override public String toString() {
        return runnable.toString();
      }
    };
  }
166959
public static URI removeServer(URI uri) {
        try {
            return new URI(null, null, null, -1, uri.getPath(), uri.getQuery(), uri.getFragment());
        } catch (URISyntaxException e) {
            throw new InvalidUriException(e);
        }

    }
803183
@Override
	public InputStream getInputStream(final String key, final URI source, final MutableInt retLength)
			throws IOException {
		final String sourceMethod = "getInputStream"; //$NON-NLS-1$
		final boolean isTraceLogging = log.isLoggable(Level.FINER);
		if (isTraceLogging) {
			log.entering(sourceClass, sourceMethod, new Object[] { key, source, retLength });
		}

		InputStream in = null, result = null;
		CacheEntry tryCacheEntry = (CacheEntry) super.get(key);
		URLConnection connection = source.toURL().openConnection();

		try {
			long lastModified = connection.getLastModified();
			if (tryCacheEntry != null) {
				// Make local copies of volatile CacheEntry fields
				byte[] bytes = tryCacheEntry.bytes;
				File file = tryCacheEntry.file;
				if (bytes != null) {
					// Important - CacheEntry.lastModified is set before CacheEntry.bytes so we can
					// safely
					// check CacheEntry.lastModified here even though we're not synchronized.
					if (lastModified != tryCacheEntry.lastModified) {
						// stale cache entry. Remove it and create a new one below
						cacheMap.remove(key, tryCacheEntry);
					} else {
						retLength.setValue(tryCacheEntry.bytes.length);
						result = new ByteArrayInputStream(tryCacheEntry.bytes);
					}
				} else if (file != null) {
					// Some platforms round file last modified times to nearest second.
					if (Math.abs(lastModified - file.lastModified()) > 1000) {
						// Stale cache entry, remove it and create a new one below
						cacheMap.remove(key, tryCacheEntry);
						// also delete the associated cache file asynchronously.
						cacheManager.deleteFileDelayed(file.getName());
					} else {
						try {
							retLength.setValue(file.length());
							result = new FileInputStream(file);
						} catch (FileNotFoundException ex) {
							// File doesn't exist (was probably deleted outside this program)
							// Not fatal, just fall through and create it again.
							cacheMap.remove(key, tryCacheEntry);
						}
					}
				}
				if (result != null) {
					// found result in cache. Return it.
					log.exiting(sourceClass, sourceMethod, result);
					return result;
				}
			}

			// Result not in cache (or we removed it). Try to create a new cache entry.
			CacheEntry newCacheEntry = new CacheEntry();
			CacheEntry oldCacheEntry = (CacheEntry) cacheMap.putIfAbsent(key, newCacheEntry);
			final CacheEntry cacheEntry = oldCacheEntry != null ? oldCacheEntry : newCacheEntry;

			// Synchronize on the cache entry so that more than one thread won't try to create the
			// zipped content.
			synchronized (cacheEntry) {
				if (cacheEntry.ex != null) {
					// An exception occurred trying to create the gzip response in another thread.
					// Re-throw the exception here.
					throw cacheEntry.ex;
				}
				// First, check to make sure that another thread didn't beat us to the punch.
				// Even though we're synchronized on the cacheEntry object, cacheEntry.bytes can be
				// cleared by the createCacheFileAsync callback, so we need to copy this volatile
				// field
				// to a local variable and access it from there.
				byte[] bytes = cacheEntry.bytes;
				if (bytes != null) {
					retLength.setValue(bytes.length);
					result = new ByteArrayInputStream(bytes);
				} else if (cacheEntry.file != null) { // once set, cacheEntry.file does not change
														// by convention
					retLength.setValue(cacheEntry.file.length());
					result = new FileInputStream(cacheEntry.file);
				} else {
					// Gzip encode the resource and save the result in the cache entry until the
					// cache
					// file is written asynchronously.
					try {
						in = connection.getInputStream();
						ByteArrayOutputStream bos = new ByteArrayOutputStream();
						VariableGZIPOutputStream compress = new VariableGZIPOutputStream(bos, 10240);
						compress.setLevel(Deflater.BEST_COMPRESSION);
						CopyUtil.copy(in, compress);

						// Important - CacheEntry.lastModified must be set before cacheEntry.bytes
						cacheEntry.lastModified = lastModified;
						cacheEntry.bytes = bos.toByteArray();
						result = new ByteArrayInputStream(cacheEntry.bytes);
						retLength.setValue(cacheEntry.bytes.length);

						// Call the cache manager to asynchronously save the gzipped response to
						// disk
						// Include the filename part of the source URI in the cached filename
						String path = source.getPath();
						int idx = path.lastIndexOf("/"); //$NON-NLS-1$
						String fname = (idx != -1) ? path.substring(idx + 1) : path;
						cacheManager.createCacheFileAsync(
								fname + ".gzip.", //$NON-NLS-1$
								new ByteArrayInputStream(cacheEntry.bytes),
								new ICacheManager.CreateCompletionCallback() {
									@Override
									public void completed(String filename, Exception e) {
										if (e != null && log.isLoggable(Level.SEVERE)) {
											// Exception occurred saving file. Not much we can do
											// except log the error
											log.logp(Level.SEVERE, sourceClass, sourceMethod,
													e.getMessage(), e);
											return;
										}
										File cacheFile = new File(cacheManager.getCacheDir(),
												filename);
										cacheFile.setLastModified(cacheEntry.lastModified);
										// Important - cacheEntry.file must be set before clearing
										// cacheEntry.bytes
										cacheEntry.file = cacheFile;
										cacheEntry.bytes = null;
									}
								});
					} catch (Throwable t) {
						cacheEntry.ex = (t instanceof IOException) ? (IOException) t
								: new IOException(t);
						cacheMap.remove(key, cacheEntry);
						throw cacheEntry.ex;
					}
				}
			}
		} finally {
			// URLConnection doesn't have a close method. The only way to make sure a connection is
			// closed is to close the input or output stream which is obtained from the connection.
			if (in != null) {
				in.close();
			} else {
				connection.getInputStream().close();
			}
		}
		if (isTraceLogging) {
			log.exiting(sourceClass, sourceClass, result);
		}
		return result;
	}
1287408
public Object run(URI source, String[] args) throws CompilationFailedException, IOException {
        return run(new GroovyCodeSource(source), args);
    }
610205
@SuppressWarnings("unchecked")
  public final E remove()
  {
    Thread thread = Thread.currentThread();
    ClassLoader loader = thread.getContextClassLoader();

    for (; loader != null; loader = loader.getParent()) {
      if (loader instanceof EnvironmentClassLoader) {
        EnvironmentClassLoader envLoader = (EnvironmentClassLoader) loader;

        return (E) envLoader.removeAttribute(_varName);
      }
    }

    return setGlobal(null);
  }
856147
public void removeFromCache(Set<String> rootPaths, boolean online) {

        Map<String, Boolean> cache;
        if (online) {
            cache = m_onlineJsps;
        } else {
            cache = m_offlineJsps;
        }
        Iterator<String> itRemove = rootPaths.iterator();
        while (itRemove.hasNext()) {
            String rootPath = itRemove.next();
            cache.remove(rootPath);
        }
    }
1195219
public <T> Future<?> removeDataFromCache(final Class<T> clazz, final Object cacheKey) {
        if (clazz == null || cacheKey == null) {
            throw new IllegalArgumentException("Both parameters must be non null.");
        }

        return executeCommand(new RemoveDataFromCacheCommand(this, clazz, cacheKey));
    }
872887
public ServerListenerBuilder addStartedCallback(Runnable runnable) {
        requireNonNull(runnable, "runnable");
        serverStartedCallbacks.add(unused -> runnable.run());
        return this;
    }
353666
static Path uncCompatibleUriToPath(URI uri) {
		String in = uri.toString();
		Matcher m = UNC_URI_PATTERN.matcher(in);
		if (m.find() && (m.group(1) != null || m.group(2) != null)) { // this is an UNC path!
			String out = in.substring("file:".length()).replace('/', '\\');
			return Paths.get(out);
		} else {
			return Paths.get(uri);
		}
	}
214201
@SuppressWarnings("unchecked")
    public static <T> T connectCache(Runnable runnable, Object cachedValue) {
        THREAD_LOCAL.set(Optional.fromNullable(cachedValue));
        @Cleanup QuietCloseable i = () -> THREAD_LOCAL.remove();

        runnable.run();
        return (T) THREAD_LOCAL.get().orNull();
    }
1246400
@Nonnull
  public final UnifiedResponse removeCaching ()
  {
    // Remove any eventually set headers
    removeExpires ();
    removeCacheControl ();
    removeETag ();
    removeLastModified ();
    m_aResponseHeaderMap.removeHeaders (CHttpHeader.PRAGMA);
    return this;
  }
1153108
@SuppressWarnings("squid:S2221")
    public <T> T runAsSystem(final Callable<T> callable) {
        return runAsSystemAsTenant(callable, tenantAware.getCurrentTenant());
    }
962514
public void delete(URI src) {
    Path dst = null;
    try {
      dst = paths.get(src);
    } catch (ExecutionException e) {
      throw new RuntimeException(e);
    }
    try {
      Files.deleteIfExists(dst);
      paths.invalidate(src);
    } catch (IOException e) {
      String msg = String.format("Failed to delete %s -> %s", src, dst);
      LOG.error(msg, e);
    }
  }
218547
public <T extends Runnable> T executeSync(T runnable) {
		synchronized (runnable) {
			this.executeAsync(runnable);
			try {
				runnable.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

		return runnable;
	}
767428
public static Optional<Long> timedRun(Runnable runnable) {
    long t0 = System.currentTimeMillis();
    runnable.run();
    return Optional.of(System.currentTimeMillis() - t0);
  }
1077749
public <Result, Param extends Resource> Result execWithoutCacheClear(Param resource, IUnitOfWork<Result, Param> transaction) throws WrappedException {
		CacheAdapter cacheAdapter = getOrCreate(resource);
		try {
			cacheAdapter.ignoreNotifications();
			return transaction.exec(resource);
		} catch (RuntimeException e) {
			throw e;
		} catch (Exception e) {
			throw new WrappedException(e);
		} finally {
			cacheAdapter.listenToNotifications();
		}
	}