/** * Converts an URI into a file and returns it as absolute pathname. * * @param uri e.g. URI("file:/tmp") * * @return e.g. "/tmp" */ public static String toAbsolutePath(final URI uri) { File file = toFile(uri); return file.getAbsolutePath(); }
/** * Converts an URI into a file and returns it as absolute pathname. * * @param uri * e.g. URI("file:/tmp") * * @return e.g. "/tmp" */ public static String toAbsolutePath(final URI uri) { File file = toFile(uri); return file.getAbsolutePath(); }
/** * Converts an URI into a file. * * @param uri * the uri as string * @return the file */ public static File toFile(final String uri) { try { return toFile(new URI(uri)); } catch (URISyntaxException ex) { LOG.trace("'{}' will be handled as file name:", uri, ex); return new File(uri); } }
/** * Which resource jar. * * @param resource the resource * * @return the jar file */ public static JarFile whichResourceJar(final URI resource) { if (resource == null) { return null; } File file = Converter.toFile(resource); try { return new JarFile(file); } catch (IOException ioe) { log.debug("can't read " + file, ioe); return null; } }
/** * Which resource jar. * * @param resource * the resource * * @return the jar file */ public static JarFile whichResourceJar(final URI resource) { if (resource == null) { return null; } File file = Converter.toFile(resource); try { return new JarFile(file); } catch (IOException ioe) { LOG.debug("Cannot read " + file + ":", ioe); return null; } }
private static byte[] readJar(final URI uri) throws IOException { File file = Converter.toFile(StringUtils.substringBefore(uri.toString(), "!")); String classpath = StringUtils.substringAfterLast(uri.toString(), "!"); JarFile jarFile = new JarFile(file); JarEntry entry = getEntry(classpath, jarFile); InputStream istream = jarFile.getInputStream(entry); try { return IOUtils.toByteArray(istream); } finally { istream.close(); } }
private void initArchiv() { if (uri.getScheme().equalsIgnoreCase("file")) { this.archiv = new File(uri); this.entry = null; } else { String name = uri.toString().substring(4); int n = name.lastIndexOf("!"); try { URI fileURI = new URI(name.substring(0, n)); this.archiv = Converter.toFile(fileURI); } catch (URISyntaxException e) { this.archiv = new File(name.substring(5, n)); } this.entry = name.substring(n+1); if (this.entry.charAt(0) == '/') { this.entry = this.entry.substring(1); } } }
/** * Gets the modification date of the resource. * * @return the modification date * @throws IOException * Signals that an I/O exception has occurred. */ public Date getModificationDate() throws IOException { String scheme = this.uri.getScheme(); if ("file".equalsIgnoreCase(scheme)) { File file = new File(this.uri); return new Date(file.lastModified()); } else if ("jar".equalsIgnoreCase(scheme)) { return getModificationTimeOf(Converter.toFile(this.uri)); } else { LOG.warn("Will return {} as Date for unsupported scheme '{}'.", new Date(0L), scheme); return new Date(0L); } }
try { String fileScheme = uri.toString().substring(4); return toFile(new URI(fileScheme)); } catch (URISyntaxException e) { throw new IllegalArgumentException("not a File: " + uri, e);
/** * Converts an URI into a file. * * @param uri * e.g. URI("file:/tmp") * * @return e.g. File("/tmp") */ public static File toFile(final URI uri) { try { return toCanonicalFile(uri); } catch (IllegalArgumentException iae) { if ("jar".equalsIgnoreCase(uri.getScheme())) { try { String fileScheme = uri.toString().substring(4); return toFile(new URI(fileScheme)); } catch (URISyntaxException ex) { LOG.trace("Cannot convert '{}' to a file:", uri, ex); throw new IllegalArgumentException("not a File: " + uri, iae); } } } String path = uri.getPath(); if (StringUtils.isEmpty(path)) { path = StringUtils.substringAfterLast(uri.toString(), ":"); } return new File(path); }
throw new IllegalArgumentException(classname + " not found in classpath"); File path = Converter.toFile(classpath); return getManifestEntries(path);
throw new IllegalArgumentException(classname + " not found in classpath"); File path = Converter.toFile(classpathURI); return getManifestEntries(path);