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.schnobosoft.semeval.cortical.PrintCorrelations.java

private static void printCorrelations(File inputFile, Retina retinaName) 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);

    for (Measure correlationMeasure : Measure.values()) {
        List<Optional> scores = readScoresFile(getOutputFile(inputFile, correlationMeasure, retinaName));

        double pearson = getPearson(gs, scores);
        System.out.printf("Pearson correlation (%s, %s): %.4f%n", retinaName.name().toLowerCase(),
                correlationMeasure, pearson);
    }//from  w  ww.j  a  v a2  s. com
}

From source file:org.cloudfoundry.client.lib.SampleProjects.java

/**
 * Returns a simple spring application.//  ww w.ja  v  a  2 s  .co  m
 *
 * @return the simple-spring-app WAR file
 * @throws IOException
 */
public static File simpleSpringApp() throws IOException {
    ClassPathResource cpr = new ClassPathResource("simple-spring-app.war");
    File file = cpr.getFile();
    assertTrue("Expected test app at " + file.getCanonicalPath(), file.exists());
    return file;
}

From source file:org.cloudfoundry.client.lib.SampleProjects.java

/**
 * Returns a bad spring application that will cause crashes.
 *
 * @return the bad-spring-app WAR file// ww  w.  j a v a 2  s.c o m
 * @throws IOException
 */
public static File badSpringApp() throws IOException {
    ClassPathResource cpr = new ClassPathResource("bad-spring-app.war");
    File file = cpr.getFile();
    assertTrue("Expected test app at " + file.getCanonicalPath(), file.exists());
    return file;
}

From source file:org.cloudfoundry.client.lib.SampleProjects.java

/**
 * Returns a spring application using a file with a non-ascii name.
 *
 * @return the non-ascii-file-name WAR file
 * @throws IOException/*from  w w  w.j  a va 2  s.  c om*/
 */
public static File nonAsciFileName() throws IOException {
    ClassPathResource cpr = new ClassPathResource("non-ascii-file-name.war");
    File file = cpr.getFile();
    assertTrue("Expected test app at " + file.getCanonicalPath(), file.exists());
    return file;
}

From source file:Main.java

/**
 * Trigger the media scanner to ensure files show up in MTP.
 * @param context a context to use for communication with the media scanner
 * @param scanfile directory or file to scan
 *///w ww.  jav  a2 s . co m
@TargetApi(11)
private static void triggerMediaScanner(Context context, File scanfile) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
        return; // API 11 - lower versions do not have MTP
    try {
        String path = scanfile.getCanonicalPath();
        Log.i("SavingHelper", "Triggering media scan for " + path);
        MediaScannerConnection.scanFile(context, new String[] { path }, null, new OnScanCompletedListener() {
            @Override
            public void onScanCompleted(String path, Uri uri) {
                Log.i("SavingHelper", "Media scan completed for " + path + " URI " + uri);
            }
        });
    } catch (Exception e) {
        Log.e("SavingHelper", "Exception when triggering media scanner", e);
    }
}

From source file:UtilFunctions.java

public static File makeDirectory(File parentDirectory, String newDirectoryName) {
    try {/* www  . j av  a 2  s .co m*/
        File newDirectory = new File(parentDirectory.getCanonicalPath() + "/" + newDirectoryName + "/");
        int i = 0;

        while (newDirectory.exists()) {
            newDirectory = new File(parentDirectory.getCanonicalPath() + "/" + newDirectoryName + i + "/");
            i++;
        }

        newDirectory.mkdir();

        return newDirectory;

    } catch (IOException ex) {
        Logger.getLogger(UtilFunctions.class.getName()).log(Level.SEVERE, null, ex);
        return parentDirectory;
    }

}

From source file:org.mycontroller.standalone.model.McTemplate.java

@JsonIgnore
public static McTemplate get(String fileName) throws IllegalAccessException, IOException {
    File templateFile = FileUtils.getFile(AppProperties.getInstance().getTemplatesLocation() + fileName);
    return McTemplate.builder().extension(FilenameUtils.getExtension(templateFile.getCanonicalPath()))
            .canonicalPath(templateFile.getCanonicalPath()).name(templateFile.getCanonicalPath())
            .lastModified(templateFile.lastModified()).size(templateFile.length()).build();
}

From source file:Main.java

/**
 * Checks whether the filename looks legitimate
 *//*  w ww  . j a  v  a2  s  .c o  m*/
static boolean isFilenameValid(String filename, File downloadsDataDir) {
    final String[] whitelist;
    try {
        filename = new File(filename).getCanonicalPath();
        whitelist = new String[] { downloadsDataDir.getCanonicalPath(),
                Environment.getDownloadCacheDirectory().getCanonicalPath(),
                Environment.getExternalStorageDirectory().getCanonicalPath(), };
    } catch (IOException e) {
        Log.w(TAG, "Failed to resolve canonical path: " + e);
        return false;
    }

    for (String test : whitelist) {
        if (filename.startsWith(test)) {
            return true;
        }
    }

    return false;
}

From source file:Main.java

public static boolean canPaste(File destDir) {

    if (getFileToPaste() == null) {
        return false;
    }// w w  w .  j  a v a2 s .co  m
    if (getFileToPaste().isFile()) {
        return true;
    }
    try {
        if (destDir.getCanonicalPath().startsWith(COPIED_FILE.getCanonicalPath())) {
            return false;
        } else {
            return true;
        }
    } catch (Exception e) {

        return false;
    }
}

From source file:azkaban.execapp.AzkabanExecutorServerTest.java

private static String getSqlScriptsDir() throws IOException {
    // Dummy because any resource file works.
    URL resource = AzkabanExecutorServerTest.class.getClassLoader().getResource("test.file");
    final String dummyResourcePath = requireNonNull(resource).getPath();
    Path resources = Paths.get(dummyResourcePath).getParent();
    Path azkabanRoot = resources.getParent().getParent().getParent().getParent();

    File sqlScriptDir = Paths.get(azkabanRoot.toString(), AZKABAN_DB_SQL_PATH).toFile();
    return props.getString(AzkabanDatabaseSetup.DATABASE_SQL_SCRIPT_DIR, sqlScriptDir.getCanonicalPath());
}