List of usage examples for java.io File getCanonicalPath
public String getCanonicalPath() throws IOException
From source file:io.cloudslang.lang.compiler.SlangSource.java
private static String getCanonicalFilePath(File file) { String filePath;//from w ww . ja va2s . c o m try { filePath = file.getCanonicalPath(); } catch (IOException e) { throw new RuntimeException("There was a problem reading the file path for: " + file.getName(), e); } return filePath; }
From source file:com.junoyoon.BullsUtil.java
/** * Make path to file form.//w w w. j a v a 2 s. c om * * @param path * @return normalized path */ public static String normalizePath(File path) { try { return normalizePath(path.getCanonicalPath()); } catch (IOException e) { return normalizePath(path.getAbsolutePath()); } }
From source file:org.mycontroller.standalone.scripts.McScript.java
@JsonIgnore public static McScript getMcScript(String scriptFileName) throws IllegalAccessException, IOException { File scriptFile = McScriptEngineUtils.getScriptFile(scriptFileName); return McScript.builder().extension(FilenameUtils.getExtension(scriptFile.getCanonicalPath())) .name(scriptFile.getCanonicalPath()).build(); }
From source file:Zip.java
/** * Create a OutputStream on a given file, transparently compressing the data * to a Zip file whose name is the provided file path, with a ".zip" * extension added.//from w ww. j a va 2 s . c o m * * @param file the file (with no zip extension) * * @return a OutputStream on the zip entry */ public static OutputStream createOutputStream(File file) { try { String path = file.getCanonicalPath(); FileOutputStream fos = new FileOutputStream(path + ".zip"); ZipOutputStream zos = new ZipOutputStream(fos); ZipEntry ze = new ZipEntry(file.getName()); zos.putNextEntry(ze); return zos; } catch (FileNotFoundException ex) { System.err.println(ex.toString()); System.err.println(file + " not found"); } catch (Exception ex) { System.err.println(ex.toString()); } return null; }
From source file:Zip.java
/** * Create a Writer on a given file, transparently compressing the data to a * Zip file whose name is the provided file path, with a ".zip" extension * added./*w w w. j a va 2s. co m*/ * * @param file the file (with no zip extension) * * @return a writer on the zip entry */ public static Writer createWriter(File file) { try { String path = file.getCanonicalPath(); FileOutputStream fos = new FileOutputStream(path + ".zip"); ZipOutputStream zos = new ZipOutputStream(fos); ZipEntry ze = new ZipEntry(file.getName()); zos.putNextEntry(ze); return new OutputStreamWriter(zos); } catch (FileNotFoundException ex) { System.err.println(ex.toString()); System.err.println(file + " not found"); } catch (Exception ex) { System.err.println(ex.toString()); } return null; }
From source file:com.schnobosoft.semeval.cortical.PrintCorrelations.java
private static void saveCorrelations(File inputFile) throws IOException { assert inputFile.getName().startsWith(INPUT_FILE_PREFIX); File gsFile = new File(inputFile.getCanonicalPath().replace(INPUT_FILE_PREFIX, GS_FILE_PREFIX)); List<Optional> gs = readScoresFile(gsFile); File targetFile = new File(inputFile.getCanonicalPath() + ".cortical.scores"); BufferedWriter writer = new BufferedWriter(new FileWriter(targetFile)); LOG.info("Writing scores to " + targetFile); for (Retina retinaName : Retina.values()) { for (Measure correlationMeasure : Measure.values()) { File outputFile = getOutputFile(inputFile, correlationMeasure, retinaName); if (outputFile.exists()) { List<Optional> scores = readScoresFile(outputFile); double pearson = getPearson(gs, scores); writer.write(String.format("Pearson correlation (%s, %s):\t%.4f%n", retinaName.name().toLowerCase(), correlationMeasure, pearson)); } else { LOG.warn("Output file not found: " + outputFile); }//from w ww . ja va 2s.c om } } writer.close(); }
From source file:Main.java
/** * Resolves the relative path of the specified artifact * * @param outputDirectory typically the parent directory of the directory containing the makefile * @param file/*from w w w. ja v a 2 s.c o m*/ * @return */ protected static String resolveRelativePath(File outputDirectory, File file) throws IOException { String resolvedPath = file.getCanonicalPath(); String strOutputDirectoryPath = outputDirectory.getCanonicalPath(); String strFilePath = file.getCanonicalPath(); //System.out.println( "Resolving " + strFilePath + " against " + strOutputDirectoryPath ); if (strFilePath.startsWith(strOutputDirectoryPath)) { // Simple case where file is in a subdirectory of outputDirectory resolvedPath = strFilePath.substring(strOutputDirectoryPath.length() + 1); } else { // Look for commonality in paths List<String> outputDirectoryPathParts = splitPath(outputDirectory.getCanonicalFile()); List<String> filePathParts = splitPath(file.getCanonicalFile()); int commonDepth = 0; int maxCommonDepth = Math.min(outputDirectoryPathParts.size(), filePathParts.size()); for (int i = 0; (i < maxCommonDepth) && outputDirectoryPathParts.get(i).equals(filePathParts.get(i)); i++) { commonDepth++; } // If there is a common root build a relative path between the common roots if (commonDepth > 0) { final StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(".."); for (int i = 0; i < outputDirectoryPathParts.size() - commonDepth - 1; i++) { stringBuilder.append(File.separator); stringBuilder.append(".."); } for (int i = commonDepth; i < filePathParts.size(); i++) { stringBuilder.append(File.separator); stringBuilder.append(filePathParts.get(i)); } resolvedPath = stringBuilder.toString(); } else { if (IS_WINDOWS) { // Windows has no common root directory, cannot resolve a path // across drives so ... throw new IOException("Unable to resolve relative path across windows drives"); } // no intersection between paths so calculate a path via the root directory final StringBuilder stringBuilder = new StringBuilder(); File depthCheck = outputDirectory.getParentFile(); while (depthCheck != null) { if (stringBuilder.length() > 0) { stringBuilder.append(File.separator); } stringBuilder.append(".."); depthCheck = depthCheck.getParentFile(); } resolvedPath = stringBuilder.toString() + strFilePath; } } //System.out.println( "resolvedPath = " + resolvedPath ); return resolvedPath; }
From source file:Zip.java
/** * Create a InputStream on a given file, by looking for a zip archive whose * path is the file path with ".zip" appended, and by reading the first * entry in this zip file.//from w w w . j ava 2s .c o m * * @param file the file (with no zip extension) * * @return a InputStream on the zip entry */ public static InputStream createInputStream(File file) { try { String path = file.getCanonicalPath(); //ZipFile zf = new ZipFile(path + ".zip"); ZipFile zf = new ZipFile(path); for (Enumeration entries = zf.entries(); entries.hasMoreElements();) { ZipEntry entry = (ZipEntry) entries.nextElement(); return zf.getInputStream(entry); } } catch (FileNotFoundException ex) { System.err.println(ex.toString()); System.err.println(file + " not found"); } catch (IOException ex) { System.err.println(ex.toString()); } return null; }
From source file:Zip.java
/** * Create a Reader on a given file, by looking for a zip archive whose path * is the file path with ".zip" appended, and by reading the first entry in * this zip file.// w ww .j av a 2s.c om * * @param file the file (with no zip extension) * * @return a reader on the zip entry */ public static Reader createReader(File file) { try { String path = file.getCanonicalPath(); ZipFile zf = new ZipFile(path + ".zip"); for (Enumeration entries = zf.entries(); entries.hasMoreElements();) { ZipEntry entry = (ZipEntry) entries.nextElement(); InputStream is = zf.getInputStream(entry); return new InputStreamReader(is); } } catch (FileNotFoundException ex) { System.err.println(ex.toString()); System.err.println(file + " not found"); } catch (IOException ex) { System.err.println(ex.toString()); } return null; }
From source file:io.wcm.devops.maven.nodejsproxy.resource.TestContext.java
static MavenProxyConfiguration getConfiguration() { ConfigurationFactory factory = new ConfigurationFactory<MavenProxyConfiguration>( MavenProxyConfiguration.class, null, OBJECT_MAPPER, "override"); try {// w w w . j ava 2 s .c o m File configFile = new File("config.yml"); if (!configFile.exists()) { throw new RuntimeException("Configuration file not found: " + configFile.getCanonicalPath()); } return (MavenProxyConfiguration) factory.build(new File("config.yml")); } catch (IOException | ConfigurationException ex) { throw new RuntimeException(ex); } }