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:com.hippikon.io.FileUtil.java

/**
 * Returns a File object located on the system classpath by a specified
 * filename. If the file is not found in a classpath directory, the "fileutil.search.path"
 * environment variable is checked if set.<p>
 *
 * The filename passed as a method parameter should and not 
 * contain any path information (e.g., "myfile.txt").<p>
 *
 * @param filename a relative filename (e.g., myfile.txt)
 *
 * @exception FileNotFoundException thrown if the file could not be
 * found or a file reference obtained/*from  w w  w  .j a v  a  2s.  c o  m*/
 */
public static final File findFileInClasspath(String filename) throws IOException {
    ClassPathResource res = new ClassPathResource(filename);
    return res.getFile();
}

From source file:org.energyos.espi.common.test.FixtureFactory.java

public static String loadFixture(String path) throws IOException {
    ClassPathResource sourceFile = new ClassPathResource(path);
    return FileUtils.readFileToString(sourceFile.getFile());
}

From source file:org.energyos.espi.common.test.FixtureFactory.java

public static String newXML(String fileName) throws IOException {
    ClassPathResource sourceFile = new ClassPathResource(fileName);
    String xml = FileUtils.readFileToString(sourceFile.getFile());
    return xml;//from  www. jav a  2s. c  om
}

From source file:org.cloudfoundry.client.lib.SampleProjects.java

/**
 * Returns a bad spring application that will cause crashes.
 *
 * @return the bad-spring-app WAR file// w  w  w. j  a  v a2  s .  c  o  m
 * @throws IOException
 */
public static File badSpringApp() throws IOException {
    ClassPathResource cpr = new ClassPathResource("bad-spring-app.war");
    File file = cpr.getFile();
    assertTrue("Expected test app at " + file.getCanonicalPath(), file.exists());
    return file;
}

From source file:org.cloudfoundry.client.lib.SampleProjects.java

/**
 * Returns a simple spring application.//from  w w  w .ja v  a2 s .  co  m
 *
 * @return the simple-spring-app WAR file
 * @throws IOException
 */
public static File simpleSpringApp() throws IOException {
    ClassPathResource cpr = new ClassPathResource("simple-spring-app.war");
    File file = cpr.getFile();
    assertTrue("Expected test app at " + file.getCanonicalPath(), file.exists());
    return file;
}

From source file:org.cloudfoundry.client.lib.SampleProjects.java

/**
 * Returns a spring application using a file with a non-ascii name.
 *
 * @return the non-ascii-file-name WAR file
 * @throws IOException/*from  w ww.j a  v a2s.co m*/
 */
public static File nonAsciFileName() throws IOException {
    ClassPathResource cpr = new ClassPathResource("non-ascii-file-name.war");
    File file = cpr.getFile();
    assertTrue("Expected test app at " + file.getCanonicalPath(), file.exists());
    return file;
}

From source file:clear.cdb.support.test.AnnotationProcessorTestCompiler.java

private static Iterable<? extends JavaFileObject> getCompilationUnitOfClass(StandardJavaFileManager fileManager,
        String classToCompile) throws IOException {
    ClassPathResource resource = new ClassPathResource(classToCompile + ".java");
    return fileManager.getJavaFileObjectsFromFiles(Collections.singletonList(resource.getFile()));
}

From source file:com.google.api.ads.adwords.awalerting.AwAlerting.java

/**
 * Prints the sample properties file on the default output.
 *///from  ww w .ja  v a 2 s .  c om
private static void printSamplePropertiesFile() throws AlertConfigLoadException {
    System.out.println("File: aw-report-alerting-sample.properties example");
    ClassPathResource sampleFile = new ClassPathResource("aw-alerting-sample.properties");

    try {
        List<String> lines = Files.asCharSource(sampleFile.getFile(), Charset.defaultCharset()).readLines();
        for (String line : lines) {
            System.out.println(line);
        }
    } catch (IOException e) {
        throw new AlertConfigLoadException("Error reading sample properties file.", e);
    }
}

From source file:com.google.api.ads.adwords.awreporting.AwReporting.java

/**
 * Prints the sample properties file on the default output.
 *//*w w w  .  j  a  va 2s.c  o m*/
private static void printSamplePropertiesFile() {

    System.out.println("\n  File: aw-report-sample.properties example");
    ClassPathResource sampleFile = new ClassPathResource("aw-report-sample.properties");
    try {
        List<String> lines = Files.asCharSource(sampleFile.getFile(), Charset.defaultCharset()).readLines();
        for (String line : lines) {
            System.out.println(line);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.uimirror.auth.StartApp.java

private File getKeyStoreFile() throws IOException {
    ClassPathResource resource = new ClassPathResource("keystore");
    try {//from   w  ww  .ja v  a 2  s .  c om
        return resource.getFile();
    } catch (Exception ex) {
        File temp = File.createTempFile("keystore", ".tmp");
        FileCopyUtils.copy(resource.getInputStream(), new FileOutputStream(temp));
        return temp;
    }
}