Example usage for java.lang ClassLoader getSystemResource

List of usage examples for java.lang ClassLoader getSystemResource

Introduction

In this page you can find the example usage for java.lang ClassLoader getSystemResource.

Prototype

public static URL getSystemResource(String name) 

Source Link

Document

Find a resource of the specified name from the search path used to load classes.

Usage

From source file:kr.co.exsoft.eframework.util.LicenseUtil.java

/**
 * ??  ?./*from  www.j a  v a2s.co  m*/
 * 
 * @param licenseType
 * @param userCount
 * @return String
 */
public static String generateLicenseKey(String licenseType, int userCount) {

    String ksPass = "loveboat";
    String keyPass = "loveboat";
    String alias = "ab942e0f-9e4a-44b9-9f82-0a5f5d48ba12";
    String ret = null;

    try {
        // ??   
        URL url = ClassLoader.getSystemResource("kr/co/exsoft/eframework/cert/exsoft.pfx");
        FileInputStream certfis = new FileInputStream(new File(url.getFile()));

        // Private Key ?.
        BufferedInputStream ksbufin = new BufferedInputStream(certfis);

        KeyStore ks = KeyStore.getInstance("PKCS12");
        ks.load(ksbufin, ksPass.toCharArray());

        PrivateKey key = (PrivateKey) ks.getKey(alias, keyPass.toCharArray());

        // ??  ?.
        ret = spell("EDMsl|" + licenseType + "|" + userCount + "|", key);

    } catch (Exception e) {
        e.printStackTrace();
    }

    return ret;
}

From source file:org.jboss.pressgang.ccms.contentspec.client.commands.PublishCommandTest.java

@Before
public void setUp() {
    bindStdOut();/* w  ww.  ja  v  a2s  .c  o m*/
    command = new PublishCommand(parser, cspConfig, clientConfig);

    // Only test the publish command and not the build or assemble command content.
    command.setNoAssemble(true);

    rootTestDirectory = FileUtils.toFile(ClassLoader.getSystemResource(""));
    when(cspConfig.getRootOutputDirectory()).thenReturn(rootTestDirectory.getAbsolutePath() + File.separator);
}

From source file:de.decoit.simu.cbor.xml.dictionary.DictionaryTest.java

@Test
public void testExtendDictionary() throws Exception {
    DictionaryNamespace dns = new DictionaryNamespace("dummy-namespace-uri", new UnsignedInteger(20));
    Path input = Paths.get(ClassLoader.getSystemResource("namespace-with-simple-elements.dict").toURI());

    Dictionary instance = new Dictionary();

    assertTrue(instance.getUnmodifiableNamespaces().isEmpty());

    instance.addNamespace(dns);//www . ja v  a2s  .  c o  m

    instance.extendDictionary(input);

    assertEquals(dns, instance.lookupNamespace("dummy-namespace-uri"));
    assertNotNull(instance.lookupNamespace("http://www.trustedcomputinggroup.org/2010/IFMAP/2"));
    assertNotNull(instance.lookupNamespace("http://www.trustedcomputinggroup.org/2010/IFMAP/2")
            .lookupElement("access-request"));
}

From source file:edu.snu.dolphin.bsp.examples.ml.algorithms.classification.LogisticRegTest.java

/**
 * Run LogisticReg test./*from   w  ww  . j  a va 2s. c  o  m*/
 */
@Test
public void testLogisticReg() throws Exception {
    final String[] args = { "-dim", "3", "-maxIter", "20", "-stepSize", "0.00001", "-lambda", "0.1", "-local",
            "true", "-split", "4", "-input",
            ClassLoader.getSystemResource("data").getPath() + "/classification", "-output", OUTPUT_PATH,
            "-maxNumEvalLocal", "5" };

    DolphinLauncher.run(Configurations.merge(
            DolphinConfiguration.getConfiguration(args, LogisticRegParameters.getCommandLine()),
            Tang.Factory.getTang().newConfigurationBuilder()
                    .bindNamedParameter(JobIdentifier.class, "Logistic Regression")
                    .bindImplementation(UserJobInfo.class, LogisticRegJobInfo.class)
                    .bindImplementation(UserParameters.class, LogisticRegParameters.class).build()));

    final File expectedModel = new File(
            ClassLoader.getSystemResource("result").getPath() + "/logisticreg_model");
    final File actualModel = new File(OUTPUT_PATH + "/model/CtrlTask-0");
    Assert.assertTrue(FileUtils.contentEquals(expectedModel, actualModel));

    final File expectedAccuracy = new File(
            ClassLoader.getSystemResource("result").getPath() + "/logisticreg_accuracy");
    final File actualAccuracy = new File(OUTPUT_PATH + "/accuracy/CtrlTask-0");
    Assert.assertTrue(FileUtils.contentEquals(expectedAccuracy, actualAccuracy));
}

From source file:org.apache.ws.security.util.Loader.java

/**
 * This method will search for <code>resource</code> in different
 * places. The search order is as follows:
 * <ol>// www.  ja va 2  s  .c o  m
 * <p><li>Search for <code>resource</code> using the thread context
 * class loader under Java2.
 * <p><li>Try one last time with
 * <code>ClassLoader.getSystemResource(resource)</code>, that is is
 * using the system class loader in JDK 1.2 and virtual machine's
 * built-in class loader in JDK 1.1.
 * </ol>
 * <p/>
 *
 * @param resource
 * @return TODO
 */
public static URL getResource(String resource) {
    ClassLoader classLoader = null;
    URL url = null;
    try {
        classLoader = getTCL();
        if (classLoader != null) {
            log.debug("Trying to find [" + resource + "] using " + classLoader + " class loader.");
            url = classLoader.getResource(resource);
            if (url != null) {
                return url;
            }
        }
    } catch (Throwable t) {
        log.warn("Caught Exception while in Loader.getResource. This may be innocuous.", t);
    }

    // Last ditch attempt: get the resource from the class path. It
    // may be the case that clazz was loaded by the Extension class
    // loader which the parent of the system class loader. Hence the
    // code below.
    log.debug("Trying to find [" + resource + "] using ClassLoader.getSystemResource().");
    return ClassLoader.getSystemResource(resource);
}

From source file:org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptorFactoryTest.java

private static URL getTestResourceUrl(String name) throws FileNotFoundException {
    name = UrlRewriteRulesDescriptorFactoryTest.class.getName().replaceAll("\\.", "/") + "/" + name;
    URL url = ClassLoader.getSystemResource(name);
    if (url == null) {
        throw new FileNotFoundException(name);
    }/*from   ww w.j  a  va 2s . co m*/
    return url;
}

From source file:org.n52.sir.IT.InsertSensorInfoNewSensorIT.java

@Test
public void insertAirBaseSensor() throws XmlException, IOException, OwsExceptionReport, HttpException {
    File sensor = new File(ClassLoader.getSystemResource("Requests/sir/testSensor-AirBase.xml").getFile());
    SensorMLDocument DOC = SensorMLDocument.Factory.parse(sensor);
    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)));/*w  ww  .  ja  v a  2  s  . co  m*/
    assertThat("no service reference was inserted",
            resp.getInsertSensorInfoResponse().getNumberOfInsertedServiceReferences(), is(equalTo(0)));
    this.sensorId = resp.getInsertSensorInfoResponse().getInsertedSensors().getSensorIDInSIRArray(0);
}

From source file:org.n52.sir.IT.solr.Harvesting.java

@Test
public void harvestService()
        throws IOException, OwsExceptionReport, HttpException, XmlException, URISyntaxException {
    File f = new File(ClassLoader.getSystemResource("Requests/HarvestService_WeatherSOS.xml").getFile());
    HarvestServiceRequestDocument doc = HarvestServiceRequestDocument.Factory.parse(f);
    XmlObject resp = client.xSendPostRequest(doc, new URI(this.serviceURL));
    System.out.println(resp);//from w  w  w. j a v  a 2 s .  c o m

    HarvestServiceResponseDocument respDoc = HarvestServiceResponseDocument.Factory.parse(resp.getDomNode());
    InsertedSensor[] sensors = respDoc.getHarvestServiceResponse().getInsertedSensorArray();
    for (int i = 0; i < sensors.length; i++) {
        String id = sensors[i].getSensorIDInSIR();
        SOLRSearchSensorDAO dao = new SOLRSearchSensorDAO();
        Collection<SirSearchResultElement> elements = dao.searchByID(id);
        assertTrue(elements.size() > 0);
    }
}

From source file:org.ldp4j.rdf.ChainedFilterExtractorTest.java

protected String loadResource(String resource) throws IOException {
    return IOUtils.toString(ClassLoader.getSystemResource(resource));
}