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:com.ikon.omr.OMRHelper.java

/**
 * process//from  w ww .j  av a  2  s.  c o  m
 */
public static Map<String, String> process(File fileToProcess, long omId) throws IOException, OMRException,
        DatabaseException, InvalidFileStructureException, InvalidImageIndexException, UnsupportedTypeException,
        MissingParameterException, WrongParameterException {
    Map<String, String> values = new HashMap<String, String>();
    Omr omr = OmrDAO.getInstance().findByPk(omId);
    InputStream asc = new ByteArrayInputStream(omr.getAscFileContent());
    InputStream config = new ByteArrayInputStream(omr.getConfigFileContent());
    InputStream fields = new ByteArrayInputStream(omr.getFieldsFileContent());

    if (asc != null && asc.available() > 0 && config != null && config.available() > 0 && fields != null
            && fields.available() > 0) {
        Gray8Image grayimage = ImageUtil.readImage(fileToProcess.getCanonicalPath());
        if (grayimage == null) {
            throw new OMRException("Not able to process the image as gray image");
        }

        ImageManipulation image = new ImageManipulation(grayimage);
        image.locateConcentricCircles();
        image.readConfig(config);
        image.readFields(fields);
        image.readAscTemplate(asc);
        image.searchMarks();
        File dataFile = FileUtils.createTempFile();
        image.saveData(dataFile.getCanonicalPath());

        // Parse data file

        FileInputStream dfStream = new FileInputStream(dataFile);
        DataInputStream in = new DataInputStream(dfStream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;

        while ((strLine = br.readLine()) != null) {
            // format key=value ( looking for first = )
            String key = "";
            String value = "";

            if (strLine.contains("=")) {
                key = strLine.substring(0, strLine.indexOf("="));
                value = strLine.substring(strLine.indexOf("=") + 1);
                value = value.trim();
            }

            if (!key.equals("")) {
                if (value.equals("")) {
                    IOUtils.closeQuietly(br);
                    IOUtils.closeQuietly(in);
                    IOUtils.closeQuietly(dfStream);
                    IOUtils.closeQuietly(asc);
                    IOUtils.closeQuietly(config);
                    IOUtils.closeQuietly(fields);
                    throw new OMRException("Empty value");
                }

                if (omr.getProperties().contains(key)) {
                    values.put(key, value);
                }
            }
        }

        IOUtils.closeQuietly(br);
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(dfStream);
        IOUtils.closeQuietly(asc);
        IOUtils.closeQuietly(config);
        IOUtils.closeQuietly(fields);
        FileUtils.deleteQuietly(dataFile);
        return values;
    } else {
        throw new OMRException("Error asc, config or fields files not found");
    }
}

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

private Set<String> normalize(Iterable<File> paths) throws IOException {
    Set<String> results = new HashSet<>();
    for (File file : paths) {
        results.add(file.getCanonicalPath());
    }/*from  w  w w  . j  a v  a2 s.c o  m*/
    return results;
}

From source file:com.parse.ParseFileUtils.java

/**
 * Copies a file to a new location./* w  w w. j  a  v a 2  s  . c  om*/
 * <p>
 * This method copies the contents of the specified source file
 * to the specified destination file.
 * The directory holding the destination file is created if it does not exist.
 * If the destination file exists, then this method will overwrite it.
 * <p>
 * <strong>Note:</strong> Setting <code>preserveFileDate</code> to
 * {@code true} tries to preserve the file's last modified
 * date/times using {@link File#setLastModified(long)}, however it is
 * not guaranteed that the operation will succeed.
 * If the modification operation fails, no indication is provided.
 *
 * @param srcFile  an existing file to copy, must not be {@code null}
 * @param destFile  the new file, must not be {@code null}
 * @param preserveFileDate  true if the file date of the copy
 *  should be the same as the original
 *
 * @throws NullPointerException if source or destination is {@code null}
 * @throws IOException if source or destination is invalid
 * @throws IOException if an IO error occurs during copying
 * @throws IOException if the output file length is not the same as the input file length after the copy completes
 * @see #copyFileToDirectory(File, File, boolean)
 * @see #doCopyFile(File, File, boolean)
 */
public static void copyFile(final File srcFile, final File destFile, final boolean preserveFileDate)
        throws IOException {
    if (srcFile == null) {
        throw new NullPointerException("Source must not be null");
    }
    if (destFile == null) {
        throw new NullPointerException("Destination must not be null");
    }
    if (srcFile.exists() == false) {
        throw new FileNotFoundException("Source '" + srcFile + "' does not exist");
    }
    if (srcFile.isDirectory()) {
        throw new IOException("Source '" + srcFile + "' exists but is a directory");
    }
    if (srcFile.getCanonicalPath().equals(destFile.getCanonicalPath())) {
        throw new IOException("Source '" + srcFile + "' and destination '" + destFile + "' are the same");
    }
    final File parentFile = destFile.getParentFile();
    if (parentFile != null) {
        if (!parentFile.mkdirs() && !parentFile.isDirectory()) {
            throw new IOException("Destination '" + parentFile + "' directory cannot be created");
        }
    }
    if (destFile.exists() && destFile.canWrite() == false) {
        throw new IOException("Destination '" + destFile + "' exists but is read-only");
    }
    doCopyFile(srcFile, destFile, preserveFileDate);
}

From source file:com.sshtools.daemon.vfs.VirtualFileSystem.java

/**
 *
 *
 * @param path//from w w  w .  j  a v a  2  s.  c o  m
 * @param securemount
 *
 * @return
 *
 * @throws FileNotFoundException
 */
public static String translateCanonicalPath(String path, String securemount) throws FileNotFoundException {
    try {
        log.debug("Translating for canonical path " + path + " against secure mount " + securemount);

        File f = new File(path);
        String canonical = f.getCanonicalPath().replace('\\', '/');

        File f2 = new File(securemount);
        String canonical2 = f2.getCanonicalPath().replace('\\', '/');

        // Verify that the canonical path does not exit out of the mount
        if (canonical.startsWith(canonical2)) {
            return canonical;
        } else {
            throw new FileNotFoundException(path + " could not be found");
        }
    } catch (IOException ex) {
        throw new FileNotFoundException(path + " could not be found");
    }
}

From source file:org.alfresco.extension.bulkfilesystemimport.impl.AbstractBulkFilesystemImporter.java

public final static String getFileName(final File file) {
    String result = null;//from   w  w  w  .  ja v  a  2  s.  c  om

    if (file != null) {
        try {
            result = file.getCanonicalPath();
        } catch (final IOException ioe) {
            result = file.toString();
        }
    }

    return (result);
}

From source file:eu.eubrazilcc.lvl.core.GbFlatFileTest.java

@Test
public void test() {
    System.out.println("GbFlatFileTest.test()");
    try {//from   ww  w .j ava 2  s .c  o  m
        final Collection<File> files = getGenBankFlatFiles();
        for (final File file : files) {
            System.out.println(" >> Sequence file: " + file.getCanonicalPath());
            final ImmutableMultimap<GenBankField, Locale> countries = inferCountry(file);
            assertThat("inferred countries is not null", countries, notNullValue());
            assertThat("inferred countries is not empty", !countries.isEmpty());
            /* uncomment to display additional output */
            System.out.println("Inferred countries: ");
            for (final GenBankField key : countries.keySet()) {
                for (final Locale locale : countries.get(key)) {
                    System.out.println("Field=" + key + ", country=" + locale.getDisplayCountry());
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace(System.err);
        fail("GbFlatFileTest.test() failed: " + e.getMessage());
    } finally {
        System.out.println("GbFlatFileTest.test() has finished");
    }
}

From source file:es.tid.fiware.rss.service.CdrsManager.java

/**
 * Run process to save Cdr into database.
 * /*  www .ja  va2 s .co  m*/
 * @return
 * @throws IOException
 * @throws InterruptedException
 */
public String runCdrToDB() throws IOException, InterruptedException {
    String cdrToDBScript = (String) rssProps.get("cdrToDBScript");
    logger.trace("cdrToDBScript: " + cdrToDBScript);
    File cdrToDBSH = new File(cdrToDBScript);
    logger.debug("Running script: " + cdrToDBSH.getCanonicalPath());
    Process p = runtime.exec("sh " + cdrToDBSH.getCanonicalPath());
    BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String aLine;
    String error = null;
    while ((aLine = br.readLine()) != null) {
        if (aLine.indexOf("ERROR") != -1 && error == null) {
            error = aLine;
            logger.error(aLine);
        } else {
            logger.debug(aLine);
        }
    }
    int exitVal = p.waitFor();
    br.close();
    logger.debug("Process exitValue: " + exitVal);
    return error;
}

From source file:com.intuit.cto.selfservice.service.ManagedProcessBuilder.java

/**
 * Adds a File as a argument to the command. This uses
 * {@link File#getCanonicalPath()}, which is usually what you'll actually
 * want when launching external processes.
 * //from  www.  j  a v  a2s .co  m
 * @throws IOException
 * @see ProcessBuilder
 */
public ManagedProcessBuilder addArgument(File arg) throws IOException {
    return addArgument(arg.getCanonicalPath());
}

From source file:com.tunyk.mvn.plugins.htmlcompressor.FileTool.java

public void setRootDirPath(String rootDirPath) throws IOException {
    File file = new File(rootDirPath);
    this.rootDirPath = file.getCanonicalPath().replaceAll("\\\\", "/").replaceAll("/$", "");
}

From source file:com.blackducksoftware.integration.build.utils.FlatDependencyListWriter.java

public void write(final File outputDirectory, final String hubProjectName, final DependencyNode rootNode)
        throws IOException {
    final Set<String> gavStrings = new HashSet<>();
    addAllGavs(gavStrings, rootNode);/*from  w  ww . jav a2  s.  c  om*/
    final List<String> gavList = new ArrayList<>(gavStrings);
    Collections.sort(gavList);

    // if the directory doesn't exist yet, let's create it
    outputDirectory.mkdirs();

    String filename = getFilename(hubProjectName);
    final File file = new File(outputDirectory, filename);
    logger.info(String.format("Generating file: %s", file.getCanonicalPath()));

    try (final OutputStream outputStream = new FileOutputStream(file)) {
        for (final String gav : gavList) {
            IOUtils.write(gav, outputStream, "UTF8");
            IOUtils.write("\n", outputStream, "UTF8");
        }
    }
}