@NotNull public static String convertFromUrl(@NotNull URL url) { String protocol = url.getProtocol(); String path = url.getPath(); if (protocol.equals(JAR)) { if (StringUtil.startsWithConcatenationOf(path, FILE, PROTOCOL_DELIMITER)) { try { URL subURL = new URL(path); path = subURL.getPath(); } catch (MalformedURLException e) { throw new RuntimeException(VfsBundle.message("url.parse.unhandled.exception"), e); } } else { throw new RuntimeException( new IOException(VfsBundle.message("url.parse.error", url.toExternalForm()))); } } if (SystemInfo.isWindows || SystemInfo.isOS2) { while (path.length() > 0 && path.charAt(0) == '/') { path = path.substring(1, path.length()); } } path = URLUtil.unescapePercentSequences(path); return protocol + "://" + path; }
@Nullable public static Image loadFromUrl(URL url) { for (Pair<String, Integer> each : getFileNames(url.toString())) { try { return loadFromStream(URLUtil.openStream(new URL(each.first)), each.second); } catch (IOException ignore) { } } return null; }
@NotNull public static String loadText(@NotNull URL url) throws IOException { InputStream inputStream = new BufferedInputStream(URLUtil.openStream(url)); InputStreamReader reader = null; try { reader = new InputStreamReader(inputStream, ENCODING_UTF_8); StringBuffer text = new StringBuffer(); char[] buf = new char[5000]; while (reader.ready()) { final int length = reader.read(buf); if (length == -1) break; text.append(buf, 0, length); } return text.toString(); } finally { if (reader != null) { reader.close(); } } }
@NotNull public static String unquote(@NotNull String urlString) { urlString = urlString.replace('/', File.separatorChar); return URLUtil.unescapePercentSequences(urlString); }