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:com.cip.crane.agent.utils.FileExtractUtilsTest.java

public void TestunTarunGzip() {
    String path = getAbsolutePath("extract/test.tar.gz");
    File file = new File(path);
    try {/*from   w ww. ja  v  a2  s.co  m*/
        FileExtractUtils.unTar(FileExtractUtils.unGzip(file));
        File testFile1 = new File(file.getParent() + "/test/test1.txt");
        assertTrue(testFile1.exists());
        FileUtils.deleteDirectory(new File(file.getParent() + "/test"));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ArchiveException e) {
        e.printStackTrace();
    }
}

From source file:com.cip.crane.agent.utils.FileExtractUtilsTest.java

public void TestunTarunBzip() {
    String path = getAbsolutePath("extract/test.tar.bz2");
    File file = new File(path);
    try {/*from   ww  w  . ja v  a2 s.  c  o m*/
        FileExtractUtils.unTar(FileExtractUtils.unBzip(file));
        File testFile1 = new File(file.getParent() + "/test/test1.txt");
        assertTrue(testFile1.exists());
        FileUtils.deleteDirectory(new File(file.getParent() + "/test"));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ArchiveException e) {
        e.printStackTrace();
    }
}

From source file:it.polimi.modaclouds.monitoring.ddaapi.Config.java

private Config() {
    try {//from   w  w  w.j  a  va  2  s  .  co m
        config = new PropertiesConfiguration("dda.properties");
    } catch (ConfigurationException e) {
        try {
            File configFile = new File(
                    Config.class.getProtectionDomain().getCodeSource().getLocation().getPath());
            config = new PropertiesConfiguration(configFile.getParent() + "/dda.properties");
        } catch (ConfigurationException e2) {
            logger.warn("dda.properties file not found. Continuing without it.", e2);
        }
    }
}

From source file:com.dp.bigdata.taurus.agent.utils.FileExtractUtilsTest.java

@Test
public void TestunTarunGzip() {
    String path = getAbsolutePath("extract/test.tar.gz");
    File file = new File(path);
    try {//from w ww . j  a v  a2  s .c o  m
        FileExtractUtils.unTar(FileExtractUtils.unGzip(file));
        File testFile1 = new File(file.getParent() + "/test/test1.txt");
        assertTrue(testFile1.exists());
        FileUtils.deleteDirectory(new File(file.getParent() + "/test"));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ArchiveException e) {
        e.printStackTrace();
    }
}

From source file:com.dp.bigdata.taurus.agent.utils.FileExtractUtilsTest.java

@Test
public void TestunTarunBzip() {
    String path = getAbsolutePath("extract/test.tar.bz2");
    File file = new File(path);
    try {//from   w  w  w .j  a v a  2 s .  co m
        FileExtractUtils.unTar(FileExtractUtils.unBzip(file));
        File testFile1 = new File(file.getParent() + "/test/test1.txt");
        assertTrue(testFile1.exists());
        FileUtils.deleteDirectory(new File(file.getParent() + "/test"));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ArchiveException e) {
        e.printStackTrace();
    }
}

From source file:com.thoughtworks.go.server.initializers.CommandRepositoryInitializerIntegrationTest.java

@Test
public void shouldNotDeleteCustomCommandRepositoryWhenUpdatingDefaultCommandRepository() throws Exception {
    File versionFile = TestFileUtil.writeStringToTempFileInFolder("default", "version.txt", "10.1=10");
    File randomFile = TestFileUtil.createTestFile(versionFile.getParentFile(), "random");
    File defaultCommandRepoDir = versionFile.getParentFile();
    File customCommandRepoDir = TestFileUtil.createTestFolder(new File(defaultCommandRepoDir.getParent()),
            "customDir");
    File userFile = TestFileUtil.createTestFile(customCommandRepoDir, "userFile");

    initializer.usePackagedCommandRepository(
            new ZipInputStream(new FileInputStream(getZippedCommandRepo("12.4=12"))), defaultCommandRepoDir);

    assertThat(defaultCommandRepoDir.exists(), is(true));
    assertThat(FileUtils.readFileToString(new File(defaultCommandRepoDir, "version.txt"), UTF_8),
            is("12.4=12"));
    assertThat(new File(defaultCommandRepoDir, "snippet.xml").exists(), is(true));
    assertThat(new File(defaultCommandRepoDir, randomFile.getName()).exists(), is(false));
    assertThat(customCommandRepoDir.exists(), is(true));
    assertThat(new File(customCommandRepoDir, userFile.getName()).exists(), is(true));
}

From source file:com.github.maven_nar.NarUtil.java

public static void makeLink(final File file, final Log log)
        throws MojoExecutionException, MojoFailureException {
    if (!file.exists()) {
        return;//from   ww w .j a va  2s . co  m
    }

    if (file.isDirectory()) {
        final File[] files = file.listFiles();
        for (final File file2 : files) {
            makeLink(file2, log);
        }
    }
    if (file.isFile() && file.canRead() && file.canWrite() && !file.isHidden()
            && file.getName().matches(".*\\.so(\\.\\d+)+$")) {
        final File sofile = new File(file.getParent(),
                file.getName().substring(0, file.getName().indexOf(".so") + 3));
        if (!sofile.exists()) {
            // ln -s lib.so.xx lib.so
            final int result = runCommand("ln", new String[] { "-s", file.getName(), sofile.getPath() }, null,
                    null, log);
            if (result != 0) {
                throw new MojoExecutionException("Failed to execute 'ln -s " + file.getName() + " "
                        + sofile.getPath() + "'" + " return code: \'" + result + "\'.");
            }
        }
    }
}

From source file:com.dibsyhex.apkdissector.ZipReader.java

public void getZipContents(String name) {
    try {//from   ww  w.  j a  v a 2s .c o  m
        File file = new File(name);
        FileInputStream fileInputStream = new FileInputStream(file);
        ZipInputStream zipInputStream = new ZipInputStream(fileInputStream);
        //System.out.println(zipInputStream.available());
        //System.out.println("Reading each entries in details:");
        ZipFile zipFile = new ZipFile(file);
        ZipEntry zipEntry;

        response.displayLog("Begining to extract");

        while ((zipEntry = zipInputStream.getNextEntry()) != null) {
            String filename = "extracts" + File.separator + file.getName() + File.separator
                    + zipEntry.getName();
            System.out.println(filename);
            response.displayLog(filename);
            File extractDirectory = new File(filename);

            //Create the directories
            new File(extractDirectory.getParent()).mkdirs();

            //Now write the contents

            InputStream inputStream = zipFile.getInputStream(zipEntry);
            OutputStream outputStream = new FileOutputStream(extractDirectory);

            FileUtils.copyInputStreamToFile(inputStream, extractDirectory);

            //Decode the xml files

            if (filename.endsWith(".xml")) {
                //First create a temp file at a location temp/extract/...
                File temp = new File("temp" + File.separator + extractDirectory);
                new File(temp.getParent()).mkdirs();

                //Create an object of XML Decoder
                XmlDecoder xmlDecoder = new XmlDecoder();
                InputStream inputStreamTemp = new FileInputStream(extractDirectory);
                byte[] buf = new byte[80000];//increase
                int bytesRead = inputStreamTemp.read(buf);
                String xml = xmlDecoder.decompressXML(buf);
                //System.out.println(xml);
                FileUtils.writeStringToFile(temp, xml);

                //Now rewrite the files at the original locations

                FileUtils.copyFile(temp, extractDirectory);

            }

        }

        response.displayLog("Extraction Done !");
        System.out.println(" DONE ! ");
        zipInputStream.close();

    } catch (Exception e) {
        System.out.println(e.toString());
        response.displayError(e.toString());
    }
}

From source file:com.ibm.liberty.starter.service.test.api.v1.ProviderEndpoint.java

@GET
@Path("uploads/process")
@Produces(MediaType.TEXT_PLAIN)//from   w  w w. ja v a2  s. co m
public String processUploads(@QueryParam("path") String uploadDirectoryPath) throws IOException {
    File uploadDirectory;
    if (uploadDirectoryPath == null || !(uploadDirectory = new File(uploadDirectoryPath)).exists()) {
        return "Couldn't fulfill the request due to internal error";
    }

    List<File> filesListInDir = new ArrayList<File>();
    populateFilesList(uploadDirectory, filesListInDir);
    for (File uploadedFile : filesListInDir) {
        uploadedFile.renameTo(new File(uploadedFile.getParent() + "/" + uploadedFile.getName() + "_renamed"));
    }
    return "success";
}