Example usage for java.io File getParent

List of usage examples for java.io File getParent

Introduction

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

Prototype

public String getParent() 

Source Link

Document

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

Usage

From source file:ch.kostceco.tools.kostsimy.service.impl.ConfigurationServiceImpl.java

private XMLConfiguration getConfig() {
    if (this.config == null) {

        try {/* w w  w .  j a  v a 2s  .  c  o  m*/

            String path = "configuration/kostsimy.conf.xml";

            URL locationOfJar = KOSTSimy.class.getProtectionDomain().getCodeSource().getLocation();
            String locationOfJarPath = locationOfJar.getPath();

            if (locationOfJarPath.endsWith(".jar")) {
                File file = new File(locationOfJarPath);
                String fileParent = file.getParent();
                path = fileParent + "/" + path;
            }

            config = new XMLConfiguration(path);

        } catch (ConfigurationException e) {
            LOGGER.logError(getTextResourceService().getText(MESSAGE_XML_MODUL_CI)
                    + getTextResourceService().getText(MESSAGE_XML_CONFIGURATION_ERROR_1));
            LOGGER.logError(getTextResourceService().getText(MESSAGE_XML_MODUL_CI)
                    + getTextResourceService().getText(MESSAGE_XML_CONFIGURATION_ERROR_2));
            LOGGER.logError(getTextResourceService().getText(MESSAGE_XML_MODUL_CI)
                    + getTextResourceService().getText(MESSAGE_XML_CONFIGURATION_ERROR_3));
            System.exit(1);
        }
    }
    return config;
}

From source file:br.com.ingenieux.mojo.jbake.SeedMojo.java

private void unpackZip(File tmpZipFile) throws IOException {
    ZipInputStream zis = new ZipInputStream(new FileInputStream(tmpZipFile));
    //get the zipped file list entry
    ZipEntry ze = zis.getNextEntry();

    while (ze != null) {
        if (ze.isDirectory()) {
            ze = zis.getNextEntry();//w  w w. j ava  2  s .  c  om
            continue;
        }

        String fileName = stripLeadingPath(ze.getName());
        File newFile = new File(outputDirectory + File.separator + fileName);

        new File(newFile.getParent()).mkdirs();

        FileOutputStream fos = new FileOutputStream(newFile);

        IOUtils.copy(zis, fos);

        fos.close();
        ze = zis.getNextEntry();
    }

    zis.closeEntry();
    zis.close();
}

From source file:c3.ops.priam.backup.MetaData.java

public File createTmpMetaFile() throws IOException {
    File metafile = File.createTempFile("meta", ".json");
    File destFile = new File(metafile.getParent(), "meta.json");
    if (destFile.exists())
        destFile.delete();/*from w ww  .  ja v  a2s . c  om*/
    FileUtils.moveFile(metafile, destFile);
    return destFile;
}

From source file:io.fabric8.maven.docker.util.DockerFileUtilTest.java

@Test
public void interpolate() throws Exception {
    MojoParameters params = mockMojoParams();
    Map<String, String> filterMapping = new HashMap<>();
    filterMapping.put("none", "false");
    filterMapping.put("var", "${*}");
    filterMapping.put("at", "@");

    for (Map.Entry<String, String> entry : filterMapping.entrySet()) {
        for (int i = 1; i < 2; i++) {
            File dockerFile = getDockerfilePath(i, entry.getKey());
            File expectedDockerFile = new File(dockerFile.getParent(), dockerFile.getName() + ".expected");
            File actualDockerFile = createTmpFile(dockerFile.getName());
            FixedStringSearchInterpolator interpolator = DockerFileUtil.createInterpolator(params,
                    entry.getValue());//w  w  w  . j a v a2 s .co m
            FileUtils.write(actualDockerFile, DockerFileUtil.interpolate(dockerFile, interpolator), "UTF-8");
            // Compare text lines without regard to EOL delimiters
            assertEquals(FileUtils.readLines(expectedDockerFile), FileUtils.readLines(actualDockerFile));
        }
    }
}

From source file:cc.creativecomputing.io.CCIOUtil.java

/**
 * Takes a path and creates any in-between folders if they don't
 * already exist. Useful when trying to save to a subfolder that
 * may not actually exist./*from   w  ww  . j a v  a  2 s.c o  m*/
 * @param theFileName theFileNameToCheck
 */
static public void createPath(String theFileName) {
    File file = new File(theFileName);
    String parent = file.getParent();
    if (parent != null) {
        File unit = new File(parent);
        if (!unit.exists())
            unit.mkdirs();
    }
}

From source file:hudson.plugins.simpleupdatesite.Plugin.java

private String getExcerpt(File hpiFile) {
    try {/*from   ww  w . ja  va2 s .  com*/
        String baseName = FilenameUtils.getBaseName(hpiFile.getName());
        File exceptFile = new File(hpiFile.getParent(), baseName + ".info");
        if (exceptFile.exists()) {
            return FileUtils.readFileToString(exceptFile, "UTF-8");
        } else {
            return "";
        }
    } catch (Exception e) {
        return "";
    }
}

From source file:hudson.plugins.simpleupdatesite.Plugin.java

private String getWiki(File hpiFile) {
    try {/*from   w ww  .  ja  va2  s .  c o  m*/
        String baseName = FilenameUtils.getBaseName(hpiFile.getName());
        File exceptFile = new File(hpiFile.getParent(), baseName + ".wiki");
        if (exceptFile.exists()) {
            return FileUtils.readFileToString(exceptFile, "UTF-8");
        } else {
            return "";
        }
    } catch (Exception e) {
        return "";
    }
}

From source file:com.stevpet.sonar.plugins.dotnet.mscover.vstest.runner.AbstractAssembliesFinder.java

public String findUnitTestAssembliesDir(VisualStudioSolution solution) {
    File solutionDirectory = solution.getSolutionDir();
    List<VisualStudioProject> projects = solution.getProjects();
    List<String> assemblies = findUnitTestAssembliesFromConfig(solutionDirectory, projects);
    File firstAssembly = new File(assemblies.get(0));
    return firstAssembly.getParent();

}

From source file:avantssar.aslanpp.testing.DiskSpecificationsProvider.java

public DiskSpecificationsProvider(String baseDirectory) {
    File base = new File(baseDirectory);
    if (!base.exists() || !base.isDirectory()) {
        throw new IllegalArgumentException(
                "Path '" + baseDirectory + "' cannot be accessed or does not point to a directory.");
    }/*from  ww w  .j a v a 2 s .c o  m*/
    IOFileFilter filter = FileFilterUtils.suffixFileFilter(".aslan++");
    IOFileFilter dirFilter = FileFilterUtils.makeCVSAware(FileFilterUtils.makeSVNAware(null));
    Collection<File> specs = FileUtils.listFiles(base, filter, dirFilter);
    List<String> forSort = new ArrayList<String>();
    SortedSet<String> forASLanPath = new TreeSet<String>();
    for (File f : specs) {
        if (isSpec(f)) {
            forSort.add(f.getAbsolutePath());
            forASLanPath.add(f.getParent());
        }
    }
    Collections.sort(forSort);
    for (String s : forSort) {
        add(new DiskTestTask(new File(s)));
    }
    String temp = "";
    for (String s : forASLanPath) {
        if (temp.length() > 0) {
            temp += File.pathSeparator;
        }
        temp += s;
    }
    aslanPath = temp;
}

From source file:cc.recommenders.io.IoUtilsTest.java

@Test
public void parentOfSomething() throws MalformedURLException {
    File tmpDir = Files.createTempDir();
    String tmp = tmpDir.getAbsolutePath();
    String parent = tmpDir.getParent();
    URL actual = sut.getParentDirectory(tmp).getUrl();
    URL expected = new Directory(parent).getUrl();
    assertEquals(expected, actual);/*from   w  w  w.  jav a2s.  c o m*/
}