List of usage examples for java.lang ClassLoader getSystemResource
public static URL getSystemResource(String name)
From source file:com.novoda.imageloader.core.file.util.FileUtilTest.java
@Test public void shouldCopyStream() throws ImageCopyException, URISyntaxException { URL testFile = ClassLoader.getSystemResource("testFile1"); File from = new File(testFile.toURI()); assertTrue(from.exists());/*from w ww . ja v a 2s.co m*/ File to = new File(cacheDir.getAbsolutePath() + "testFile1"); fileUtil.copy(from, to); FileAssert.assertBinaryEquals(from, to); }
From source file:dk.dma.ais.encode.EncodeTest.java
/** * Decode VDM, re-encode, and compare messages * //from w w w.j a v a 2 s . co m */ @Test public void vdmDecodeEncode() throws IOException, SentenceException, SixbitException, AisMessageException { URL url = ClassLoader.getSystemResource("decode_encode_messages.txt"); Assert.assertNotNull(url); try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()))) { Assert.assertNotNull(in); String line; Vdm vdm = new Vdm(); while ((line = in.readLine()) != null) { int res = vdm.parse(new SentenceLine(line)); if (res != 0) { continue; } AisMessage msg = AisMessage.getInstance(vdm); Assert.assertNotNull(msg); vdm = new Vdm(); // TODO Do encoding of new Vdm with decoded message and compare // messages // TODO Fill decode_encode_messages.txt with supported messages } } }
From source file:org.openecomp.sdc.be.dao.es.ElasticSearchClient.java
@PostConstruct public void initialize() throws URISyntaxException { URL url = null;/*w w w . jav a 2s . c om*/ Settings settings = null; URL systemResourceElasticsearchPath = ClassLoader.getSystemResource("elasticsearch.yml"); if (systemResourceElasticsearchPath != null) { log.debug("try to create URI for {}", systemResourceElasticsearchPath.toString()); Path classpathConfig = Paths.get(systemResourceElasticsearchPath.toURI()); settings = Settings.settingsBuilder().loadFromPath(classpathConfig).build(); } String configHome = System.getProperty("config.home"); if (configHome != null && false == configHome.isEmpty()) { try { if (SystemUtils.IS_OS_WINDOWS) { url = new URL("file:///" + configHome + "/elasticsearch.yml"); } else { url = new URL("file:" + configHome + "/elasticsearch.yml"); } log.debug("URL {}", url); settings = Settings.settingsBuilder().loadFromPath(Paths.get(url.toURI())).build(); } catch (MalformedURLException | URISyntaxException e1) { log.error("Failed to create URL in order to load elasticsearch yml"); System.err.println("Failed to create URL in order to load elasticsearch yml from " + configHome); } } if (settings == null) { log.error("Failed to find settings of elasticsearch yml"); System.err.println("Failed to create URL in order to load elasticsearch yml from " + configHome); } if (isTransportClient()) { log.info("******* ElasticSearchClient type is Transport Client *****"); TransportClient transportClient = TransportClient.builder().addPlugin(ShieldPlugin.class) .settings(settings).build(); String[] nodesArray = transportClient.settings().getAsArray("transport.client.initial_nodes"); for (String host : nodesArray) { int port = 9300; // or parse it from the host string... String[] splitHost = host.split(":", 2); if (splitHost.length == 2) { host = splitHost[0]; port = Integer.parseInt(splitHost[1]); } transportClient .addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress(host, port))); } this.client = transportClient; serverHost = Arrays.toString(nodesArray); } else { log.info("******* ElasticSearchClient type is Node Client *****"); this.node = NodeBuilder.nodeBuilder().settings(settings).client(!isLocal).clusterName(this.clusterName) .local(isLocal).node(); this.client = node.client(); serverHost = this.client.settings().get("discovery.zen.ping.unicast.hosts"); if (serverHost == null) { serverHost = "['localhost:9200']"; } } serverPort = this.client.settings().get("http.port"); if (serverPort == null) { serverPort = "9200"; } log.info("Initialized ElasticSearch client for cluster <{}> with nodes: {}", this.clusterName, serverHost); }
From source file:kr.co.exsoft.eframework.util.LicenseUtil.java
/** * // w w w . j a v a 2 s . com * <pre> * 1. : ?? APPLICATION * 2. : * </pre> * @Method Name : decipherLicenseKey * @param licenseKey * @return String * @throws Exception */ public static String decipherLicenseKey(String licenseKey) throws Exception { String ret = null; if (StringUtils.isNotBlank(licenseKey)) { // ?? ? public key ? URL url = ClassLoader.getSystemResource("kr/co/exsoft/eframework/cert/exsoft.cer"); FileInputStream certfis = new FileInputStream(new File(url.getFile())); CertificateFactory cf = CertificateFactory.getInstance("X.509"); Certificate cert = cf.generateCertificate(certfis); PublicKey key = cert.getPublicKey(); // ?? . ret = unspell(licenseKey, key); } return ret; }
From source file:org.n52.sir.IT.InsertSensorInfoNewSensorIT.java
@Test public void insertTestSensorFromFile1() throws XmlException, IOException, OwsExceptionReport, HttpException { File f = new File(ClassLoader.getSystemResource("Requests/sir/testSensor-1.xml").getFile()); SensorMLDocument doc = SensorMLDocument.Factory.parse(f); InsertSensorInfoRequestDocument req = InsertSensorInfoRequestDocument.Factory.newInstance(); req.addNewInsertSensorInfoRequest().addNewInfoToBeInserted() .setSensorDescription(doc.getSensorML().getMemberArray()[0].getProcess()); XmlObject res = client.xSendPostRequest(req); InsertSensorInfoResponseDocument resp = InsertSensorInfoResponseDocument.Factory.parse(res.getDomNode()); assertThat("one sensor was inserted", resp.getInsertSensorInfoResponse().getNumberOfInsertedSensors(), is(equalTo(1)));//www . j a v a 2 s.com assertThat("no service reference was inserted", resp.getInsertSensorInfoResponse().getNumberOfInsertedServiceReferences(), is(equalTo(0))); this.sensorId = resp.getInsertSensorInfoResponse().getInsertedSensors().getSensorIDInSIRArray(0); }
From source file:com.blackducksoftware.tools.commonframework.core.config.ConfigurationManagerTest.java
/** * Sets the up before class.//from w w w . ja v a 2s.co m */ @BeforeClass static public void setUpBeforeClass() { final String fullLocation = ClassLoader.getSystemResource(testFile).getFile(); configurationManager = new TestConfigurationManagerBean(fullLocation); }
From source file:de.tbuchloh.kiskis.persistence.exporter.XMLTransformer.java
/** * @param stylesheet//from w w w . j a v a2s.co m * is the stylesheet to use. * @param is * is the input source. * @param os * is the output sink. */ public void transform(final URL stylesheet, final InputStream is, final OutputStream os) throws TransformException { try { LOG.debug("transforming with stylesheet=" + stylesheet); final XMLReader reader = XMLReaderFactory.createXMLReader(); reader.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException, IOException { if (systemId == null) { throw new IllegalArgumentException("systemId must not be null!"); } final int pos = systemId.lastIndexOf(File.separator); String resource = systemId; if (pos >= 0) { resource = resource.substring(pos + 1); } final URL dtd = ClassLoader.getSystemResource(resource); LOG.debug("Resolving " + "systemId=" + systemId + ", resource=" + resource + ", dtd=" + dtd); return new InputSource(dtd.openStream()); } }); try { final Builder builder = new Builder(reader, false); final Document s = builder.build(stylesheet.openStream()); final Document source = builder.build(is); final XSLTransform transform = new XSLTransform(s); final Document target = XSLTransform.toDocument(transform.transform(source)); final Serializer ser = new Serializer(os); ser.setIndent(2); ser.write(target); } catch (final Exception e) { LOG.error(e, e); throw new XMLException(e.getMessage()); } } catch (final Exception e) { throw new TransformException(e.getMessage(), e); } }
From source file:org.opf_labs.fmts.AllFidgetTests.java
/** * @param resName/*from w w w .j av a2s .c om*/ * the name of the resource to retrieve a file for * @return the java.io.File for the named resource * @throws URISyntaxException * if the named resource can't be converted to a URI */ public final static File getResourceAsFile(String resName) throws URISyntaxException { return new File(ClassLoader.getSystemResource(resName).toURI()); }
From source file:com.netspective.commons.lang.ResourceLoader.java
/** * This method will search for <code>resource</code> in different * places. The search order is as follows: * <p/>// www .j a v a2s. c o m * <ol> * <li>Search for <code>resource</code> using the thread context * class loader. If that fails, search for <code>resource</code> using * the class loader that loaded this class. * <li>Try one last time with <code>ClassLoader.getSystemResource(resource)</code>. * </ol> */ public static URL getResource(String resource) { ClassLoader classLoader = null; URL url = null; try { classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader != null) { url = classLoader.getResource(resource); if (url != null) return url; } // We could not find resource. Lets try with the classloader that loaded this class. classLoader = ResourceLoader.class.getClassLoader(); if (classLoader != null) { url = classLoader.getResource(resource); if (url != null) return url; } } catch (Throwable t) { log.warn("Caught Exception while in ResourceLoader.getResource.", t); } // Last ditch attempt: get the resource from the class path. It // may be the case that clazz was loaded by the Extentsion class // loader which the parent of the system class loader. Hence the // code below. return ClassLoader.getSystemResource(resource); }
From source file:org.apache.james.jmap.json.ParsingWritingObjectsTest.java
@Test public void parsingJsonShouldWorkOnMessage() throws Exception { Message expected = MESSAGE;// w ww . j a va 2s .c o m Message message = testee.forParsing() .readValue(IOUtils.toString(ClassLoader.getSystemResource("json/message.json")), Message.class); assertThat(message).isEqualToComparingFieldByField(expected); }