1 /*
   2  * Copyright (c) 2002-2012, the original author or authors.
   3  *
   4  * This software is distributable under the BSD license. See the terms of the
   5  * BSD license in the documentation provided with this software.
   6  *
   7  * http://www.opensource.org/licenses/bsd-license.php
   8  */
   9 package jline.internal;
  10 
  11 import java.io.File;
  12 import java.net.MalformedURLException;
  13 import java.net.URL;
  14 
  15 /**
  16  * URL helpers.
  17  *
  18  * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
  19  * @author <a href="mailto:gnodet@gmail.com">Guillaume Nodet</a>
  20  * @since 2.7
  21  */
  22 public class Urls
  23 {
  24     public static URL create(final String input) {
  25         if (input == null) {
  26             return null;
  27         }
  28         try {
  29             return new URL(input);
  30         }
  31         catch (MalformedURLException e) {
  32             return create(new File(input));
  33         }
  34     }
  35 
  36     public static URL create(final File file) {
  37         try {
  38             return file != null ? file.toURI().toURL() : null;
  39         }
  40         catch (MalformedURLException e) {
  41             throw new IllegalStateException(e);
  42         }
  43     }
  44 }