public static File toFile(final String classFileName, final URL url) { String path = url.getFile(); path = path.substring(0, path.length() - classFileName.length()); return new File(decode(path)); }
public static File toFile(final String classFileName, final URL url) { String path = url.getFile(); path = path.substring(0, path.length() - classFileName.length()); return new File(decode(path)); }
private static File jarLocation(final URL url, final String classFileName) throws MalformedURLException { if ("jar".equals(url.getProtocol())) { final String spec = url.getFile(); return new File(JarLocation.decode(new URL(spec.substring(0, spec.indexOf('!'))).getFile())); } else if ("file".equals(url.getProtocol())) { return JarLocation.toFile(classFileName, url); } return null; }
public static File toFile(URL url) { if ("jar".equals(url.getProtocol())) { try { String spec = url.getFile(); int separator = spec.indexOf('!'); /* * REMIND: we don't handle nested JAR URLs */ if (separator == -1) throw new MalformedURLException("no ! found in jar url spec:" + spec); return toFile(new URL(spec.substring(0, separator++))); } catch (MalformedURLException e) { throw new IllegalStateException(e); } } else if ("file".equals(url.getProtocol())) { return new File(decode(url.getFile())); } else { throw new IllegalArgumentException("Unsupported URL scheme: " + url.toExternalForm()); } }
public static File toFile(final URL url) { if ("jar".equals(url.getProtocol())) { try { final String spec = url.getFile(); int separator = spec.indexOf('!'); /* * REMIND: we don't handle nested JAR URLs */ if (separator == -1) { throw new MalformedURLException("no ! found in jar url spec:" + spec); } return toFile(new URL(spec.substring(0, separator++))); } catch (final MalformedURLException e) { throw new IllegalStateException(e); } } else if ("file".equals(url.getProtocol())) { String path = decode(url.getFile()); if (path.endsWith("!")) { path = path.substring(0, path.length() - 1); } return new File(path); } else { throw new IllegalArgumentException("Unsupported URL scheme: " + url.toExternalForm()); } }
public static File toFile(final URL url) { if ("jar".equals(url.getProtocol())) { try { final String spec = url.getFile(); int separator = spec.indexOf('!'); /* * REMIND: we don't handle nested JAR URLs */ if (separator == -1) { throw new MalformedURLException("no ! found in jar url spec:" + spec); } return toFile(new URL(spec.substring(0, separator++))); } catch (final MalformedURLException e) { throw new IllegalStateException(e); } } else if ("file".equals(url.getProtocol())) { String path = decode(url.getFile()); if (path.endsWith("!")) { path = path.substring(0, path.length() - 1); } return new File(path); } else { throw new IllegalArgumentException("Unsupported URL scheme: " + url.toExternalForm()); } }
public static File toFile(final URL url) { if ("jar".equals(url.getProtocol())) { try { final String spec = url.getFile(); int separator = spec.indexOf('!'); /* * REMIND: we don't handle nested JAR URLs */ if (separator == -1) { throw new MalformedURLException("no ! found in jar url spec:" + spec); } return toFile(new URL(spec.substring(0, separator++))); } catch (final MalformedURLException e) { throw new IllegalStateException(e); } } else if ("file".equals(url.getProtocol())) { String path = decode(url.getFile()); if (path.endsWith("!")) { path = path.substring(0, path.length() - 1); } return new File(path); } else { throw new IllegalArgumentException("Unsupported URL scheme: " + url.toExternalForm()); } }
public static File toFile(final URL url) { if ("jar".equals(url.getProtocol())) { try { final String spec = url.getFile(); int separator = spec.indexOf('!'); /* * REMIND: we don't handle nested JAR URLs */ if (separator == -1) { throw new MalformedURLException("no ! found in jar url spec:" + spec); } return toFile(new URL(spec.substring(0, separator++))); } catch (final MalformedURLException e) { throw new IllegalStateException(e); } } else if ("file".equals(url.getProtocol())) { String path = decode(url.getFile()); if (path.endsWith("!")) { path = path.substring(0, path.length() - 1); } return new File(path); } else { throw new IllegalArgumentException("Unsupported URL scheme: " + url.toExternalForm()); } }
public static File jarFromResource(final ClassLoader loader, final String resourceName) { try { URL url = loader.getResource(resourceName); if (url == null) { throw new IllegalStateException("classloader.getResource(classFileName) returned a null URL"); } if ("jar".equals(url.getProtocol())) { final String spec = url.getFile(); int separator = spec.indexOf('!'); /* * REMIND: we don't handle nested JAR URLs */ if (separator == -1) { throw new MalformedURLException("no ! found in jar url spec:" + spec); } url = new URL(spec.substring(0, separator++)); return new File(decode(url.getFile())); } else if ("file".equals(url.getProtocol())) { return toFile(resourceName, url); } else { throw new IllegalArgumentException("Unsupported URL scheme: " + url.toExternalForm()); } } catch (final RuntimeException e) { throw e; } catch (final Exception e) { throw new IllegalStateException(e); } }
return new File(decode(url.getFile()));