Example usage for org.apache.commons.io FilenameUtils normalize

List of usage examples for org.apache.commons.io FilenameUtils normalize

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils normalize.

Prototype

public static String normalize(String filename) 

Source Link

Document

Normalizes a path, removing double and single dot path steps.

Usage

From source file:ch.unibas.fittingwizard.application.base.MoleculesDir.java

public MoleculesDir(File directory) {
    directory.mkdir();//from   ww w  .  java2 s  . c om
    if (!directory.isDirectory()) {
        throw new IllegalArgumentException("Given directory does not exist " + directory.getAbsolutePath());
    }
    this.directory = new File(FilenameUtils.normalize(directory.getAbsolutePath()));
}

From source file:de.micromata.genome.util.text.NormalizeFileNameTest.java

private void test(String fn) {
    String fnnorm = FilenameUtils.normalize(fn);
    File f = new File(fn);
    String abf = f.getAbsolutePath();
    System.out.println("UnNorm: " + fn + "; norm: " + fnnorm + "; abspath: " + abf);
}

From source file:com.omertron.slackbot.utils.PropertiesUtil.java

/**
 * Set the properties filename/* w  w  w  .  java 2  s  . co m*/
 *
 * @param streamName
 * @return
 */
public static boolean setPropertiesStreamName(final String streamName) {
    LOG.info("Using properties file '{}'", FilenameUtils.normalize(streamName));

    try (InputStream propertiesStream = new FileInputStream(streamName);) {
        try (Reader reader = new InputStreamReader(propertiesStream, PROPERTIES_CHARSET)) {
            PROPS.load(reader);
        }
    } catch (IOException error) {
        LOG.error(
                "Failed loading file {}: Please check your configuration. The properties file should be in the classpath.",
                streamName, error);
        return Boolean.FALSE;
    }
    return Boolean.TRUE;
}

From source file:net.sf.zekr.engine.server.DefaultHttpServerTest.java

public void testGetRealPath() throws Exception {
    String url = "[base]/path/to/somewhere";
    String path = (String) server.pathLookup.get(HttpServer.BASE_RESOURCE);
    path = FilenameUtils.normalize(path + "/path/to/somewhere");
    assertEquals(path, server.toRealPath(url));

    url = "[workspace]/path/to/somewhere";
    path = (String) server.pathLookup.get(HttpServer.WORKSPACE_RESOURCE);
    path = FilenameUtils.normalize(path + "/path/to/somewhere");
    assertEquals(path, server.toRealPath(url));

    url = "[cache]/path/to/somewhere";
    path = (String) server.pathLookup.get(HttpServer.CACHED_RESOURCE);
    path = FilenameUtils.normalize(path + "/path/to/somewhere");
    assertEquals(path, server.toRealPath(url));

    url = "[absolute]c:/path/to/somewhere";
    path = FilenameUtils.normalize("c:/path/to/somewhere");
    assertEquals(path, server.toRealPath(url));
}

From source file:com.indoqa.lang.util.FileUtils.java

public static String getRelativeFilePath(String filePath, String directoryPath) {
    String baseDir = FilenameUtils.normalize(directoryPath + File.separator);
    String currentFile = FilenameUtils.normalize(filePath);

    if (!currentFile.startsWith(baseDir)) {
        throw new IllegalArgumentException(
                "Failed to get the relative file path. The given file path must start with the base directory!");
    }//from ww w  . jav a 2  s  .com

    return currentFile.substring(baseDir.length());
}

From source file:ffx.Main.java

/**
 * Create an instance of Force Field X//ww w . j  ava  2s .com
 *
 * @param args an array of {@link java.lang.String} objects.
 * @throws java.lang.Exception if any.
 */
public static void main(String[] args) throws Exception {
    /**
     * Process any "-D" command line flags.
     */
    args = processProperties(args);

    /**
     * Configure our logging.
     */
    startLogging();

    /**
     * Print out help for the command line interface.
     */
    if (GraphicsEnvironment.isHeadless() && args.length < 2) {
        commandLineInterfaceHelp();
    }

    /**
     * Determine host name and process ID.
     */
    environment();

    /**
     * Start up the Parallel Java communication layer.
     */
    startParallelJava(args);

    /**
     * Run the pKa input GUI if requested. Halts execution until GUI exits.
     */
    /**
     * if (System.getProperty("pKaCalc") != null) { if
     * (System.getProperty("pKaCalc").equals("true")) { ffx.pka.pKaRun
     * runnable = new ffx.pka.pKaRun(); Thread t = new Thread(runnable,"pKa
     * Thread"); t.start(); t.join(); final int NUM_PKA_ARGS = 25; String[]
     * newArgs = new String[NUM_PKA_ARGS]; int currentArg = 0; for (int i=0;
     * i < newArgs.length; i++) { newArgs[currentArg] = runnable.getArg(i);
     * if (runnable.getArg(i) == null) { String temp = runnable.getArg(i -
     * 1); if (temp.startsWith("-s") || temp.startsWith("-f")) {
     * currentArg--; } } else { currentArg++; } } args = newArgs; } }
     */
    // Print the header.
    // Moved this here so I could see the args being supplied by pKaRun.
    header(args);

    /**
     * Parse the specified command or structure file.
     */
    File commandLineFile = null;
    int nArgs = args.length;
    if (nArgs > 0) {
        commandLineFile = new File(args[0]);
        // Resolve a relavtive path
        if (commandLineFile.exists()) {
            commandLineFile = new File(FilenameUtils.normalize(commandLineFile.getAbsolutePath()));
        }
    }

    /**
     * Convert the args to a List<String>.
     */
    List<String> argList = new ArrayList<>(nArgs);
    if (nArgs > 1) {
        for (int i = 1; i < nArgs; i++) {
            argList.add(args[i]);
        }
    }

    /**
     * Start up the GUI or CLI version of Force Field X.
     */
    if (!GraphicsEnvironment.isHeadless()) {
        startGraphicalUserInterface(commandLineFile, argList);
    } else {
        startCommandLineInterface(commandLineFile, argList);
    }
}

From source file:com.github.ipaas.ideploy.agent.util.ZipUtil.java

/**
 * //  ww w.j a  v  a  2s  .c om
 * @param srcFile  ?
 * @param targetDir 
 * @throws Exception
 */
public static void unZip(String zipFile, String targetDir) throws Exception {
    ZipFile zipfile = new ZipFile(zipFile);
    try {
        Enumeration<ZipEntry> entries = zipfile.getEntries();
        if (entries == null || !entries.hasMoreElements()) {
            return;
        }
        //  
        FileUtils.forceMkdir(new File(targetDir));

        // ??

        while (entries.hasMoreElements()) {
            ZipEntry zipEntry = entries.nextElement();
            String fname = zipEntry.getName();

            // 

            if (zipEntry.isDirectory()) {
                String fpath = FilenameUtils.normalize(targetDir + "/" + fname);
                FileUtils.forceMkdir(new File(fpath));
                continue;

            }
            // ?

            if (StringUtils.contains(fname, "/")) {
                String tpath = StringUtils.substringBeforeLast(fname, "/");
                String fpath = FilenameUtils.normalize(targetDir + "/" + tpath);
                FileUtils.forceMkdir(new File(fpath));
            }
            // ? 
            InputStream input = null;
            OutputStream output = null;

            try {
                input = zipfile.getInputStream(zipEntry);
                String file = FilenameUtils.normalize(targetDir + "/" + fname);
                output = new FileOutputStream(file);
                IOUtils.copy(input, output);
            } finally {
                IOUtils.closeQuietly(input);
                IOUtils.closeQuietly(output);
            }
        }
    } finally {
        ZipFile.closeQuietly(zipfile);
    }

}

From source file:net.sf.zekr.engine.server.HttpServer.java

protected HttpServer() {
    pathLookup.put(CACHED_RESOURCE, FilenameUtils.normalize(Naming.getViewCacheDir()));
    pathLookup.put(WORKSPACE_RESOURCE, FilenameUtils.normalize(Naming.getWorkspace()));
    pathLookup.put(BASE_RESOURCE, FilenameUtils.normalize(GlobalConfig.RUNTIME_DIR));
}

From source file:de.uni_hildesheim.sse.ant.versionReplacement.PluginVersionReplacer.java

/**
 * Updates the version numbers of a plugin.
 * @param tmpFolder A temporary folder where files can be created and deleted.
 * Will be used for unpacking the plugin.
 * @param plugin The location of a plugin (jar file) to transform.
 * @param version The new version number of the plugin.
 * @param destinationFolder The destination folder where the transformed plugin shall be saved to.
 * @throws IOException /*from   w  w w  . j a v  a  2  s .c o  m*/
 */
static void updatePlugins(File tmpFolder, File plugin, String version, File destinationFolder)
        throws IOException {

    unZipIt(plugin, tmpFolder);
    GenericVersionReplacer replacer = new GenericVersionReplacer();
    replacer.setVersion(version);
    replacer.setPath(tmpFolder.getAbsolutePath());
    replacer.execute();

    File destFile = new File(destinationFolder, plugin.getName());
    String basePath = FilenameUtils.normalize(tmpFolder.getAbsolutePath());
    if (!basePath.endsWith(File.separator)) {
        basePath += File.separator;
    }
    try (ZipOutputStream out = new JarOutputStream(new FileOutputStream(destFile))) {
        addDir(basePath, tmpFolder, out);
    }
}

From source file:com.opendoorlogistics.core.geometry.ShapefileLink.java

public ShapefileLink(String filename, String typename, String featureId) {
    this.filename = FilenameUtils.normalize(filename);
    this.typename = typename;
    this.featureId = featureId;

    // Also save standardised version for the hash lookup, including standardising slashes in the filename
    // to stop issues with shapefilelink generated in linux and used in windows (or vice-versa).
    filenameStd = Strings.std(this.filename).replace("/", "\\");
    typenameStd = Strings.std(typename);
    featureIdStd = Strings.std(featureId);
}