X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FHttpUtils.java;fp=src%2Fjalview%2Futil%2FHttpUtils.java;h=88df58772d55349c8a535320903ccca34c2fb644;hb=e411c801ba976142e207e28f196d59ab24507767;hp=0000000000000000000000000000000000000000;hpb=95e1400e3e807ec4eb7fb23e6d2ae2519416baa3;p=jalview.git diff --git a/src/jalview/util/HttpUtils.java b/src/jalview/util/HttpUtils.java new file mode 100644 index 0000000..88df587 --- /dev/null +++ b/src/jalview/util/HttpUtils.java @@ -0,0 +1,47 @@ +package jalview.util; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +public class HttpUtils +{ + + /** + * Returns true if it is possible to open an input stream at the given URL, + * else false. The input stream is closed. + * + * @param url + * @return + */ + public static boolean isValidUrl(String url) + { + InputStream is = null; + try + { + is = new URL(url).openStream(); + if (is != null) + { + return true; + } + } catch (IOException x) + { + // MalformedURLException, FileNotFoundException + return false; + } finally + { + if (is != null) + { + try + { + is.close(); + } catch (IOException e) + { + // ignore + } + } + } + return false; + } + +}