1 4 package com.tc.config.schema.setup.sources; 5 6 import com.tc.config.schema.setup.ConfigurationSetupException; 7 import com.tc.util.Assert; 8 9 import java.io.File ; 10 import java.io.IOException ; 11 import java.io.InputStream ; 12 import java.net.MalformedURLException ; 13 import java.net.URL ; 14 import java.net.URLConnection ; 15 16 21 public class URLConfigurationSource implements ConfigurationSource { 22 23 private final String url; 24 25 public URLConfigurationSource(String url) { 26 Assert.assertNotBlank(url); 27 this.url = url; 28 } 29 30 public InputStream getInputStream(long maxTimeoutMillis) throws IOException , ConfigurationSetupException { 31 URL theURL = new URL (this.url); 32 33 System.setProperty("sun.net.client.defaultConnectTimeout", String.valueOf(maxTimeoutMillis)); 35 System.setProperty("sun.net.client.defaultReadTimeout", String.valueOf(maxTimeoutMillis)); 36 37 try { 38 URLConnection connection = theURL.openConnection(); 39 return connection.getInputStream(); 40 } catch (MalformedURLException murle) { 41 throw new ConfigurationSetupException("The URL '" + this.url 42 + "' is malformed, and thus can't be used to load configuration."); 43 } 44 } 45 46 public File directoryLoadedFrom() { 47 return null; 48 } 49 50 public boolean isTrusted() { 51 return false; 52 } 53 54 public String toString() { 55 return "URL '" + this.url + "'"; 56 } 57 58 } 59 | Popular Tags |