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

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

Introduction

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

Prototype

@Override
public File getFile() throws IOException 

Source Link

Document

This implementation returns a File reference for the underlying class path resource, provided that it refers to a file in the file system.

Usage

From source file:nl.jteam.mahout.gettingstarted.datamodel.ResourceDataModelTest.java

@Test
public void testConstructor() throws IOException {
    ClassPathResource resource = new ClassPathResource("ratings.dat");
    FileDataModel fileDataModel = new FileDataModel(resource.getFile());

    ResourceDataModel resourceDataModel = new ResourceDataModel(resource);
    assertEquals(fileDataModel.getDataFile(), resourceDataModel.delegate.getDataFile());
}

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

@GET
@Path("/doc/")
public String doc() {
    ClassPathResource classPathResource = new ClassPathResource("com/geoapi/webview/doc.html");
    try {/*from   w  w w.jav  a 2 s.co m*/
        File file = classPathResource.getFile();
        return readFileAsString(file);
    } catch (IOException e) {
        e.printStackTrace();
    }
    String homepage = readFileAsString(classPathResource.getPath());
    return homepage;
}

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

@GET
@Path("css/{name}")
@Produces("text/css")
public String css(@PathParam("name") String name) {
    ClassPathResource classPathResource = new ClassPathResource("com/geoapi/webview/css/" + name);
    try {/*ww w  .j  a  va 2  s. co  m*/
        File file = classPathResource.getFile();
        return readFileAsString(file);
    } catch (IOException e) {
        e.printStackTrace();
    }
    String css = readFileAsString(classPathResource.getPath());
    return css;
}

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  ww  w . j  av  a 2  s  . co m
        File file = classPathResource.getFile();
        return readFileAsString(file);
    } catch (IOException e) {
        e.printStackTrace();
    }
    String homepage = readFileAsString(classPathResource.getPath());
    return homepage;
}

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

@GET
@Path("javascript/{name}")
@Produces("application/javascript")
public String javascript(@PathParam("name") String name) {
    ClassPathResource classPathResource = new ClassPathResource("com/geoapi/webview/javascript/" + name);
    try {// w w w  .j ava2 s  .  co  m
        File file = classPathResource.getFile();
        return readFileAsString(file);
    } catch (IOException e) {
        e.printStackTrace();
    }
    String css = readFileAsString(classPathResource.getPath());
    return css;
}

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

@GET
@Path("textures/planets/{name}")
@Produces("image/*")
public Response planetTextures(@PathParam("name") String name) {

    ClassPathResource classPathResource = new ClassPathResource("com/geoapi/webview/planets/" + name);
    try {/*  w  w w .  j  a  v a 2s  .co m*/
        File file = classPathResource.getFile();

        if (!file.exists()) {
            throw new WebApplicationException(404);
        }

        String mt = new MimetypesFileTypeMap().getContentType(file);
        return Response.ok(file, mt).build();
    } catch (IOException e) {
        e.printStackTrace();
        throw new WebApplicationException(404);
    }
}

From source file:nl.knaw.dans.common.lang.spring.UsernamePropertyPlaceholderConfigurer.java

public UsernamePropertyPlaceholderConfigurer() throws IOException {
    String filename = RESOURCE_PATH + System.getProperty("user.name") + ".properties";
    ClassPathResource resource = new ClassPathResource(filename);
    if (!resource.exists()) {
        resource = new ClassPathResource(DEFAULT_APP_PROPERTIES);
    }//from w  w  w.j  ava 2 s  .c o  m
    setLocation(resource);
    logger.info("Found application properties at " + resource.getFile().getAbsolutePath());
}

From source file:com.acmemotors.gf.support.GemfireLoaderTests.java

@Test
public void testIntegration() throws Exception {
    ArgumentCaptor<Journeys> capturedJourneys = ArgumentCaptor.forClass(Journeys.class);
    ClassPathResource inputFile = new ClassPathResource("/data/clusters.json");

    loader.run(inputFile.getFile().getAbsolutePath());

    verify(repository, times(3)).save(capturedJourneys.capture());

    List<Journeys> results = capturedJourneys.getAllValues();

    assertEquals(3, results.size());/*  ww  w .  j av a2 s  .c  om*/

    Journeys curVin = results.get(0);

    // Let's go back...to the FUTURE!
    assertEquals("SCEDT26T0BD007019", curVin.getVin());
    assertEquals(4, curVin.getDestinations().size());
    validateLocation("", "", 32.952136134697362, -96.820293184407973, curVin.getDestinations().get(0));
    validateLocation("", "", 32.775359756851508, -96.804928235059336, curVin.getDestinations().get(1));
    validateLocation("", "", 32.943392560883851, -96.649327721702406, curVin.getDestinations().get(2));
    validateLocation("", "", 32.968117331986988, -96.927546300480572, curVin.getDestinations().get(3));

    curVin = results.get(1);

    // 53
    assertEquals("4724069", curVin.getVin());
    assertEquals(1, curVin.getDestinations().size());
    validateLocation("", "", 33.9336949, -117.2768647, curVin.getDestinations().get(0));

    curVin = results.get(2);

    // Don't hassle the Hoff
    assertEquals("1G2AW87HXCL527449", curVin.getVin());
    assertEquals(2, curVin.getDestinations().size());
    validateLocation("", "", 34.165145, -118.508207, curVin.getDestinations().get(0));
    validateLocation("", "", 32.775359756851508, -96.804928235059336, curVin.getDestinations().get(1));
}

From source file:org.architecturerules.configuration.AbstractConfigurationFactoryTest.java

public void testGetConfigurationAsXmlFromAbsolutePath() throws IOException {

    final ClassLoader classLoader = getClass().getClassLoader();

    final ClassPathResource resource = new ClassPathResource("architecture-rules.xml", classLoader);

    // TODO find other ways to compute absolute path to configuration file
    final String filepath = resource.getFile().getAbsolutePath();
    factory.loadConfiguration(filepath);
}

From source file:org.joy.config.TypeMapping.java

public TypeMapping(String classPath) {
    ClassPathResource resource = new ClassPathResource(this.MAPING_FILE);

    try {/* ww w  .  ja  v a2 s  .c  o m*/
        //            this.mappginFile = classPath + MAPING_FILE;
        this.mappginFile = resource.getFile().getAbsolutePath();
    } catch (IOException e) {
        throw new Wrong(e);
    }

    typeMap = new HashMap<Integer, String>();
    fullTypeMap = new HashMap<Integer, String>();
}