Example usage for java.io File getCanonicalPath

List of usage examples for java.io File getCanonicalPath

Introduction

In this page you can find the example usage for java.io File getCanonicalPath.

Prototype

public String getCanonicalPath() throws IOException 

Source Link

Document

Returns the canonical pathname string of this abstract pathname.

Usage

From source file:cinematicketsim.MovieClassParser.java

public ArrayList<Movie> getMovie(String filename, String name) {

    ArrayList<Movie> movieList = new ArrayList<Movie>();

    try {// w  ww  .j  a v a 2s.  co m
        File f = new File(filename);
        filename = f.getCanonicalPath();

    } catch (Exception e) {
        e.printStackTrace();
    }

    FileResource file = new FileResource(filename);

    CSVParser parser = file.getCSVParser();

    for (CSVRecord record : parser) {
        String movieId = record.get("id");

        String movieTitle = record.get("title");

        String movieYear = record.get("year");

        String movieCountry = record.get("country");

        String movieGenre = record.get("genre");

        String movieDirector = record.get("director");

        int movieMinutes = Integer.parseInt(record.get("minutes"));

        String moviePoster = record.get("poster");

        Movie movie = new Movie(movieId, movieTitle, movieYear, movieGenre, movieDirector, movieCountry,
                moviePoster, movieMinutes);
        movieList.add(movie);
    }

    ArrayList<Movie> movieSearch = new ArrayList<Movie>();
    String smallName = name.toLowerCase();
    for (Movie temp : movieList) {
        String tempName = temp.getTitle();
        String lowerTempName = tempName.toLowerCase();
        if (lowerTempName.equals(smallName)) {
            movieSearch.add(temp);
        }

    }

    return movieSearch;

}

From source file:com.asakusafw.testdriver.inprocess.EmulatorUtilsTest.java

/**
 * Find jobflow library path.//from   w w  w.java 2s  .  co m
 * @throws Exception if failed
 */
@Test
public void getJobflowLibraryPath() throws Exception {
    context.setCurrentBatchId("b");
    context.setCurrentFlowId("f");
    context.setCurrentExecutionId("e");
    File expected = new File(context.getBatchApplicationsInstallationPath(), "b/lib/jobflow-f.jar");
    File actual = EmulatorUtils.getJobflowLibraryPath(context);
    assertThat(actual.getCanonicalPath(), is(expected.getCanonicalPath()));
}

From source file:com.sap.dirigible.runtime.content.ContentInitializerServlet.java

private void checkAndImportRegistry(ServletConfig config, String user) throws IOException {
    String path = config.getServletContext().getRealPath(PATH_REGISTRY_ROOT_SOURCE);
    File root = new File(path);
    logger.debug("root: " + root.getCanonicalPath().replace('\\', '/')); //$NON-NLS-1$
    if (root.exists() && root.isDirectory()) {
        File[] files = root.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                File folder = files[i];
                checkAndImportFileOrFolder(root.getCanonicalPath().length(), folder, user);
            }//  w  w w  .  j av  a  2s . co m
        }
    } else {
        throw new IOException(CONTENT_INITIALIZATION_FAILED + path);
    }
}

From source file:mcp.tools.nmap.parser.NmapXmlParser.java

public static void parse(File xmlResultsFile, String scanDescription, String commandLine) {
    Pattern endTimePattern = Pattern.compile("<runstats><finished time=\"(\\d+)");
    String xmlResults;/*from  ww w. j a  va 2  s.  c o  m*/
    try {
        xmlResults = FileUtils.readFileToString(xmlResultsFile);
    } catch (IOException e) {
        logger.error("Failed to parse nmap results file '" + xmlResultsFile.toString() + "': "
                + e.getLocalizedMessage(), e);
        return;
    }

    Matcher m = endTimePattern.matcher(xmlResults);
    Instant scanTime = null;
    if (m.find()) {
        int t;
        try {
            t = Integer.parseInt(m.group(1));
            scanTime = Instant.ofEpochSecond(t);
        } catch (NumberFormatException e) {

        }
    }

    if (scanTime == null) {
        logger.debug("Failed to find scan completion time in nmap results. Using current time.");
        scanTime = Instant.now();
    }
    String path;
    try {
        path = xmlResultsFile.getCanonicalPath();
    } catch (IOException e1) {
        logger.debug("Why did the canonical path fail?");
        path = xmlResultsFile.getAbsolutePath();
    }

    NmapScanSource source = new NmapScanSourceImpl(path, scanDescription, commandLine);

    NMapXmlHandler nmxh = new NMapXmlHandler(scanTime, source);
    SAXParserFactory spf = SAXParserFactory.newInstance();

    SAXParser sp;
    try {
        sp = spf.newSAXParser();
    } catch (ParserConfigurationException e) {
        throw new UnexpectedException("This shouldn't have happened: " + e.getLocalizedMessage(), e);
    } catch (SAXException e) {
        throw new UnexpectedException("This shouldn't have happened: " + e.getLocalizedMessage(), e);
    }

    try {
        sp.parse(xmlResultsFile, nmxh);
    } catch (SAXException e) {
        logger.error("Failed to parse nmap results file '" + xmlResultsFile.toString() + "': "
                + e.getLocalizedMessage(), e);
        return;
    } catch (IOException e) {
        logger.error("Failed to parse nmap results file '" + xmlResultsFile.toString() + "': "
                + e.getLocalizedMessage(), e);
        return;
    }
}

From source file:me.timothy.ddd.entities.EntityManager.java

public void loadEntities(File file) throws IOException, ParseException {
    logger.printf(Level.INFO, "Loading entities from %s (exists: %b)", file.getCanonicalPath(), file.exists());
    JSONArray jsonArray;/*www.  j  av  a  2 s.  co  m*/
    try (FileReader fr = new FileReader(file)) {
        JSONParser parser = new JSONParser();
        jsonArray = (JSONArray) parser.parse(fr);
    }

    for (int i = 0; i < jsonArray.size(); i++) {
        EntityInfo ei = new EntityInfo();
        ei.loadFrom((JSONObject) jsonArray.get(i));
        logger.trace(ei.toString());
        entities.add(new Entity(ei));
    }
    logger.printf(Level.INFO, "Successfully loaded %d entities", entities.size());
}

From source file:com.heliosdecompiler.helios.tasks.AddFilesTask.java

private void handleDirectory(File file) throws IOException {
    LinkedList<File> filesToProcess = new LinkedList<>();
    filesToProcess.add(file);/*w w  w .  j ava  2s.c  om*/
    Set<String> filesProcessed = new HashSet<>();

    while (!filesToProcess.isEmpty()) {
        File current = filesToProcess.pop();
        if (current.isFile() && filesProcessed.add(current.getCanonicalPath())) {
            handle(current);
        } else {
            File[] listFiles = current.listFiles();
            if (listFiles != null) {
                filesToProcess.addAll(Arrays.asList(listFiles));
            }
        }
    }
}

From source file:io.wcm.devops.conga.plugins.aem.maven.InstallPackagesMojo.java

private String getCanonicalPath(File file) {
    try {//from   w ww .  jav a2 s. c o  m
        return file.getCanonicalPath();
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:io.wcm.devops.conga.plugins.sling.postprocessor.ProvisioningOsgiConfigPostProcessorTest.java

private void assertExists(String fileName) throws IOException {
    File file = new File(targetDir, fileName);
    assertTrue("Config file found: " + file.getCanonicalPath(), file.exists());
}

From source file:Dropper.java

/**
 * Do the actual import./* w  w  w .  j a  v  a  2s  . c  om*/
 * 
 * @see javax.swing.TransferHandler#importData(javax.swing.JComponent,
 *      java.awt.datatransfer.Transferable)
 */
public boolean importData(JComponent comp, Transferable t) {
    DataFlavor[] flavors = t.getTransferDataFlavors();
    System.out.println("Trying to import:" + t);
    System.out.println("... which has " + flavors.length + " flavors.");
    for (int i = 0; i < flavors.length; i++) {
        DataFlavor flavor = flavors[i];
        try {
            if (flavor.equals(DataFlavor.javaFileListFlavor)) {
                System.out.println("importData: FileListFlavor");

                List l = (List) t.getTransferData(DataFlavor.javaFileListFlavor);
                Iterator iter = l.iterator();
                while (iter.hasNext()) {
                    File file = (File) iter.next();
                    System.out.println("GOT FILE: " + file.getCanonicalPath());
                    // Now do something with the file...
                }
                return true;
            } else if (flavor.equals(DataFlavor.stringFlavor)) {
                System.out.println("importData: String Flavor");
                String fileOrURL = (String) t.getTransferData(flavor);
                System.out.println("GOT STRING: " + fileOrURL);
                try {
                    URL url = new URL(fileOrURL);
                    System.out.println("Valid URL: " + url.toString());
                    // Do something with the contents...
                    return true;
                } catch (MalformedURLException ex) {
                    System.err.println("Not a valid URL");
                    return false;
                }
                // now do something with the String.

            } else {
                System.out.println("importData rejected: " + flavor);
                // Don't return; try next flavor.
            }
        } catch (IOException ex) {
            System.err.println("IOError getting data: " + ex);
        } catch (UnsupportedFlavorException e) {
            System.err.println("Unsupported Flavor: " + e);
        }
    }
    // If you get here, I didn't like the flavor.
    Toolkit.getDefaultToolkit().beep();
    return false;
}

From source file:de.wpsverlinden.dupfind.FileIndexer.java

private void recAddFilesInDir(File dir) {
    try {//from w  ww.j a  v  a 2 s .  c o  m
        Map<String, FileEntry> collect = Files.walk(Paths.get(dir.getCanonicalPath())).parallel()
                .filter(Files::isRegularFile).map((e) -> e.toFile()).filter((e) -> {
                    FileEntry fi = fileIndex.get(getPath(e));
                    return fi == null || fi.getLastModified() < e.lastModified();
                }).collect(Collectors.toMap((e) -> getPath(e),
                        (e) -> new FileEntry(getPath(e), e.length(), e.lastModified(), "")));
        fileIndex.putAll(collect);
    } catch (IOException ex) {
        System.err.println(ex);
    }
}