X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FHttpUtils.java;fp=src%2Fjalview%2Futil%2FHttpUtils.java;h=991a20a1f23f387362b577667d82cbd461e2aca9;hb=9623cea766a766683243235557ad48e6f7659e6a;hp=0000000000000000000000000000000000000000;hpb=6066400ed6b0fe288ebbea82389f59838a534706;p=jalview.git diff --git a/src/jalview/util/HttpUtils.java b/src/jalview/util/HttpUtils.java new file mode 100644 index 0000000..991a20a --- /dev/null +++ b/src/jalview/util/HttpUtils.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + ******************************************************************************/ +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; + } + +}