Example usage for org.springframework.core.io ClassPathResource ClassPathResource

List of usage examples for org.springframework.core.io ClassPathResource ClassPathResource

Introduction

In this page you can find the example usage for org.springframework.core.io ClassPathResource ClassPathResource.

Prototype

public ClassPathResource(String path) 

Source Link

Document

Create a new ClassPathResource for ClassLoader usage.

Usage

From source file:com.w3ma.m3u8web.config.ConfigManager.java

public ConfigManager() throws IOException {
    final Resource resource = new ClassPathResource("configuration.json");
    final InputStream is = resource.getInputStream();
    final Reader reader = new InputStreamReader(is);
    appConfiguration = new Gson().fromJson(reader, AppConfiguration.class);
}

From source file:org.vincibean.salestaxes.jaxb.JaxbFactory.java

/**
 * Factory method, creates a {@link Marshaller} from the context given in the constructor; moreover, ensure that
 * the marshalled XML data is formatted with linefeeds and indentation.  
 * @return an {@link Optional} object which may or may not contain a {@link Marshaller}
 *///from   w ww.  ja va  2s  .c  om
public static Optional<Marshaller> createMarshaller(final Class<?> context) {
    try {
        Marshaller marshaller = JAXBContext.newInstance(context).createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setSchema(SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
                .newSchema(new ClassPathResource("receipt/Poiuyt.xsd").getFile()));
        marshaller.setEventHandler(new FoobarValidationEventHandler());
        return Optional.fromNullable(marshaller);
    } catch (JAXBException | SAXException | IOException e) {
        logger.warn("Exception on jaxb factory creation: ", e);
        return Optional.absent();
    }
}

From source file:org.atomserver.core.validators.RelaxNGContentValidatorTest.java

public void testSimpleSchema() throws Exception {
    RelaxNGValidator validator = new RelaxNGValidator();
    validator.setSchemaLocation(new ClassPathResource("test.rnc"));

    checkValidity(validator, "<foo xmlns='http://atomserver.org/test' id='1'><bar>hi</bar></foo>", false);
    checkValidity(validator, "<foo xmlns='http://atomserver.org/test' id='1'></foo>", true);
}

From source file:org.mybatis.spring.AbstractMyBatisSpringTest.java

@BeforeClass
public static void setupBase() throws Exception {
    // create an SqlSessionFactory that will use SpringManagedTransactions
    SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
    factoryBean/*ww w . j  av  a 2  s  .  c  o m*/
            .setMapperLocations(new Resource[] { new ClassPathResource("org/mybatis/spring/TestMapper.xml") });
    // note running without SqlSessionFactoryBean.configLocation set => default configuration
    factoryBean.setDataSource(dataSource);
    factoryBean.setPlugins(new Interceptor[] { executorInterceptor });

    exceptionTranslator = new MyBatisExceptionTranslator(dataSource, true);

    sqlSessionFactory = factoryBean.getObject();

    txManager = new DataSourceTransactionManager(dataSource);
}

From source file:org.ligoj.app.plugin.prov.aws.in.CsvForBeanEc2Test.java

@Test
public void readDedicatedHost() throws IOException {
    final BufferedReader reader = new BufferedReader(new InputStreamReader(
            new ClassPathResource("mock-server/aws/index-small-dedicated-host.csv").getInputStream()));
    Assertions.assertNull(new CsvForBeanEc2(reader).read());
}

From source file:org.canova.codec.reader.CodecReaderTest.java

@Test
public void testCodecReader() throws Exception {
    File file = new ClassPathResource("fire.mp4").getFile();
    SequenceRecordReader reader = new CodecRecordReader();
    Configuration conf = new Configuration();
    conf.set(CodecRecordReader.RAVEL, "true");
    conf.set(CodecRecordReader.START_FRAME, "160");
    conf.set(CodecRecordReader.TOTAL_FRAMES, "500");
    reader.initialize(new FileSplit(file));
    reader.setConf(conf);/*from   ww  w  .  j a v a 2s  .  c  o  m*/
    assertTrue(reader.hasNext());
    Collection<Collection<Writable>> record = reader.sequenceRecord();
    System.out.println(record.size());
}

From source file:com.geoapi.api.server.services.implementations.WebViewService.java

@GET
@Path("/")
public String homepage() {
    ClassPathResource classPathResource = new ClassPathResource("com/geoapi/webview/homepage.html");
    try {//from  www . j  a  v  a2 s .  c om
        File file = classPathResource.getFile();
        return readFileAsString(file);
    } catch (IOException e) {
        e.printStackTrace();
    }
    String homepage = readFileAsString(classPathResource.getPath());
    return homepage;
}

From source file:org.mongeez.MongeezTest.java

private Mongeez create(String path) {
    Mongeez mongeez = new Mongeez();
    mongeez.setFile(new ClassPathResource(path));
    mongeez.setMongo(mongo);//from  w w w.  j  a  v  a2 s.c o m
    mongeez.setDbName(dbName);
    mongeez.setVerbose(true);
    return mongeez;
}

From source file:com.clicktravel.cheddar.server.runtime.config.PropertiesConfigurationBuilder.java

private static void addResource(final List<Resource> resources, final String path) {
    resources.add(new ClassPathResource(path));
}

From source file:org.openhealthtools.openatna.audit.OpenAtnaPropertiesLoader.java

public void setLocation(Resource location) {
    String loc = AtnaFactory.getPropertiesLocation();
    if (loc != null && loc.length() > 0) {
        location = new ClassPathResource(loc);
    }// w  w w. jav  a  2 s  .c o m
    super.setLocation(location);
}