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.gisgraphy.domain.geoloc.importer.ImporterHelper.java

/**
 * unzip a file in the same directory as the zipped file
 * //from w ww .  j  a v a 2 s.  c  o m
 * @param file
 *            The file to unzip
 */
public static void unzipFile(File file) {
    logger.info("will Extracting file: " + file.getName());
    Enumeration<? extends ZipEntry> entries;
    ZipFile zipFile;

    try {
        zipFile = new ZipFile(file);

        entries = zipFile.entries();

        while (entries.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) entries.nextElement();

            if (entry.isDirectory()) {
                // Assume directories are stored parents first then
                // children.
                (new File(entry.getName())).mkdir();
                continue;
            }

            logger.info("Extracting file: " + entry.getName() + " to " + file.getParent() + File.separator
                    + entry.getName());
            copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(
                    new FileOutputStream(file.getParent() + File.separator + entry.getName())));
        }

        zipFile.close();
    } catch (IOException e) {
        logger.error("can not unzip " + file.getName() + " : " + e.getMessage());
        throw new ImporterException(e);
    }
}

From source file:net.mindengine.galen.javascript.GalenJsExecutor.java

public Object eval(Reader scriptFileReader, String javascriptPath) throws IOException {
    File file = new File(javascriptPath);
    scriptExecutor.putContextPath(file.getParent());
    return context.evaluateReader(scope, scriptFileReader, javascriptPath, 1, null);
}

From source file:net.sourceforge.jweb.maven.minify.YUICompressorMinifier.java

public void minify(File f) {
    File saveTo = getSaveFile(f, "");

    String parent = saveTo.getParent();
    String pname = saveTo.getName().substring(0, saveTo.getName().indexOf("."));
    String sname = saveTo.getName().substring(saveTo.getName().lastIndexOf("."));
    String finalName = parent + File.separator + pname + this.getMinifyMojo().getMiniPrefix() + sname;
    File finalFile = new File(finalName);
    try {/*  w  w w  . j  a va 2 s  . co m*/
        FileUtils.writeStringToFile(finalFile, "");

        String[] provied = this.getMinifyMojo().getYuiArguments();
        int length = (provied == null ? 0 : provied.length);
        length += 5;
        int i = 0;

        String[] ret = new String[length];

        ret[i++] = "--type";
        ret[i++] = (saveTo.getName().toLowerCase().endsWith(".css") ? "css" : "js");

        if (provied != null) {
            for (String s : provied) {
                ret[i++] = s;
            }
        }

        ret[i++] = f.getAbsolutePath();
        ret[i++] = "-o";
        ret[i++] = finalName;
        StringBuilder builder = new StringBuilder();
        builder.append("yuicompressor ");
        for (String s : ret) {
            builder.append(s).append(" ");
        }
        this.getLog().debug(builder);

        YUICompressorNoExit.main(ret);
    } catch (Exception e) {
        //e.printStackTrace();
        this.getLog().warn(e);
        this.getLog().info("minifier will copy source only");
        try {
            FileUtils.copyFile(f, finalFile);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}

From source file:com.blogspot.skam94.main.datatypes.FileItem.java

public FileItem(File file) {
    this.filePath = file.getParent() + "/";
    this.fileName = file.getName().substring(0, file.getName().lastIndexOf('.'));
    this.ext = file.getName().substring(file.getName().lastIndexOf('.') + 1);
}

From source file:com.jcalvopinam.core.Unzipping.java

public Unzipping(String path) throws IOException {
    CustomFile customFile = new CustomFile();
    File inputFile = new File(path);

    customFile.setPath(String.format("%s%s", inputFile.getParent(), File.separator));
    customFile.setFileName(inputFile.getName());
    customFile.setFileNameExtension(inputFile.getName());
    customFile.setFileExtension(FilenameUtils.getExtension(inputFile.getName()));

    joinAndUnzipFile(inputFile, customFile);
}

From source file:IntegrationTests.FileStorageUploadIT.java

@After
public void tearDown() throws StorageException {
    System.gc();//from  w w w.j a v  a2  s .com
    Iterator it = testEnv.uploadFileList.entrySet().iterator();
    if (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        File x = (File) pair.getValue();
        LOGGER.log(Level.INFO, x.getParent() + " will now be deleted");
        try {
            FileUtils.deleteDirectory(x.getParentFile());
        } catch (IOException ex) {
            Logger.getLogger(WAStorageClientUploadIT.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    testEnv.fileShare.deleteIfExists();
    testEnv.uploadFileList.clear();
}

From source file:FileTreeFrame.java

public void valueForPathChanged(TreePath path, Object value) {
    File oldFile = (File) path.getLastPathComponent();
    String fileParentPath = oldFile.getParent();
    String newFileName = (String) value;
    File targetFile = new File(fileParentPath, newFileName);
    oldFile.renameTo(targetFile);//  w ww.j  a v a2  s. co m
    File parent = new File(fileParentPath);
    int[] changedChildrenIndices = { getIndexOfChild(parent, targetFile) };
    Object[] changedChildren = { targetFile };
    fireTreeNodesChanged(path.getParentPath(), changedChildrenIndices, changedChildren);

}

From source file:com.quangphuong.crawler.util.XMLUtil.java

public XMLUtil() throws URISyntaxException {
    URL u = getClass().getProtectionDomain().getCodeSource().getLocation();
    File f = new File(u.toURI().getPath());
    rootPath = f.getParent();
    f.delete();/*from  w w w  . j  av  a 2  s . co  m*/
}

From source file:com.jcalvopinam.core.Zipping.java

/***
 *
 * @param path path of file to core//from  ww w  .j  a  v a 2s. c  o m
 * @param fileSize size for each file in MB
 */
public Zipping(String path, int fileSize) throws IOException {
    CustomFile customFile = new CustomFile();
    File inputFile = new File(path);

    customFile.setPath(String.format("%s%s", inputFile.getParent(), File.separator));
    customFile.setFileName(FilenameUtils.getBaseName(inputFile.getName()));
    customFile.setFileNameExtension(inputFile.getName());
    customFile.setFileExtension(FilenameUtils.getExtension(inputFile.getName()));

    int bufferSize = CustomFile.BYTE_SIZE * CustomFile.BYTE_SIZE * fileSize;
    splitAndZipFile(inputFile, bufferSize, customFile);
}

From source file:azkaban.database.AzkabanDatabaseUpdaterTest.java

@Test
public void testH2AutoCreate() throws Exception {
    URL resourceUrl = Resources.getResource("conf/dbtesth2");
    assertNotNull(resourceUrl);/*  ww  w  .  jav  a  2s .  c om*/
    File resource = new File(resourceUrl.toURI());
    String confDir = resource.getParent();

    System.out.println("1.***Now testing check");
    AzkabanDatabaseUpdater.main(new String[] { "-c", confDir });

    System.out.println("2.***Now testing update");
    AzkabanDatabaseUpdater.main(new String[] { "-u", "-c", confDir });

    System.out.println("3.***Now testing check again");
    AzkabanDatabaseUpdater.main(new String[] { "-c", confDir });

    System.out.println("4.***Now testing update again");
    AzkabanDatabaseUpdater.main(new String[] { "-c", confDir, "-u" });

    System.out.println("5.***Now testing check again");
    AzkabanDatabaseUpdater.main(new String[] { "-c", confDir });
}