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:se.uu.it.cs.recsys.dataloader.correction.CourseSelectionRecourseCorrecter.java

public static void main(String[] args) throws IOException {
    final String COURSE_SEL_REC_FILES_DIR = "file:C:\\Dev\\yong\\CourseRecommenderParent\\CourseRecommenderDataLoader\\src\\main\\resources\\data_source\\course_selection_records";

    Resource courseSelectionDir = new FileSystemResource(COURSE_SEL_REC_FILES_DIR);

    File[] recordFiles = courseSelectionDir.getFile().listFiles();

    Arrays.stream(recordFiles).forEach(file -> {
        try {/*from   w  ww.  j  a v a  2 s. co m*/
            correctCourseName(file, CourseNameCorrectionGenerator.getWrongToCorrectNamePairs());
        } catch (IOException ex) {
            LOGGER.error("Failed to correct names in file.{}", ex);
        }
    });
}

From source file:de.alpharogroup.duplicate.files.panels.progressbar.ImagePanelTest.java

/**
 * The main method.//from w w w . j  a v  a 2 s .  co m
 *
 * @param args the arguments
 */
public static void main(String[] args) {
    final JFrame frame = new JFrame();
    frame.addWindowListener(new CloseWindow());
    frame.setTitle("ImagePanelTest");

    ApplicationContext ctx = SpringApplicationContext.getInstance().getApplicationContext();
    Resource resource = ctx.getResource("classpath:images/EngineHierarchy.PNG");

    Resource log4jconfig = ctx.getResource("classpath:conf/log4j/log4jconfig.xml");

    try {
        DOMConfigurator.configure(log4jconfig.getURL());
    } catch (FactoryConfigurationError e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    File imageFile = null;
    try {
        imageFile = resource.getFile();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    BufferedImage image = null;
    try {
        image = javax.imageio.ImageIO.read(imageFile);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    ImagePanel pnlIconPanel = new ImagePanel(image);
    frame.add(pnlIconPanel);
    frame.setBounds(0, 0, 534, 336);
    frame.setVisible(true);
}

From source file:org.guzz.web.context.spring.GuzzContextBeanFactory.java

public static GuzzContext createGuzzContext(Resource springResource) throws Exception {
    File file = springResource.getFile();

    if (file == null) {
        throw new IOException("file is null. spring resource:" + springResource);
    }//from  w  w  w  . j a va 2s  . c o  m

    return new Configuration(file.getAbsolutePath()).newGuzzContext();
}

From source file:com.bootcamp.utils.FreeMarkers.java

public static Configuration buildConfiguration(String directory) throws IOException {
    Configuration cfg = new Configuration();
    Resource path = new DefaultResourceLoader().getResource(directory);
    cfg.setDirectoryForTemplateLoading(path.getFile());
    return cfg;/*from ww  w  .  j  a  va 2  s . co m*/
}

From source file:com.wavemaker.commons.util.ConversionUtils.java

public static List<File> convertToFileList(List<Resource> resources) {
    List<File> files = new ArrayList<File>();
    for (Resource resource : resources) {
        try {//from   w  w w  .ja  va2  s  .c  o  m
            files.add(resource.getFile());
        } catch (IOException ex) {
            throw new WMRuntimeException(ex);
        }
    }
    return files;
}

From source file:com.univocity.app.utils.FileFinder.java

public static File findFile(String path) {
    Resource resource = new ClassPathResource(path);
    File file;/* ww w.java 2s  .c  o m*/
    try {
        file = resource.getFile();
    } catch (IOException e) {
        file = new File(path);
        if (!file.exists()) {
            //we are not including the resources into the jars
            //this is needed to find the resources when executing from the IDE & test cases.
            file = new File("src/main/resources/" + path);
        }
    }

    if (file == null || !file.exists()) {
        throw new IllegalArgumentException("Unable to find file specified by path: " + path);
    }

    return file;
}

From source file:de.tudarmstadt.ukp.dkpro.spelling.experiments.data.util.DataUtil.java

public static Map<String, String> getAllDatasets(String path, String[] extensions) throws IOException {

    Map<String, String> datasetMap = new HashMap<String, String>();

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    for (Resource resource : resolver.getResources(path)) {
        for (File datasetFile : FileUtils.listFiles(resource.getFile(), extensions, true)) {
            datasetMap.put(datasetFile.getAbsolutePath(), datasetFile.getParentFile().getName());
        }/*from  w  w  w .j ava2  s .  c o m*/
    }

    return datasetMap;
}

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

@BeforeClass
public static void init() throws IOException {
    Resource resource = new ClassPathResource("featuremodel");
    model = new FeatureModel(resource.getFile());
}

From source file:com.xyxy.platform.modules.extension.tools.FreeMarkers.java

/**
 * ??.//from   w ww.j  a va2  s  .c  om
 */
public static Configuration buildConfiguration(String directory) throws IOException {
    Configuration cfg = new Configuration();
    Resource path = new DefaultResourceLoader().getResource(directory);
    cfg.setDirectoryForTemplateLoading(path.getFile());
    return cfg;
}

From source file:com.adaptc.mws.plugins.testing.support.PluginsResourceUtils.java

/**
 * Gets the class name of the specified resource
 *
 * @param resource The Spring Resource//  ww  w .  jav a 2s.com
 * @return The class name or null if the resource is not a
 */
public static String getClassName(Resource resource) {
    try {
        return getClassName(resource.getFile().getAbsolutePath());
    } catch (IOException e) {
        return null;
    }
}