/** * Return the registered URLHelper, constructed with the provided URL * @see #registerHelperClass(Class) * @param url * @return */ public static URLHelper getURLHelper(URL url) { try { return getURLHelper(urlHelperClass, url); } catch (Exception e) { return getURLHelper(defaultUrlHelperClass, url); } }
/** * Return the registered URLHelper, constructed with the provided URL * @see #registerHelperClass(Class) * @param url * @return */ public static URLHelper getURLHelper(URL url) { try { return getURLHelper(urlHelperClass, url); } catch (Exception e) { return getURLHelper(defaultUrlHelperClass, url); } }
/** * Return the registered URLHelper, constructed with the provided URL * @see #registerHelperClass(Class) * @param url * @return */ public static URLHelper getURLHelper(URL url) { try { return getURLHelper(urlHelperClass, url); } catch (Exception e) { return getURLHelper(defaultUrlHelperClass, url); } }
public static InputStream openInputStream(String path) throws IOException { InputStream inputStream; if (path.startsWith("http:") || path.startsWith("https:") || path.startsWith("ftp:")) { inputStream = getURLHelper(new URL(path)).openInputStream(); } else { File file = new File(path); inputStream = new FileInputStream(file); } return inputStream; }
public static boolean resourceExists(String resource) throws IOException{ boolean remoteFile = resource.startsWith("http://") || resource.startsWith("https://") || resource.startsWith("ftp://"); if (remoteFile) { URL url = null; try { url = new URL(resource); } catch (MalformedURLException e) { // Malformed URLs by definition don't exist return false; } URLHelper helper = getURLHelper(url); return helper.exists(); } else { return (new File(resource)).exists(); } }
public static boolean resourceExists(String resource) throws IOException{ boolean remoteFile = resource.startsWith("http://") || resource.startsWith("https://") || resource.startsWith("ftp://"); if (remoteFile) { URL url = null; try { url = new URL(resource); } catch (MalformedURLException e) { // Malformed URLs by definition don't exist return false; } URLHelper helper = getURLHelper(url); return helper.exists(); } else if (IOUtil.hasScheme(resource)) { return Files.exists(IOUtil.getPath(resource)); } else { return (new File(resource)).exists(); } }
public static boolean resourceExists(String resource) throws IOException{ boolean remoteFile = resource.startsWith("http://") || resource.startsWith("https://") || resource.startsWith("ftp://"); if (remoteFile) { URL url = null; try { url = new URL(resource); } catch (MalformedURLException e) { // Malformed URLs by definition don't exist return false; } URLHelper helper = getURLHelper(url); return helper.exists(); } else if (IOUtil.hasScheme(resource)) { return Files.exists(IOUtil.getPath(resource)); } else { return (new File(resource)).exists(); } }
/** * open an input stream from the given path and wrap the raw byte stream with a wrapper if given * * the wrapper will only be applied to paths that are not http, https, ftp, or file, i.e. any {@link java.nio.file.Path} * using a custom filesystem plugin * @param uri a uri like string * @param wrapper to wrap the input stream in, may be used to implement caching or prefetching, etc * @return An inputStream appropriately created from uri and conditionally wrapped with wrapper (only in certain cases) * @throws IOException when stream cannot be opened against uri */ public static InputStream openInputStream(final String uri, final Function<SeekableByteChannel, SeekableByteChannel> wrapper) throws IOException { final InputStream inputStream; if (URL_SCHEMES.stream().anyMatch(uri::startsWith)) { inputStream = getURLHelper(new URL(uri)).openInputStream(); } else if (!IOUtil.hasScheme(uri)) { File file = new File(uri); inputStream = Files.newInputStream(file.toPath()); } else { inputStream = new SeekablePathStream(IOUtil.getPath(uri), wrapper); } return inputStream; }
/** * open an input stream from the given path and wrap the raw byte stream with a wrapper if given * * the wrapper will only be applied to paths that are not http, https, ftp, or file, i.e. any {@link java.nio.file.Path} * using a custom filesystem plugin * @param uri a uri like string * @param wrapper to wrap the input stream in, may be used to implement caching or prefetching, etc * @return An inputStream appropriately created from uri and conditionally wrapped with wrapper (only in certain cases) * @throws IOException when stream cannot be opened against uri */ public static InputStream openInputStream(final String uri, final Function<SeekableByteChannel, SeekableByteChannel> wrapper) throws IOException { final InputStream inputStream; if (URL_SCHEMES.stream().anyMatch(uri::startsWith)) { inputStream = getURLHelper(new URL(uri)).openInputStream(); } else if (!IOUtil.hasScheme(uri)) { File file = new File(uri); inputStream = Files.newInputStream(file.toPath()); } else { inputStream = new SeekablePathStream(IOUtil.getPath(uri), wrapper); } return inputStream; }