Example usage for java.io File getParentFile

List of usage examples for java.io File getParentFile

Introduction

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

Prototype

public File getParentFile() 

Source Link

Document

Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.

Usage

From source file:Main.java

private static boolean isFileSystemAvailable(File file, File topLevelResource) {

    boolean available;

    if (file.exists()) {
        available = true;//from   w  w w  .  jav a 2s .  co  m
    } else {
        if (isEqualPath(file, topLevelResource)) {
            available = false;
        } else {
            available = isFileSystemAvailable(file.getParentFile(), topLevelResource);
        }
    }

    return available;
}

From source file:com.thoughtworks.go.util.FileUtil.java

public static void createParentFolderIfNotExist(File file) {
    File parentFile = file.getParentFile();
    if (parentFile != null && !parentFile.exists()) {
        parentFile.mkdirs();//  w w  w  . j av  a  2s  .c  om
    }
}

From source file:com.taobao.android.builder.tools.FileNameUtils.java

private static MavenCoordinates getMavenCoordinate(String path) {
    File file = new File(path);
    File parentDir = file.getParentFile();
    //3/*  w  w w.j a v a 2s  .co  m*/
    for (int i = 0; i < 3; i++) {
        MavenCoordinates mavenCoordinates = AtlasBuildContext.dependencyTraceMap
                .get(parentDir.getAbsolutePath());
        if (null != mavenCoordinates) {
            return mavenCoordinates;
        }
        parentDir = parentDir.getParentFile();
    }

    return null;
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.io.FileProtection.java

/**
 * Returns the digest file for the specified file.
 * //from www  .  ja v a  2 s.  com
 * @param file the file to be validated
 * @return the digest file for the specified file
 */
public static File getDigestFile(File file) {
    return new File(file.getParentFile(),
            MessageFormat.format(Settings.getFileProtectionFormat(), file.getName()));
}

From source file:it.geosolutions.jaiext.JAIEXTTest.java

@BeforeClass
public static void setup() throws FileNotFoundException, IOException {
    final File inputJAIFile = TestData.file(JAIEXTTest.class,
            "META-INF" + File.separator + "registryFile2.jaiext");
    newJAIFile = new File(inputJAIFile.getParentFile().getParentFile().getParentFile().getParentFile()
            .getParentFile().getParentFile(), "META-INF" + File.separator + "registryFile.jaiext");
    FileUtils.copyFile(inputJAIFile, newJAIFile);

    // Setting of the operation registry
    JAIExt.initJAIEXT();//from  w ww. j  a  v a2s . com
}

From source file:com.netspective.axiom.TestUtils.java

static public void setupDb(String connProviderId, boolean createDb, boolean loadData) {
    Log log = LogFactory.getLog(TestUtils.class);

    Set connContextsWithOpenConnections = new HashSet(
            AbstractConnectionContext.getConnectionContextsWithOpenConnections());

    for (Iterator i = connContextsWithOpenConnections.iterator(); i.hasNext();) {
        ConnectionContext cc = (ConnectionContext) i.next();

        cc.rollbackAndCloseAndLogAsConnectionLeak(log, null);
    }//from  ww  w  .  ja  v  a  2s.  c  o m

    String classDir = connProviderId.replace('.', '/');

    FileFind.FileFindResults ffr = FileFind.findInClasspath(classDir + "/" + schemaFilename,
            FileFind.FINDINPATHFLAG_SEARCH_RECURSIVELY);
    if (!ffr.isFileFound()) {
        ffr = FileFind.findInClasspath(classDir + "-" + schemaFilename,
                FileFind.FINDINPATHFLAG_SEARCH_RECURSIVELY);
    }

    if (!ffr.isFileFound()) {
        return;
    }

    File schemaFile = ffr.getFoundFile();
    String rootPath = schemaFile.getParentFile().getAbsolutePath();

    Project project = new Project();

    Target target = new Target();
    target.setName("generate-ddl");

    AxiomTask task = new AxiomTask();
    task.setTaskName("generate-ddl");
    task.setSchema("db");
    task.setDdl("*");
    task.setProjectFile(new File(rootPath + "/" + schemaFilename));
    task.setDestDir(new File(rootPath + ddlPath));

    target.addTask(task);
    project.addTarget(target);
    task.setProject(project);

    SqlManager manager = task.getSqlManager();
    task.generateDdlFiles(manager);

    if (!createDb)
        return;

    SQLExec sqlExec = new SQLExec();
    target.addTask(sqlExec);
    sqlExec.setProject(project);
    File dbFolder = new File(rootPath + dbPath);

    //need to do a recursive delete or call the deleteTree ant task
    Delete del = new Delete();
    target.addTask(del);
    del.setProject(project);
    del.setDir(dbFolder);
    del.execute();

    dbFolder.mkdir();

    sqlExec.setSrc(new File(rootPath + ddlPath + "/db-hsqldb.sql"));
    sqlExec.setDriver("org.hsqldb.jdbcDriver");
    sqlExec.setUrl("jdbc:hsqldb:" + rootPath + dbPath + "/" + dbName);
    sqlExec.setUserid("sa");
    sqlExec.setPassword("");
    sqlExec.execute();

    //TODO: If we ever need to generate the DAL, then the trick is how to compile the classes that use it.
    //      For now, we leve it here for code coverage purposes, since it is excercising the DAL Generator
    String testRoot = rootPath.substring(0, rootPath.length() - connProviderId.length() - 1);
    task.setDestDir(new File(testRoot));
    task.setDalPackage(connProviderId + ".dal");
    task.generateDalFiles(manager);

    if (!loadData)
        return;

    task.setImport(new File(rootPath + "/" + dataImportFile));
    task.setDtdFile(new File(rootPath + dataImportDtdFile));
    task.generateImportDtd(manager);

    task.setDriver("org.hsqldb.jdbcDriver");
    task.setUrl("jdbc:hsqldb:" + rootPath + dbPath + "/" + dbName);
    task.setUserId("sa");
    task.setPassword("");
    task.importData(manager);

    connProvider.addDataSourceInfo(connProviderId, "org.hsqldb.jdbcDriver",
            "jdbc:hsqldb:" + rootPath + dbPath + File.separator + dbName, "sa", "");

}

From source file:jeplus.util.RelativeDirUtil.java

/**
 * break a path down into individual elements and add to a list. example : if a path is /a/b/c/d.txt, the breakdown will be
 * [d.txt,c,b,a]/*from w  ww  . ja v a2  s.c om*/
 *
 * @param f input file
 * @return a List collection with the individual elements of the path in reverse order
 */
private static List getPathList(File f) {
    List l = new ArrayList();
    File r;
    try {
        r = f.getCanonicalFile();
        while (r != null) {
            l.add(r.getName());
            r = r.getParentFile();
        }
    } catch (IOException e) {
        logger.error("", e);
        l = null;
    }
    return l;
}

From source file:com.sifcoapp.report.util.ReportConfigUtil.java

public static JasperPrint fillReport(File reportFile, Map<String, Object> parameters, Connection conn)
        throws JRException {
    parameters.put("BaseDir", reportFile.getParentFile());

    /*parametro localidades para monedas estatico*/
    parameters.put(JRParameter.REPORT_LOCALE, Locale.US);

    JasperPrint jasperPrint = JasperFillManager.fillReport(reportFile.getPath(), parameters, conn);

    return jasperPrint;
}

From source file:Main.java

/** Write the text provided to a File.
 * /*from www  .j  a  va  2  s  . c  om*/
 * @param file the file to write to.
 * @param text the text to write.
 * @throws IOException
 */
public static void write(File file, String text) throws IOException {
    FileOutputStream out = null;
    try {
        file.getParentFile().mkdirs();
        file.delete();
        file.createNewFile();
        out = new FileOutputStream(file);
        OutputStreamWriter writer = new OutputStreamWriter(out);
        writer.write(text);
        writer.flush();
    } finally {
        try {
            out.close();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}

From source file:utils.TestUtils.java

private static File codeSourceDir(Class<?> clazz) {
    URI uri = null;//from  w w  w  . j a va2  s .  c o m
    try {
        uri = clazz.getProtectionDomain().getCodeSource().getLocation().toURI();
        File jarOrDir = new File(uri);
        return jarOrDir.isDirectory() ? jarOrDir : jarOrDir.getParentFile();
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}