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:cz.jirutka.spring.unboundid.InMemoryDirectoryServerFactoryBean.java

public InMemoryDirectoryServer getObject() throws LDAPException, LDIFException, IOException {
    List<Schema> schemas = new ArrayList<>(schemaFiles.size() + 1);
    String[] baseDNsArray = baseDNs.toArray(new String[0]);
    InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(baseDNsArray);

    config.addAdditionalBindCredentials(BIND_DN, BIND_PASSWORD);

    if (loadDefaultSchemas) {
        schemas.add(Schema.getDefaultStandardSchema());
    }//from  w w  w  .  j a va 2s . co  m
    for (Resource resource : schemaFiles) {
        schemas.add(Schema.getSchema(resource.getFile()));
    }
    Schema mergedSchema = Schema.mergeSchemas(schemas.toArray(new Schema[schemas.size()]));
    config.setSchema(mergedSchema);

    server = new InMemoryDirectoryServer(config);

    for (Resource resource : ldifFiles) {
        server.importFromLDIF(false, new LDIFReader(resource.getFile()));
    }
    server.startListening();

    return server;
}

From source file:de.tudarmstadt.ukp.similarity.experiments.coling2012.util.StopwordFilter.java

@SuppressWarnings("unchecked")
@Override// w  w  w.j a v  a  2 s  . c o m
public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);

    try {
        annotationType = (Class<? extends Annotation>) Class.forName(annotationTypeName);
    } catch (ClassNotFoundException e) {
        throw new ResourceInitializationException(e);
    }

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

    File f;
    try {
        f = res.getFile();
    } catch (IOException e) {
        throw new ResourceInitializationException(e);
    }

    try {
        loadStopwords(new FileInputStream(f));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:org.slc.sli.ingestion.tool.OfflineToolTest.java

/**
 *
 * @param dir/*from  w ww . ja va 2s.c o m*/
 *            : the path of the test data
 * @param target
 *            : the target string to be verify in the log file
 * @throws Throwable
 */
void toolTest(String dir, String target) throws Throwable {
    Resource fileResource = new ClassPathResource(dir);
    String[] args = new String[1];
    try {
        args[0] = fileResource.getFile().toString();
    } catch (IOException e) {
        fail("IO Exception");
    }
    try {
        PrivateAccessor.invoke(offlineTool, "start", new Class[] { args.getClass() }, new Object[] { args });
    } catch (IOException e) {
        fail("IO Exception from main");
    }
}

From source file:slina.mb.utils.LogFileReaderImpl.java

@Override
public List<String> readFile(String fileName) {

    List<String> lines = new ArrayList<String>();

    try {/*ww  w. ja v a  2 s. com*/

        long before = System.currentTimeMillis();

        File file = new File(fileName);

        if (!file.isFile()) {

            if (this.checkClassPath) {

                Resource classPathResource = new ClassPathResource(fileName);
                file = classPathResource.getFile();
            }

        }

        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
        String line = reader.readLine();

        while (line != null) {
            lines.add(line);
            line = reader.readLine();
        }

        long after = System.currentTimeMillis();
        reader.close();
        LOGGER.info("conv. run took " + (after - before) + " ms, size = " + lines.size());
        return lines;

    } catch (IOException e) {
        LOGGER.error(e);
        return lines;
    }

}

From source file:org.mitre.jdbc.datasource.util.SqlFileParser.java

private String processResource(Resource res) throws IOException {
    StringBuilder sql = new StringBuilder();
    File resourceFile = res.getFile();
    stateStack.push(State.INIT);//from   w  w w .j a  v a  2  s .  co  m
    processFile(resourceFile, sql);
    stateStack.pop();

    logger.debug(" SQL:: " + sql);

    return sql.toString();
}

From source file:com.fredhopper.core.connector.index.impl.DefaultIndexer.java

private File createFileDirectory(final Resource dataDirectoryResource) throws IOException {

    return FileUtils.createRandomDirectory(dataDirectoryResource.getFile());

}

From source file:fr.acxio.tools.agia.io.AbstractFileOperations.java

protected void removeFile(Resource sOriginFile) throws IOException {
    FileUtils.forceDelete(sOriginFile.getFile());
}

From source file:org.unidle.service.LocationServiceImpl.java

@Autowired
public LocationServiceImpl(@Value("${unidle.maxmind.database}") final Resource database,
        @Value("#{'${unidle.internal.ips}'.split(',')}") final Set<String> internalIps) throws IOException {
    this(database.getFile(), internalIps);
}

From source file:com.dubic.dc.dev.assist.services.ModuleService.java

private List<ModFile> loadFilesFromJson(Resource r) throws IOException {
    File f = r.getFile();
    Type listType = new TypeToken<ArrayList<ModFile>>() {
    }.getType();/*from   www.  j  av a 2  s .  co  m*/

    return new Gson().fromJson(FileUtils.readFileToString(f), listType);

}

From source file:org.paxml.tag.AbstractPaxmlEntity.java

@Override
public boolean isModified() {
    Resource res = getResource().getSpringResource();
    if (!res.exists()) {
        return true;
    }//ww w  .  j a v a 2s.  c  o  m
    final File file;
    try {
        file = res.getFile();

    } catch (IOException e) {
        // if file is not obtainable, it is not modifiable.
        return false;
    }
    return !file.exists() || file.lastModified() != timestamp;
}