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:io.druid.segment.loading.LocalDataSegmentFinderTest.java

private String getDescriptorPath(DataSegment segment) {
    final File indexzip = new File(String.valueOf(segment.getLoadSpec().get("path")));
    return indexzip.getParent() + "/" + DESCRIPTOR_JSON;
}

From source file:com.gisgraphy.importer.ImporterHelper.java

/**
 * unzip a file in the same directory as the zipped file
 * /*from  ww w.  j a  v a2 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(), e);
        throw new ImporterException(e);
    }
}

From source file:ste.web.http.beanshell.BeanShellHandler.java

@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context)
        throws HttpException, IOException {

    String uri = request.getRequestLine().getUri();
    int pos = uri.indexOf('?');
    if (pos >= 0) {
        uri = uri.substring(0, pos);/* w ww.  ja  v a 2 s .c o  m*/
    }
    if (log.isLoggable(Level.FINE)) {
        log.fine(String.format("serving %s", uri));
    }

    if (controllersFolder == null) {
        controllersFolder = DEFAULT_CONTROLLERS_PREFIX;
    } else {
        //
        // let's fix a common mistake :)
        //
        if (!controllersFolder.startsWith("/")) {
            setControllersFolder('/' + getControllersFolder());
        }
    }

    File scriptFile = new File(appsRoot, uri);
    String controllerPath = scriptFile.getParent() + getControllersFolder();
    scriptFile = new File(controllerPath, scriptFile.getName());

    if (log.isLoggable(Level.FINE)) {
        log.fine(String.format("script path: %s", scriptFile.getAbsolutePath()));
    }

    try {
        Interpreter bsh = new Interpreter();
        BeanShellUtils.setup(bsh, request, response, (HttpSessionContext) context);
        bsh.set(VAR_SOURCE, scriptFile.getAbsolutePath());
        bsh.eval(BeanShellUtils.getScript(scriptFile));

        String view = (String) bsh.get(ATTR_VIEW);
        if (view == null) {
            throw new HttpException(
                    "view not defined. Set the variable 'view' to the name of the view to show (including .v).");
        }

        if (log.isLoggable(Level.FINE)) {
            log.fine("view: " + view);
        }

        BeanShellUtils.cleanup(bsh, request);
        BeanShellUtils.setVariablesAttributes(bsh, context);
    } catch (FileNotFoundException e) {
        response.setStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_FOUND,
                "Script " + scriptFile + " not found.");
    } catch (EvalError x) {
        String msg = x.getMessage();

        if (log.isLoggable(Level.SEVERE)) {
            log.severe(String.format("error evaluating: %s: %s", uri, msg));
            log.throwing(getClass().getName(), "handleError", x);
        }
        throw new HttpException("error evaluating " + uri + ": " + msg, x);
    }
}

From source file:aurelienribon.texturepackergui.Project.java

public void save(File projectFile) throws IOException {
    String str = "input=\"" + FilenameHelper.getRelativePath(input, projectFile.getParent()) + "\"\n"
            + "output=\"" + FilenameHelper.getRelativePath(output, projectFile.getParent()) + "\"\n"
            + "packName=\"" + packName + "\"\n\n" + saveSettings(settings);

    FileUtils.writeStringToFile(projectFile, str);
}

From source file:com.honnix.yaacs.adapter.http.ui.ACHttpClientCli.java

private void save(String filePath, InputStream is) throws IOException {
    File file = new File(filePath);
    File directory = new File(file.getParent());

    if (!directory.exists()) {
        directory.mkdirs();//from  w w w .  j  a v  a2 s  . co  m
    }

    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
    BufferedInputStream bis = new BufferedInputStream(is);
    byte[] buffer = new byte[255];
    int length = -1;

    while ((length = bis.read(buffer)) != -1) {
        bos.write(buffer, 0, length);
    }

    bos.flush();
    StreamUtil.closeStream(bos);
    StreamUtil.closeStream(bis);
}

From source file:com.att.aro.core.cloud.TraceManager.java

private void unZip(String zipFile, String saveTo) {
    notifyListeners(State.UNCOMPRESSING);
    if (zipFile == null) {
        return;/*from  ww  w .j av  a2  s  .  c  o  m*/
    }
    File tempFile = new File(zipFile);
    try {
        ZipFile zipfile = new ZipFile(zipFile);
        String savedFolder = tempFile.getParent() + FILE_SEPARATOR + saveTo;
        File folder = new File(savedFolder);
        folder.mkdir();
        zipfile.extractAll(savedFolder);
    } catch (ZipException e) {
        e.printStackTrace();
    }
    notifyListeners(State.DONE);

}

From source file:com.flysystem.core.adapter.local.Local.java

protected File ensureDirectory(File file) {
    if (!file.isDirectory()) {
        new File(file.getParent()).mkdirs();
    }/*from  w w w . j  ava2  s  .  c o  m*/
    return file;
}

From source file:com.apporiented.hermesftp.FtpServerApp.java

private void logPaths(File file) {
    log.info("Hermes Home: " + IOUtils.getHomeDir());

    log.info("Application context: " + file);
    if (file != null && file.getParent() != null) {
        System.setProperty("hermes.ctx.dir", file.getParent());
        log.info("Application context path: " + file.getParent());
    }//from w  ww . j  a v  a 2  s .  c  o m
}

From source file:com.opera.core.systems.util.ProfileUtils.java

public boolean isMainProfile(String prefsPath) {
    File prefsFile = new File(prefsPath);
    String absolutePrefsPath = prefsFile.getAbsolutePath();

    // Get user home
    String path = System.getProperty("user.home");

    if (isMac()) {
        /* Mac/*from w  w w  . j  av  a 2  s.c  o  m*/
         * ~/Library/Application Support/Opera 
         * ~/Library/Caches/Opera 
         * ~/Library/Preferences/Opera Preferences
         */
        File appSupport = new File(path + "/Library/Application Support/Opera");
        File cache = new File(path + "/Library/Caches/Opera");
        File prefs = new File(path + "/Library/Preferences/Opera Preference");

        // Check if profiles start with this path
        if (absolutePrefsPath.startsWith(appSupport.getAbsolutePath())
                || absolutePrefsPath.startsWith(cache.getAbsolutePath())
                || absolutePrefsPath.startsWith(prefs.getAbsolutePath()))
            return true;

    } else if (isWindows()) {

        // On XP and Vista/7: 
        String appData = System.getenv("APPDATA");
        File appFile = new File(appData + "\\Opera");
        if (absolutePrefsPath.startsWith(appFile.getAbsolutePath()))
            return true;

        // On XP:
        String homeDrive = System.getenv("HOMEDRIVE");
        String homePath = System.getenv("HOMEPATH");
        File homeOpera = new File(homeDrive + homePath + "\\Local Settings\\Application Data\\Opera");
        if (absolutePrefsPath.startsWith(homeOpera.getAbsolutePath()))
            return true;

        // In Vista/7:
        String localAppData = System.getenv("LOCALAPPDATA");
        File localAppDataFile = new File(localAppData + "\\Opera");
        if (absolutePrefsPath.startsWith(localAppDataFile.getAbsolutePath()))
            return true;

        // On all Windows systems, <Installation Path>\profile:
        File exeFile = new File(settings.getOperaBinaryLocation());
        String parentPath = exeFile.getParent();
        File profileFolder = new File(parentPath + "\\profile");

        //a/b/c/exe
        //a/b/c/profile
        if (prefsFile.equals(profileFolder))
            return true;

    } else {

        /* *nix */
        File dotOpera = new File(path + "/.opera");
        if (/*platform nix && */ prefsFile.equals(dotOpera))
            return true;

    }

    return false;
}

From source file:com.github.igor_kudryashov.utils.notes.NotesTempFile.java

/**
 * Seeking notesXXXXXX folder in temporary directory and checks for file ~notetp2.reg in this
 * folder./*from  w w w.j  ava 2  s.c  om*/
 * 
 * @param tempDir
 *            - temporary directory.
 * @return temporary directory if the file ~notetp2.reg exist in this directory.
 */
private String getTemDirFromTempDir(String tempDir) {
    String temp = null;
    File file = new File(tempDir);
    String[] directories = file.list(new FilenameFilter() {
        @Override
        public boolean accept(File current, String name) {
            return new File(current, name).isDirectory();
        }
    });
    for (int i = 0; i < directories.length; i++) {
        if (directories[i].startsWith("notes")) {
            // check "~notetp2.reg" file
            String regFilename = tempDir + File.separator + directories[i] + File.separator
                    + NOTES_REG_FILENAME;
            File regFile = new File(regFilename);
            if (regFile.exists()) {
                return regFile.getParent();
            }
        }
    }
    return temp;
}