List of usage examples for java.io File getCanonicalPath
public String getCanonicalPath() throws IOException
From source file:net.semanticmetadata.lire.solr.AddImages.java
private static StringBuilder createAddDoc(File image) throws IOException { BufferedImage img = ImageIO.read(image); StringBuilder result = new StringBuilder(200); // result.append("<add>\n"); result.append("\t<doc>\n"); // id and file name ... result.append("\t\t<field name=\"id\">"); result.append(image.getCanonicalPath()); result.append("</field>\n"); result.append("\t\t<field name=\"title\">"); result.append(image.getName());/* www.j a v a 2 s .com*/ result.append("</field>\n"); // features: getFields(img, result, new ColorLayout(), "cl_hi", "cl_ha"); getFields(img, result, new EdgeHistogram(), "eh_hi", "eh_ha"); getFields(img, result, new JCD(), "jc_hi", "jc_ha"); getFields(img, result, new PHOG(), "ph_hi", "ph_ha"); getFields(img, result, new OpponentHistogram(), "oh_hi", "oh_ha"); // close doc ... result.append("\t</doc>\n"); // result.append("</add>"); return result; }
From source file:com.ibm.wala.cast.js.nodejs.NodejsRequireTargetSelector.java
/** * NODE_MODULES_PATHS(START)//from w w w .j a v a 2 s . c o m * 1. let PARTS = path split(START) * 2. let I = count of PARTS - 1 * 3. let DIRS = [] * 4. while I >= 0, * a. if PARTS[I] = "node_modules" CONTINUE * b. DIR = path join(PARTS[0 .. I] + "node_modules") * c. DIRS = DIRS + DIR * d. let I = I - 1 * 5. return DIRS * * @param d * @throws IOException */ private static List<File> nodeModulePaths(File rootDir, File d) throws IOException { LinkedList<File> dirs = new LinkedList<>(); while (d.getCanonicalPath().startsWith(rootDir.getCanonicalPath()) && d.toPath().getNameCount() > 0) { // 4.a. if (!d.getName().equals("node_modules")) { // 4.b. and 4.c. dirs.add(new File(d, "node_modules")); } // 4.d. d = d.getParentFile(); } return dirs; }
From source file:com.termmed.utils.ResourceUtils.java
/** * Gets the resources from directory.// www .j a v a2s. co m * * @param directory the directory * @param pattern the pattern * @return the resources from directory */ private static Collection<String> getResourcesFromDirectory(final File directory, final Pattern pattern) { final ArrayList<String> retval = new ArrayList<String>(); final File[] fileList = directory.listFiles(); for (final File file : fileList) { if (file.isDirectory()) { retval.addAll(getResourcesFromDirectory(file, pattern)); } else { try { final String fileName = file.getCanonicalPath(); final boolean accept = pattern.matcher(fileName).matches(); if (accept) { retval.add(fileName); } } catch (final IOException e) { throw new Error(e); } } } return retval; }
From source file:com.appunity.ant.Utils.java
protected static String obtainValidPath(Task task, String path, String name) { baseDir = task.getProject().getBaseDir(); if (path == null || "".equals(path)) { path = task.getProject().getProperty(name); }//from w ww . j ava 2 s . com if (path == null || "".equals(path)) { throw new BuildException("Can not find the path " + name + ":" + path); } try { File tempFile = new File(path); try { if (relativePath == null) { relativePath = new File("").getCanonicalPath(); } boolean contains = tempFile.getCanonicalPath().contains(relativePath); if (contains || path.startsWith(".")) { tempFile = new File(baseDir, path); } return tempFile.getCanonicalPath(); } catch (Exception e) { } return path; } catch (Exception e) { throw new BuildException("Can not find the path " + name + ":" + path); } }
From source file:com.connexta.arbitro.TestUtil.java
/** * This creates the expected XACML response from a file * * @param rootDirectory root directory of the response files * @param versionDirectory version directory of the response files * @param responseId response file name * @return ResponseCtx or null if any error *///www .j a v a2 s . co m public static ResponseCtx createResponse(String rootDirectory, String versionDirectory, String responseId) { File file = new File("."); try { String filePath = file.getCanonicalPath() + File.separator + TestConstants.RESOURCE_PATH + File.separator + rootDirectory + File.separator + versionDirectory + File.separator + TestConstants.RESPONSE_DIRECTORY + File.separator + responseId; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setIgnoringComments(true); factory.setNamespaceAware(true); factory.setValidating(false); DocumentBuilder db = factory.newDocumentBuilder(); Document doc = db.parse(new FileInputStream(filePath)); return ResponseCtx.getInstance(doc.getDocumentElement()); } catch (Exception e) { log.error("Error while reading expected response from file ", e); //ignore any exception and return null } return null; }
From source file:com.nokia.dempsy.mpcluster.zookeeper.ZookeeperTestServer.java
private static Properties genZookeeperConfig(File zkDir) throws IOException { Properties props = new Properties(); props.setProperty("timeTick", "2000"); props.setProperty("initLimit", "10"); props.setProperty("syncLimit", "5"); try {/* w w w. ja v a 2 s. co m*/ props.setProperty("dataDir", zkDir.getCanonicalPath()); } catch (IOException e) { fail("Can't create zkConfig, zkDir has no path"); } props.setProperty("clientPort", String.valueOf(port)); return props; }
From source file:org.codehaus.mojo.screenshot.ScreenshotMojo.java
/** * Computes the path for a file relative to a given base, or fails if the * only shared directory is the root and the absolute form is better. * /*from w w w .j a va 2 s.co m*/ * @param base * File that is the base for the result * @param name * File to be "relativized" * @return the relative name * @throws IOException * if files have no common sub-directories, i.e. at best share * the root prefix "/" or "C:\" */ public static String getRelativePath(File base, File name) throws IOException { File parent = base.getParentFile(); if (parent == null) { throw new IOException("No common directory"); } String bpath = base.getCanonicalPath(); String fpath = name.getCanonicalPath(); if (fpath.startsWith(bpath)) { return fpath.substring(bpath.length() + 1); } else { return (".." + File.separator + getRelativePath(parent, name)); } }
From source file:com.schnobosoft.semeval.cortical.Util.java
/** * Get the output file object for an input file. The output file begins with the {@link #COMMON_PREFIX}, * and appends the retina name and the {@code measure} name. * * @param inputFile the input file object, beginning with {@link #INPUT_FILE_PREFIX}. * @param measure the {@link Measure} * @param retinaName the {@link Retina}//from w w w . ja v a 2s. c o m * @return a {@link File} object for the output file * @throws IOException */ public static File getOutputFile(File inputFile, Measure measure, Retina retinaName) throws IOException { if (!inputFile.getName().startsWith(INPUT_FILE_PREFIX)) { throw new IllegalArgumentException(inputFile + " does not match expected pattern."); } return new File(inputFile.getCanonicalPath().replace(INPUT_FILE_PREFIX, COMMON_PREFIX + retinaName.name().toLowerCase() + "." + measure.name() + ".")); }
From source file:ch.sourcepond.maven.release.scm.git.GitRepository.java
private static String pathOf(final File file) { String path;/*from w w w . j a v a2 s . c om*/ try { path = file.getCanonicalPath(); } catch (final IOException e1) { path = file.getAbsolutePath(); } return path; }
From source file:apim.restful.exportimport.utils.ArchiveGenerator.java
public static void addToZip(File directoryToZip, File file, ZipOutputStream zos) throws FileNotFoundException, IOException { FileInputStream fis = new FileInputStream(file); // we want the zipEntry's path to be a relative path that is relative // to the directory being zipped, so chop off the rest of the path String zipFilePath = file.getCanonicalPath().substring(directoryToZip.getCanonicalPath().length() + 1, file.getCanonicalPath().length()); System.out.println("Writing '" + zipFilePath + "' to zip file"); ZipEntry zipEntry = new ZipEntry(zipFilePath); zos.putNextEntry(zipEntry);//from w w w.ja va2 s . c om byte[] bytes = new byte[1024]; int length; while ((length = fis.read(bytes)) >= 0) { zos.write(bytes, 0, length); } zos.closeEntry(); fis.close(); }