List of usage examples for java.net URL openStream
public final InputStream openStream() throws java.io.IOException
From source file:com.tera.common.vcontext.service.ContextConfigurationParser.java
/** * @param bundle bundle of the loading resource * @param xsdSchema schema location of vcontext.xml * @param fileSystemXml resource to be loaded *//*from w w w .java 2s. c o m*/ public static final void parseVirtualConfiguration(Bundle bundle, URL xsdSchema, URL fileSystemXml) { Unmarshaller un = JaxbUtil.create(VContextTemplate.class, xsdSchema); try { VContextTemplate context = (VContextTemplate) un.unmarshal(fileSystemXml.openStream()); List<VElementTemplate> elements = context.getTemplates(); for (VElementTemplate template : elements) { String name = template.getName(); String path = template.getPath(); String target = template.getTarget(); switch (template.getType()) { case DM: ContextRegisterService.registerDM(bundle.getSymbolicName(), name); break; case CONFIG: ContextRegisterService.registerConfig(bundle.getSymbolicName(), name); break; case FILE: ContextRegisterService.registerFile(bundle.getResource(path), name, target); break; case PROPERTIES: ContextRegisterService.registerProperties(bundle.getResource(name), name); break; case COMMAND: ContextRegisterService.registerCommands(bundle.getSymbolicName(), bundle.getEntryPaths(path)); break; case SCHEMA_VERSION: ContextRegisterService.registerSchemaVersions(bundle.getResource(path)); break; } } } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.microsoft.intellij.util.WAHelper.java
/** * This API compares if two files content is identical. It ignores extra * spaces and new lines while comparing/*from ww w . ja v a 2 s . c o m*/ * * @param sourceFile * @param destFile * @return * @throws Exception */ public static boolean isFilesIdentical(URL sourceFile, File destFile) throws Exception { try { Scanner sourceFileScanner = new Scanner(sourceFile.openStream()); Scanner destFileScanner = new Scanner(destFile); while (sourceFileScanner.hasNext()) { /* * If source file is having next token then destination file * also should have next token, else they are not identical. */ if (!destFileScanner.hasNext()) { destFileScanner.close(); sourceFileScanner.close(); return false; } if (!sourceFileScanner.next().equals(destFileScanner.next())) { sourceFileScanner.close(); destFileScanner.close(); return false; } } /* * Handling the case where source file is empty and destination file * is having text */ if (destFileScanner.hasNext()) { destFileScanner.close(); sourceFileScanner.close(); return false; } else { destFileScanner.close(); sourceFileScanner.close(); return true; } } catch (Exception e) { e.printStackTrace(); throw e; } /*finally { sourceFile.close(); }*/ }
From source file:io.fabric8.devops.ProjectConfigs.java
/** * Returns the project config from the given url if it exists or null *//*from w ww. j ava 2 s . c o m*/ public static ProjectConfig loadFromUrl(URL url) { InputStream input = null; try { input = url.openStream(); } catch (FileNotFoundException e) { LOG.info("No fabric8.yml at URL: " + url); } catch (IOException e) { LOG.warn("Failed to open fabric8.yml file at URL: " + url + ". " + e, e); } if (input != null) { try { LOG.info("Parsing " + ProjectConfigs.FILE_NAME + " from " + url); return ProjectConfigs.parseProjectConfig(input); } catch (IOException e) { LOG.warn("Failed to parse " + ProjectConfigs.FILE_NAME + " from " + url + ". " + e, e); } } return null; }
From source file:at.gv.egovernment.moa.id.configuration.helper.MailHelper.java
private static String readTemplateFromURL(String templateurl, String rootDir) throws ConfigurationException { InputStream input;/*from w ww.j a v a 2 s. c o m*/ try { URL keystoreURL = new URL(FileUtils.makeAbsoluteURL(templateurl, rootDir)); input = keystoreURL.openStream(); StringWriter writer = new StringWriter(); IOUtils.copy(input, writer); input.close(); return writer.toString(); } catch (Exception e) { log.warn("Mailtemplate can not be read from source" + templateurl); throw new ConfigurationException("Mailtemplate can not be read from source" + templateurl); } }
From source file:com.tunyk.jsonbatchtranslate.api.JsonBatchTranslateTest.java
@BeforeClass public static void setUp() throws IOException { Properties properties = new Properties(); URL url = ClassLoader.getSystemResource("config.properties"); properties.load(url.openStream()); googleTranslateApiKey = properties.getProperty("google.translate.api.key"); microsoftTranslatorApiKey = properties.getProperty("microsoft.translator.api.key"); yandexApiKey = null;//from w ww .j a v a 2 s.c o m in = FileUtils.readFileToString(new File(ClassLoader.getSystemResource("input.json").getPath())); }
From source file:eionet.gdem.conversion.datadict.DataDictUtil.java
/** * gather all element definitions/*from w ww . j a v a2s . co m*/ * * @param instance * @param schemaUrl */ public static Map<String, DDElement> importDDTableSchemaElemDefs(String schemaUrl) { InputStream inputStream = null; Map<String, DDElement> elemDefs = new HashMap<String, DDElement>(); try { // get element definitions for given schema // DataDictUtil.getSchemaElemDefs(elemDefs, schemaUrl); // load imported schema URLs IXmlCtx ctx = new XmlContext(); URL url = new URL(schemaUrl); inputStream = url.openStream(); ctx.checkFromInputStream(inputStream); IXQuery xQuery = ctx.getQueryManager(); // run recursively the same function for importing elem defs for imported schemas List<String> schemas = xQuery.getSchemaImports(); Map<String, String> multiValueElements = xQuery.getSchemaElementWithMultipleValues(); for (int i = 0; i < schemas.size(); i++) { String schema = schemas.get(i); DataDictUtil.importDDElementSchemaDefs(elemDefs, schema); } for (Map.Entry<String, String> entry : multiValueElements.entrySet()) { DDElement multiValueElement = null; if (elemDefs.containsKey(entry.getKey())) { multiValueElement = elemDefs.get(entry.getKey()); } else { multiValueElement = new DDElement(entry.getKey()); } multiValueElement.setHasMultipleValues(true); multiValueElement.setDelimiter(entry.getValue()); elemDefs.put(entry.getKey(), multiValueElement); } } catch (Exception ex) { LOGGER.error("Error reading schema file ", ex); } finally { try { inputStream.close(); } catch (Exception e) { } } return elemDefs; }
From source file:com.turt2live.hurtle.uuid.UUIDServiceProvider.java
/** * Gets the UUID of a player name.// ww w . j a v a2 s. co m * * @param name the name, cannot be null * * @return the UUID for the player, or null if not found or for invalid input */ public static UUID getUUID(String name) { if (name == null) return null; try { URL url = new URL("http://uuid.turt2live.com/uuid/" + name); BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); String parsed = ""; String line; while ((line = reader.readLine()) != null) parsed += line; reader.close(); Object o = JSONValue.parse(parsed); if (o instanceof JSONObject) { JSONObject jsonObject = (JSONObject) o; o = jsonObject.get("uuid"); if (o instanceof String) { String s = (String) o; if (!s.equalsIgnoreCase("unknown")) { return UUID.fromString(insertDashes(s)); } } } } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:org.stem.ClusterManagerDaemon.java
public static Config loadConfig() { URL url = getConfigUrl(); logger.info("Loading settings from " + url); InputStream stream;/*from w w w . j ava2 s .co m*/ try { stream = url.openStream(); } catch (IOException e) { throw new AssertionError(e); } Constructor constructor = new Constructor(Config.class); Yaml yaml = new Yaml(constructor); config = (Config) yaml.load(stream); return config; }
From source file:com.moadbus.banking.iso.core.data.DataSetConfigParser.java
/** Creates a dataset factory from the file located at the specified URL. */ public static DataSetFactory createFromUrl(URL url) throws IOException { if (dsFactory == null) { dsFactory = new DataSetFactory(); InputStream stream = url.openStream(); try {/*ww w. j a v a 2 s.c om*/ parse(dsFactory, stream); } finally { stream.close(); } } return dsFactory; }
From source file:hudson.init.InitScriptsExecutor.java
@Initializer(after = JOB_LOADED) public static void init(Hudson hudson) throws IOException { URL bundledInitScript = hudson.servletContext.getResource("/WEB-INF/init.groovy"); if (bundledInitScript != null) { logger.info("Executing bundled init script: " + bundledInitScript); InputStream in = bundledInitScript.openStream(); try {//www . j a v a 2 s . c o m String script = IOUtils.toString(in); logger.info(new Script(script).execute()); } finally { IOUtils.closeQuietly(in); } } File initScript = new File(hudson.getRootDir(), "init.groovy"); if (initScript.exists()) { execute(initScript); } File initScriptD = new File(hudson.getRootDir(), "init.groovy.d"); if (initScriptD.isDirectory()) { File[] scripts = initScriptD.listFiles(new FileFilter() { @Override public boolean accept(File f) { return f.getName().endsWith(".groovy"); } }); if (scripts != null) { // sort to run them in a deterministic order Arrays.sort(scripts); for (File f : scripts) { execute(f); } } } }