List of usage examples for org.springframework.core.io Resource getFile
File getFile() throws IOException;
From source file:org.codehaus.griffon.commons.GriffonResourceUtils.java
/** * Returns the class name for a Griffon resource * * @param resource The Spring Resource//from w ww . j av a2 s . c o m * @return The class name or null if the resource is not a Griffon class */ public static String getClassName(Resource resource) { try { return getClassName(resource.getFile().getAbsolutePath()); } catch (IOException e) { throw new IllegalStateException( "I/O error reading class name from resource [" + resource + "]: " + e.getMessage(), e); } }
From source file:org.dspace.servicemanager.spring.ResourceFinder.java
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 {// w w w . ja v a 2 s.co m 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.config.SystemProperties.java
public static void reload() { if (!loading.get()) { try {/*from w w w . j av a2 s .co m*/ loading.set(true); Resource resource = new ClassPathResource(Constants.SYSTEM_CONFIG); ROOT_CONF_PATH = resource.getFile().getParentFile().getParentFile().getAbsolutePath(); ROOT_APP_PATH = resource.getFile().getParentFile().getParentFile().getParentFile() .getAbsolutePath(); System.out.println("load system config:" + resource.getFile().getAbsolutePath()); } catch (IOException ex) { ex.printStackTrace(); throw new RuntimeException(ex); } finally { loading.set(false); } } }
From source file:org.jamwiki.utils.ResourceUtil.java
/** * Given a file name for a file that is located somewhere in the application * classpath, return a File object representing the file. * * @param filename The name of the file (relative to the classpath) that is * to be retrieved.// w ww . j av a 2 s .c o m * @return A file object representing the requested filename. Note that the * file name is not guaranteed to match the filename passed to this method * since (for example) the file might be found in a JAR file and thus will * need to be copied to a temporary location for reading. * @throws IOException Thrown if the classloader can not be found or if * the file can not be found in the classpath. */ public static File getClassLoaderFile(String filename) throws IOException { // note that this method is used when initializing logging, so it must // not attempt to log anything. Resource resource = new ClassPathResource(filename); try { return resource.getFile(); } catch (IOException e) { // does not resolve to a file, possibly a JAR URL } InputStream is = null; FileOutputStream os = null; try { // url exists but file cannot be read, so perhaps it's not a "file:" url (an example // would be a "jar:" url). as a workaround, copy the file to a temp file and return // the temp file. String tempFilename = RandomStringUtils.randomAlphanumeric(20); File file = File.createTempFile(tempFilename, null); is = resource.getInputStream(); os = new FileOutputStream(file); IOUtils.copy(is, os); return file; } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); } }
From source file:org.dspace.servicemanager.spring.ResourceFinder.java
public static File getFile(String path) { Resource r = getResource(path); File f = null;/*from w w w . j ava 2 s . c o m*/ try { f = r.getFile(); } catch (IOException e) { throw new RuntimeException("Failed to get file for: " + r.getFilename(), e); } return f; }
From source file:org.paxml.util.PaxmlUtils.java
public static String getResourceFile(Resource res) { try {//from w ww.j a v a 2 s .co m return res.getFile().getAbsolutePath(); } catch (IOException e) { return res.getFilename(); } }
From source file:org.jspringbot.keyword.expression.ELUtils.java
private static Properties getInProperties(String location) throws IOException { if (inCache.containsKey(location)) { return inCache.get(location); }// www.j av a 2s. co m ResourceEditor editor = new ResourceEditor(); editor.setAsText(location); Resource resource = (Resource) editor.getValue(); File inFile = resource.getFile(); Properties properties = new Properties(); properties.load(new FileReader(inFile)); inCache.put(location, properties); return properties; }
From source file:org.dkpro.similarity.experiments.sts2013baseline.util.Evaluator.java
private static void computePearsonCorrelation(Mode mode, Dataset dataset) throws IOException { File expScoresFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".csv"); String gsScoresFilePath = GOLDSTANDARD_DIR + "/" + mode.toString().toLowerCase() + "/" + "STS.gs." + dataset.toString() + ".txt"; PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver(); Resource res = r.getResource(gsScoresFilePath); File gsScoresFile = res.getFile(); List<Double> expScores = new ArrayList<Double>(); List<Double> gsScores = new ArrayList<Double>(); List<String> expLines = FileUtils.readLines(expScoresFile); List<String> gsLines = FileUtils.readLines(gsScoresFile); for (int i = 0; i < expLines.size(); i++) { expScores.add(Double.parseDouble(expLines.get(i))); gsScores.add(Double.parseDouble(gsLines.get(i))); }//from w ww . ja v a 2s .com double[] expArray = ArrayUtils.toPrimitive(expScores.toArray(new Double[expScores.size()])); double[] gsArray = ArrayUtils.toPrimitive(gsScores.toArray(new Double[gsScores.size()])); PearsonsCorrelation pearson = new PearsonsCorrelation(); Double correl = pearson.correlation(expArray, gsArray); FileUtils.writeStringToFile( new File(OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".txt"), correl.toString()); }
From source file:org.dkpro.similarity.experiments.sts2013.util.Evaluator.java
@SuppressWarnings("unchecked") private static void computePearsonCorrelation(Mode mode, Dataset dataset) throws IOException { File expScoresFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".csv"); String gsScoresFilePath = GOLDSTANDARD_DIR + "/" + mode.toString().toLowerCase() + "/" + "STS.gs." + dataset.toString() + ".txt"; PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver(); Resource res = r.getResource(gsScoresFilePath); File gsScoresFile = res.getFile(); List<Double> expScores = new ArrayList<Double>(); List<Double> gsScores = new ArrayList<Double>(); List<String> expLines = FileUtils.readLines(expScoresFile); List<String> gsLines = FileUtils.readLines(gsScoresFile); for (int i = 0; i < expLines.size(); i++) { expScores.add(Double.parseDouble(expLines.get(i))); gsScores.add(Double.parseDouble(gsLines.get(i))); }/* w w w .j ava 2s. c o m*/ double[] expArray = ArrayUtils.toPrimitive(expScores.toArray(new Double[expScores.size()])); double[] gsArray = ArrayUtils.toPrimitive(gsScores.toArray(new Double[gsScores.size()])); PearsonsCorrelation pearson = new PearsonsCorrelation(); Double correl = pearson.correlation(expArray, gsArray); FileUtils.writeStringToFile( new File(OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".txt"), correl.toString()); }
From source file:org.paxml.table.csv.CsvTable.java
private static File getWriterFile(Resource res) { try {//from w w w . j a v a2s . c o m File f = res.getFile(); return PaxmlUtils.getSiblingFile(f, "." + seq.getNextValue(f.getAbsolutePath()) + ".write", true); } catch (IOException e) { return null; } }