Example usage for java.lang ClassLoader getSystemResourceAsStream

List of usage examples for java.lang ClassLoader getSystemResourceAsStream

Introduction

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

Prototype

public static InputStream getSystemResourceAsStream(String name) 

Source Link

Document

Open for reading, a resource of the specified name from the search path used to load classes.

Usage

From source file:com.impetus.client.schemamanager.CassandraPropertiesTest.java

@Test
public void testValid() throws NotFoundException, InvalidRequestException, TException, IOException {
    getEntityManagerFactory("create");

    PersistenceUnitMetadata puMetadata = KunderaMetadataManager.getPersistenceUnitMetadata(pu);
    Properties properties = new Properties();
    try {/*from  w  w  w .  j  av a 2s .  c o m*/
        InputStream inStream = puMetadata != null ? ClassLoader.getSystemResourceAsStream(
                puMetadata.getProperty(PersistenceProperties.KUNDERA_CLIENT_PROPERTY)) : null;
        properties.load(inStream);
        String expected_replication = properties.getProperty(Constants.REPLICATION_FACTOR);
        String expected_strategyClass = properties.getProperty(Constants.PLACEMENT_STRATEGY);

        KsDef ksDef = client.describe_keyspace(keyspace);
        Assert.assertEquals(expected_replication, ksDef.strategy_options.get("replication_factor"));
        Assert.assertEquals(expected_strategyClass, ksDef.getStrategy_class());
    } catch (IOException e) {
        log.warn("kundera-cassandra.properties file not found");
    }
}

From source file:fr.gael.dhus.server.http.SolrWebapp.java

@Override
public void afterPropertiesSet() throws Exception {
    try {/* w ww.  j  av  a 2 s  . co m*/
        SolrConfiguration solr = configurationManager.getSolrConfiguration();

        File solrroot = new File(solr.getPath());
        System.setProperty("solr.solr.home", solrroot.getAbsolutePath());

        File libdir = new File(solrroot, "lib");
        libdir.mkdirs();
        File coredir = new File(solrroot, "dhus");
        coredir.mkdirs();
        File confdir = new File(coredir, "conf");

        // Move old data/conf dirs if any
        File olddata = new File(solrroot, "data/dhus");
        if (olddata.exists()) {
            File newdata = new File(coredir, "data");
            olddata.renameTo(newdata);
        }
        File oldconf = new File(solrroot, "conf");
        if (oldconf.exists()) {
            oldconf.renameTo(confdir);
        }
        confdir.mkdirs();
        // Rename old `schema.xml` file to `managed-schema`
        File schemafile = new File(confdir, "managed-schema");
        File oldschema = new File(confdir, "schema.xml");
        if (oldschema.exists()) {
            oldschema.renameTo(schemafile);
        }

        // solr.xml
        InputStream input = ClassLoader.getSystemResourceAsStream("fr/gael/dhus/server/http/solr/solr.xml");
        OutputStream output = new FileOutputStream(new File(solrroot, "solr.xml"));
        IOUtils.copy(input, output);
        output.close();
        input.close();

        // dhus/core.properties
        input = ClassLoader.getSystemResourceAsStream("fr/gael/dhus/server/http/solr/core.properties");
        File core_props = new File(coredir, "core.properties");
        output = new FileOutputStream(core_props);
        IOUtils.copy(input, output);
        output.close();
        input.close();

        // dhus/solrconfig.xml
        input = ClassLoader.getSystemResourceAsStream("fr/gael/dhus/server/http/solr/solrconfig.xml");
        File solrconfigfile = new File(confdir, "solrconfig.xml");
        output = new FileOutputStream(solrconfigfile);
        IOUtils.copy(input, output);
        output.close();
        input.close();

        // dhus/schema.xml
        if (!schemafile.exists()) {
            String schemapath = solr.getSchemaPath();
            if ((schemapath == null) || ("".equals(schemapath)) || (!(new File(schemapath)).exists())) {
                input = ClassLoader.getSystemResourceAsStream("fr/gael/dhus/server/http/solr/schema.xml");
            } else {
                input = new FileInputStream(new File(schemapath));
            }
            output = new FileOutputStream(schemafile);
            IOUtils.copy(input, output);
            output.close();
            input.close();
        }

        // dhus/stopwords.txt
        input = ClassLoader.getSystemResourceAsStream("fr/gael/dhus/server/http/solr/stopwords.txt");
        output = new FileOutputStream(new File(confdir, "stopwords.txt"));
        IOUtils.copy(input, output);
        output.close();
        input.close();

        // dhus/synonyms.txt
        String synonympath = solr.getSynonymPath();
        if ((synonympath == null) || ("".equals(synonympath)) || (!(new File(synonympath)).exists())) {
            input = ClassLoader.getSystemResourceAsStream("fr/gael/dhus/server/http/solr/synonyms.txt");
        } else {
            input = new FileInputStream(new File(synonympath));
        }
        output = new FileOutputStream(new File(confdir, "synonyms.txt"));
        IOUtils.copy(input, output);
        output.close();
        input.close();

        // dhus/xslt/opensearch_atom.xsl
        input = ClassLoader.getSystemResourceAsStream("fr/gael/dhus/server/http/solr/xslt/opensearch_atom.xsl");
        if (input != null) {
            File xslt_dir = new File(confdir, "xslt");
            if (!xslt_dir.exists()) {
                xslt_dir.mkdirs();
            }
            output = new FileOutputStream(new File(xslt_dir, "opensearch_atom.xsl"));
            IOUtils.copy(input, output);
            output.close();
            input.close();
        } else {
            LOGGER.warn("Cannot file opensearch xslt file. " + "Opensearch interface is not available.");
        }

        solrInitializer.createSchema(coredir.getAbsolutePath(), schemafile.getAbsolutePath());

    } catch (IOException e) {
        throw new UnsupportedOperationException("Cannot initialize Solr service.", e);
    }
}

From source file:org.openengsb.openengsbplugin.tools.ToolsTest.java

@Test
public void testRemoveNode() throws Exception {
    Document doc = Tools//from w  w  w .  j a  v a  2  s .com
            .parseXMLFromString(IOUtils.toString(ClassLoader.getSystemResourceAsStream("removeNode/pom.xml")));
    String xpath = "/pom:project/pom:properties";
    assertNotNull(Tools.evaluateXPath(xpath, doc, NS_CONTEXT, XPathConstants.NODE, Node.class));
    Tools.removeNode("/pom:project/pom:properties", doc, NS_CONTEXT, false);
    assertNull(Tools.evaluateXPath(xpath, doc, NS_CONTEXT, XPathConstants.NODE, Node.class));
}

From source file:org.underworldlabs.util.FileUtils.java

public static String loadResource(String path) throws IOException {
    InputStream input = null;/*  w w  w  .jav a  2 s.  c  om*/
    BufferedReader reader = null;

    try {

        ClassLoader cl = FileUtils.class.getClassLoader();

        if (cl != null) {
            input = cl.getResourceAsStream(path);
        } else {
            input = ClassLoader.getSystemResourceAsStream(path);
        }

        reader = new BufferedReader(new InputStreamReader(input));

        String line = null;
        StringBuilder buf = new StringBuilder();

        while ((line = reader.readLine()) != null) {
            buf.append(line);
            buf.append("\n");
        }

        return buf.toString();
    } finally {
        if (reader != null) {
            reader.close();
        }
        if (input != null) {
            input.close();
        }
    }
}

From source file:org.cloudifysource.esc.driver.provisioning.privateEc2.parser.PrivateEc2TemplateParserTest.java

@Test
public void testJoinTemplate() throws IOException, PrivateEc2ParserException {
    InputStream templateStream = ClassLoader.getSystemResourceAsStream("./cfn_templates/join.template");
    PrivateEc2Template template = ParserUtils.mapJson(PrivateEc2Template.class, templateStream);
    assertNotNull(template);//w ww  .j av a2  s  . c o m
    assertNotNull(template);
    assertNotNull(template.getEC2Instance());
    assertNotNull(template.getEC2Instance().getProperties());
    assertNotNull(template.getEC2Instance().getProperties().getAvailabilityZone());
    assertNotNull(template.getEC2Instance().getProperties().getUserData());
    assertEquals("export NIC_ADDR=`hostname`\nexport JAVA_HOME=/home/ubuntu/java\n",
            template.getEC2Instance().getProperties().getUserData().getValue());
}

From source file:org.apache.james.http.jetty.JettyHttpServerFactoryTest.java

@SuppressWarnings("unchecked")
@Test//from w  w  w  . j  a  va  2 s. c o m
public void shouldBeAbleToLoadEmptyMappingConfiguration() throws Exception {
    HierarchicalConfiguration configuration = loadConfiguration(
            ClassLoader.getSystemResourceAsStream("emptymappingconfiguration.xml"));
    assertThat(new JettyHttpServerFactory().createServers(configuration))
            .extracting(server -> server.getConfiguration().getMappings()).containsOnly(ImmutableMap.of());
}

From source file:org.apache.james.webadmin.integration.JwtFilterIntegrationTest.java

@Before
public void setUp() throws Exception {
    JwtConfiguration jwtConfiguration = new JwtConfiguration(Optional
            .of(IOUtils.toString(ClassLoader.getSystemResourceAsStream("jwt_publickey"), Charsets.UTF_8)));

    guiceJamesServer = cassandraJmapTestRule.jmapServer().overrideWith(new WebAdminConfigurationModule(),
            binder -> binder.bind(AuthenticationFilter.class).to(JwtFilter.class),
            binder -> binder.bind(JwtConfiguration.class).toInstance(jwtConfiguration));
    guiceJamesServer.start();//from  www  . ja  v  a 2 s. c  o m
    dataProbe = guiceJamesServer.getProbe(DataProbeImpl.class);
    webAdminGuiceProbe = guiceJamesServer.getProbe(WebAdminGuiceProbe.class);

    RestAssured.requestSpecification = new RequestSpecBuilder().setContentType(ContentType.JSON)
            .setAccept(ContentType.JSON)
            .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8)))
            .build();
}

From source file:dk.dma.ais.track.AisTrackServiceConfiguration.java

private InputStream aisBusConfiguration() throws IOException {
    InputStream is = null;//from   w w w.j a  va 2s  .c  om

    if (!StringUtils.isBlank(aisBusXmlFileName)) {
        LOG.debug("Application properties say that aisbus.xml can be found in " + aisBusXmlFileName);

        Path aisBusXmlFile = Paths.get(aisBusXmlFileName);
        if (Files.exists(aisBusXmlFile) && Files.isReadable(aisBusXmlFile)
                && Files.isRegularFile(aisBusXmlFile)) {
            LOG.debug(aisBusXmlFileName
                    + " exists, is readable and regular. Using that for AisBus configuration.");
            LOG.info("Using " + aisBusXmlFile.toAbsolutePath().toString());
            is = Files.newInputStream(aisBusXmlFile);
        } else {
            LOG.debug(
                    "Application properties points to a file which does not exist or is not readable or regular.");
        }
    } else {
        LOG.debug("No location of aisbus.xml given in application properties.");
    }

    if (is == null) {
        LOG.info("Falling back to built-in default AisBus configuration.");
        is = ClassLoader.getSystemResourceAsStream("aisbus.xml");
    }

    return is;
}

From source file:org.ebayopensource.turmeric.services.repository.listener.util.CommonUtil.java

public static AssetKey createCompleteServiceAsset() {

    Properties prop = loadPropertyFile("properties/common.properties");
    AssetKey serviceAssetKey = null;/*from w w  w  .  j  a  v a2s.  c o  m*/

    String assetName = "testasset";
    prop.getProperty("libraryName", "GovernedAssets");
    String groupName = prop.getProperty("groupName", "GroupName");
    String assetDescription = "Test asset created using junit";
    String versionOne = "1.0.0";
    String appendTimeStamp = new Long(System.currentTimeMillis()).toString();
    assetName = assetName.concat(appendTimeStamp);

    AssetKey assetKey = new AssetKey();
    assetKey.setAssetName(assetName);

    BasicAssetInfo basicAssetInfo = new BasicAssetInfo();
    basicAssetInfo.setAssetDescription(assetDescription);
    basicAssetInfo.setAssetKey(assetKey);
    basicAssetInfo.setAssetName(assetName);
    basicAssetInfo.setAssetType("Service");
    basicAssetInfo.setGroupName(groupName);
    basicAssetInfo.setVersion(versionOne);

    ArtifactInfo artifactInfo = new ArtifactInfo();
    Artifact artifact = new Artifact();
    artifact.setArtifactName("assetName.wsdl");
    artifact.setArtifactCategory(RepositoryServiceClientConstants.ARTIFACT_CATEGORY);
    artifact.setArtifactValueType(
            ArtifactValueType.valueOf(RepositoryServiceClientConstants.ARTIFACT_VALUE_TYPE_FILE));
    artifactInfo.setArtifact(artifact);

    InputStream is = ClassLoader.getSystemResourceAsStream("wsdls/SoaSchemaValidateTestServiceV1.wsdl");

    byte[] bytes = null;
    try {
        bytes = IOUtils.toByteArray(is);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    artifactInfo.setArtifactDetail(bytes);
    artifactInfo.setContentType("application/xml");

    List<AttributeNameValue> attributeNameValues = new ArrayList<AttributeNameValue>();
    AttributeNameValue attributeNameValue = new AttributeNameValue();
    attributeNameValue.setAttributeName(RepositoryServiceClientConstants.ATTRIBUTE1_NAME);
    attributeNameValue.setAttributeValueString(RepositoryServiceClientConstants.ATTRIBUTE1_VALUE);
    attributeNameValues.add(attributeNameValue);

    ExtendedAssetInfo extendedAssetInfo = new ExtendedAssetInfo();
    extendedAssetInfo.getAttribute().addAll(attributeNameValues);

    AssetLifeCycleInfo assetLifeCycleInfo = new AssetLifeCycleInfo();
    assetLifeCycleInfo.setApprover("jpnadar");
    assetLifeCycleInfo.setLifeCycleState("Approved");
    assetLifeCycleInfo.setProjectManager("arajmony");

    AssetInfo fdAssetInfo = createBasicAsset("Functional Domain", "Functional Domain Template");

    FlattenedRelationship flattenedRelationship = new FlattenedRelationship();
    flattenedRelationship.setDepth(1);
    flattenedRelationship.setPartial(false);
    flattenedRelationship.setSourceAsset(assetKey);
    Relation relation = new Relation();
    relation.setSourceAsset(assetKey);

    relation.setTargetAsset(fdAssetInfo.getBasicAssetInfo().getAssetKey());
    relation.setAssetRelationship("Predecessor");
    flattenedRelationship.getRelatedAsset().add(relation);

    AssetInfo assetInfo = new AssetInfo();
    assetInfo.setBasicAssetInfo(basicAssetInfo);
    assetInfo.getArtifactInfo().add(artifactInfo);
    assetInfo.setExtendedAssetInfo(extendedAssetInfo);
    assetInfo.setAssetLifeCycleInfo(assetLifeCycleInfo);
    assetInfo.setFlattenedRelationship(flattenedRelationship);

    CreateCompleteAssetRequest createCompleteAssetRequest = new CreateCompleteAssetRequest();
    createCompleteAssetRequest.setAssetInfo(assetInfo);

    RepositoryServiceConsumer rsConsumer = new RepositoryServiceConsumer();

    try {
        CreateCompleteAssetResponse createCompleteAssetResponse = rsConsumer.getProxy()
                .createCompleteAsset(createCompleteAssetRequest);
        if (createCompleteAssetResponse.getAck().value()
                .equalsIgnoreCase(RepositoryServiceClientConstants.SUCCESS)) {
            serviceAssetKey = createCompleteAssetResponse.getAssetKey();
        }
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return serviceAssetKey;
}

From source file:view.BackgroundImageController.java

public void saveBackgroundImage(String savePath) {
    if (resourceImagePath == null) {
        return;//  w ww  .  j  a v a 2 s . co  m
    }

    Path destPath = Paths.get(savePath + ".background");
    try {
        if (!resourceImagePath.startsWith("maps")) {
            Path sourcePath = Paths.get(resourceImagePath);
            Files.copy(sourcePath, destPath, StandardCopyOption.REPLACE_EXISTING);
        } else {
            InputStream backgroundFileStream = ClassLoader.getSystemResourceAsStream(resourceImagePath);
            Files.copy(backgroundFileStream, destPath, StandardCopyOption.REPLACE_EXISTING);
        }
    } catch (IOException ex) {
        Logger.getLogger(BackgroundImageController.class.getName()).log(Level.SEVERE, null, ex);
    }
}