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

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

Introduction

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

Prototype

File getFile() throws IOException;

Source Link

Document

Return a File handle for this resource.

Usage

From source file:org.sakaiproject.genericdao.springutil.ResourceFinder.java

/**
 * Resolves a list of paths into resources within the current classloader
 * @param paths a list of paths to resources (org/sakaiproject/mystuff/Thing.xml)
 * @return an array of File objects/*w w  w .ja  v  a2 s  .c  o  m*/
 */
public static File[] getFiles(List<String> paths) {
    List<Resource> rs = makeResources(paths);
    File[] files = new File[rs.size()];
    for (int i = 0; i < rs.size(); i++) {
        Resource r = rs.get(i);
        try {
            files[i] = r.getFile();
        } catch (IOException e) {
            throw new RuntimeException("Failed to get file for: " + r.getFilename(), e);
        }
    }
    return files;
}

From source file:com.glaf.core.context.ApplicationContext.java

public static String getAppPath() {
    if (appPath == null) {
        try {/*from  w ww. j av a 2  s.c  o m*/
            Resource resource = new ClassPathResource("/glaf.properties");
            appPath = resource.getFile().getParentFile().getParentFile().getParentFile().getAbsolutePath();
            logger.info("app path:" + appPath);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return appPath;
}

From source file:scala.c24.demo.java.C24DemoUtils.java

public static Document getDocument(Resource resource) throws Exception {
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(resource.getFile());

    return document;

}

From source file:com.wavemaker.tools.project.LauncherHelper.java

/**
 * NOTE: this method is called from the Launcher. DO NOT CHANGE TO NEW RESOURCE API.
 * /*w ww  .  j a v a2  s.c  om*/
 * @param waveMakerHome
 * @throws IOException
 */
public static void doUpgrade(java.io.File waveMakerHomeFile) throws IOException {
    Resource waveMakerHome = new FileSystemResource(waveMakerHomeFile);
    VersionInfo vi = LocalStudioConfiguration.getCurrentVersionInfo();
    LocalStudioConfiguration.setRegisteredVersionInfo(vi);

    Resource oldWMHome = LocalStudioConfiguration.staticGetWaveMakerHome();
    if (0 != oldWMHome.getFile().compareTo(waveMakerHome.getFile())) {
        FileUtils.copyDirectory(oldWMHome.getFile(), waveMakerHome.getFile());
        LocalStudioConfiguration.setWaveMakerHome(waveMakerHome);
    }
}

From source file:org.dkpro.similarity.experiments.sts2013.util.Features2Arff.java

public static void toArffFile(Mode mode, Dataset... datasets) throws IOException {
    for (Dataset dataset : datasets) {
        String path = GOLDSTANDARD_DIR + "/" + mode.toString().toLowerCase() + "/STS.gs." + dataset.toString()
                + ".txt";

        PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver();
        Resource res = r.getResource(path);

        toArffFile(mode, dataset, res.getFile());
    }/* w  ww  . j a v a 2  s.  com*/
}

From source file:org.haedus.datatypes.phonetic.FeatureModelTest.java

@BeforeClass
public static void init() throws IOException {
    //                                  0     1    2    3    4    5    6    7    8    9   10    11   12   13   14   15    16   17
    //                                son   con  vot  rel  nas  lat  lab  rnd  lin  lam  hgt   frn  bck  atr  rad  air   glt  len
    Collections.addAll(G_FEATURES, 0.0, -1.0, NAN, 1.0, NAN, NAN, NAN, NAN, NAN, NAN, 1.0, -1.0, 1.0, NAN, NAN,
            NAN, 0.0, 0.0);//from   w ww  .j  a v a 2s. com
    Collections.addAll(GH_FEATURES, 0.0, -1.0, 1.0, 1.0, NAN, NAN, NAN, NAN, NAN, NAN, 1.0, -1.0, 1.0, NAN, NAN,
            NAN, 0.0, 0.0);
    Collections.addAll(GJ_FEATURES, 0.0, -1.0, NAN, 1.0, NAN, NAN, NAN, NAN, NAN, NAN, 1.0, 1.0, 1.0, NAN, NAN,
            NAN, 0.0, 0.0);
    Collections.addAll(KWH_FEATURES, 0.0, -1.0, 1.0, 1.0, NAN, NAN, NAN, 1.0, NAN, NAN, 1.0, -1.0, 1.0, NAN,
            NAN, NAN, -3.0, 0.0);
    Collections.addAll(KKWH_FEATURES, 0.0, -1.0, 1.0, 1.0, NAN, NAN, NAN, 1.0, NAN, NAN, 1.0, -1.0, 1.0, NAN,
            NAN, NAN, -3.0, 1.0);

    Resource resource = new ClassPathResource("featuremodel");
    model = new FeatureModel(resource.getFile());
}

From source file:com.googlecode.flyway.core.util.ResourceUtils.java

/**
 * Retrieves the location of a resource on disk.
 *
 * @param resource The resource to evaluate.
 * @return The location of the resource on disk.
 *//*from w w w. j a v  a2 s .c  o  m*/
public static String getResourceLocation(Resource resource) {
    try {
        return resource.getURL().toExternalForm();
    } catch (IOException e) {
        try {
            return resource.getFile().getAbsolutePath();
        } catch (IOException e1) {
            return resource.getFilename();
        }
    }
}

From source file:org.springframework.hateoas.VndErrorsMarshallingTest.java

private static String readFile(org.springframework.core.io.Resource resource) throws IOException {

    FileInputStream stream = new FileInputStream(resource.getFile());

    try {//  www  .j  a va2s .c  o  m
        FileChannel fc = stream.getChannel();
        MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
        return Charset.defaultCharset().decode(bb).toString();
    } finally {
        stream.close();
    }
}

From source file:magoffin.matt.sobriquet.test.DirectoryServerStatement.java

public static InMemoryDirectoryServer startServer(final int port, final String baseDN, final String authDN,
        final String authPassword, final String[] ldifFiles, final String[] schemaFiles)
        throws LDIFException, LDAPException, IOException {
    final InMemoryListenerConfig listenerConfig = InMemoryListenerConfig.createLDAPConfig("default", port);
    final InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(new DN(baseDN));
    config.setListenerConfigs(listenerConfig);
    config.addAdditionalBindCredentials(authDN, authPassword);
    if (schemaFiles != null && schemaFiles.length > 0) {
        // merge custom schemas with default standard schemas
        List<File> files = new ArrayList<File>(schemaFiles.length);
        for (String name : schemaFiles) {
            // try fs first
            Resource r = new FileSystemResource(name);
            if (r.exists()) {
                files.add(r.getFile());
            } else {
                r = new ClassPathResource(name);
                if (r.exists()) {
                    files.add(r.getFile());
                }/*from w ww . j a va  2 s . co  m*/
            }
        }
        if (files.size() > 0) {
            config.setSchema(Schema.mergeSchemas(Schema.getDefaultStandardSchema(), Schema.getSchema(files)));
        }
    }
    final InMemoryDirectoryServer server = new InMemoryDirectoryServer(config);
    server.add(new Entry(baseDN, new Attribute("objectclass", "domain", "top")));
    server.startListening();
    if (ldifFiles != null) {
        for (final String ldifFile : ldifFiles) {
            DirectoryServerUtils.loadData(server, ldifFile);
        }
    }
    return server;
}

From source file:net.javacrumbs.smock.axis2.server.SmockServer.java

public static ConfigurationContext createConfigurationContextFromResource(Resource axis2Repository) {
    try {//from  ww  w .  j  a v  a2  s. c  om
        Assert.notNull(axis2Repository, "axis2Repository can not be null");
        return ConfigurationContextFactory
                .createConfigurationContextFromFileSystem(axis2Repository.getFile().getAbsolutePath());
    } catch (Exception e) {
        throw new IllegalStateException("Can not load Axis2 repository.", e);
    }
}