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

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

Introduction

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

Prototype

public static String getPrefix(String filename) 

Source Link

Document

Gets the prefix from a full filename, such as C:/ or ~/.

Usage

From source file:jodtemplate.util.Utils.java

public static String removePrefixSeparator(final String path) {
    final String prefix = FilenameUtils.getPrefix(path);
    if ("/".equals(prefix) || "\\".equals(prefix)) {
        return StringUtils.substring(path, 1);
    }/*www  .j av  a2 s .  com*/
    return path;
}

From source file:com.thoughtworks.go.util.FilenameUtil.java

public static boolean isNormalizedPathOutsideWorkingDir(String path) {
    final String normalize = FilenameUtils.normalize(path);
    final String prefix = FilenameUtils.getPrefix(normalize);
    return (normalize != null && StringUtils.isBlank(prefix));
}

From source file:com.r573.enfili.common.io.file.PathBuilder.java

private void init(String initialPath) {
    this.separator = File.separator;
    this.prefix = FilenameUtils.getPrefix(initialPath);

    this.elements = new LinkedList<String>();

    String pathWithoutPrefix = FilenameUtils.getPath(initialPath);
    String[] initialPathParts = pathWithoutPrefix.split("\\" + separator);
    for (int i = 0; i < initialPathParts.length; i++) {
        String thisPart = initialPathParts[i];
        if ((thisPart != null) && (!thisPart.isEmpty())) {
            elements.add(thisPart);//from  w  w w  .j  a v  a 2s .  c  o m
        }
    }
    elements.add(FilenameUtils.getName(initialPath));
}

From source file:com.kamike.misc.FsNameUtils.java

public static String getName(String disk, String filename, String fid, String uid, Date date) {
    String name = FilenameUtils.getName(filename);
    String prefix = FilenameUtils.getPrefix(filename);

    String extension = FilenameUtils.getExtension(filename);
    //?/*ww w. j  ava2 s . com*/
    return getName(prefix, disk, getShortDate(date), name, fid, uid, extension);

}

From source file:net.sourceforge.jencrypt.lib.FolderList.java

/**
 * Return the parent folder or the drive letter on Windows systems
 *//*  w ww  .j a v  a 2  s .c om*/
private String getParent(File topFolder) {

    File topFolderParent = topFolder.getParentFile();

    if (topFolderParent == null) {
        return FilenameUtils.getPrefix(topFolder.getAbsolutePath());
    } else
        return topFolderParent.getPath();
}

From source file:com.sangupta.jerry.util.FileUtils.java

/**
 * Returns if the given file path is an absolute file path or not.
 * //w w  w. j av a  2 s .co  m
 * @param filePath
 *            the file path to search for
 * 
 * @return <code>true</code> if the filepath is absolute, <code>false</code>
 *         otherwise
 */
public static boolean isAbsolutePath(String filePath) {
    if (filePath == null) {
        throw new IllegalArgumentException("Filepath cannot be null");
    }

    // normalize
    filePath = FilenameUtils.normalize(filePath);

    // now check
    String prefix = FilenameUtils.getPrefix(filePath);

    if (AssertUtils.isEmpty(prefix)) {
        return false;
    }

    return true;
}

From source file:com.kamike.misc.FsNameUtils.java

public static String getName(String disk, String filename, String fid, String uid) {
    String name = FilenameUtils.getName(filename);
    String prefix = FilenameUtils.getPrefix(filename);
    Date date = new Date(System.currentTimeMillis());
    String extension = FilenameUtils.getExtension(filename);
    return getName(prefix, disk, getShortDate(date), name, fid, uid, extension);
}

From source file:com.sangupta.jerry.util.FileUtils.java

/**
 * Resolve a file path into its corresponding {@link File} object. This method
 * also makes sure that '~' can be used to refer to the user's home directory - the
 * standard way on Linux and OS X.//w  ww  . j ava2  s .c  o m
 * 
 * @param filePath
 * @return <code>null</code> if filePath is empty, {@link File} instance otherwise.
 * 
 */
public static File resolveToFile(String filePath) {
    if (AssertUtils.isEmpty(filePath)) {
        return null;
    }

    if ("..".equals(filePath)) {
        return new File(".").getAbsoluteFile().getParentFile().getParentFile();
    }

    if (filePath.startsWith("../") || filePath.startsWith("..\\")) {
        // replace initial path with current path
        filePath = new File(".").getAbsoluteFile().getParentFile().getParentFile().getAbsolutePath()
                + File.separator + filePath.substring(2);
    }

    if (filePath.startsWith("./") || filePath.startsWith(".\\")) {
        // replace initial path with current path
        filePath = new File(".").getAbsoluteFile().getParentFile().getAbsolutePath() + File.separator
                + filePath.substring(2);
    }

    // normalize
    filePath = FilenameUtils.normalize(filePath);

    // now check
    String prefix = FilenameUtils.getPrefix(filePath);

    if (AssertUtils.isEmpty(prefix)) {
        return new File(filePath);
    }

    // check for user home
    if (filePath.charAt(0) == '~') {
        if (filePath.length() == 1) {
            return getUsersHomeDirectory();
        }

        if (filePath.length() == 2 && filePath.equals("~/")) {
            return getUsersHomeDirectory();
        }

        return new File(getUsersHomeDirectory(), filePath.substring(2));
    }

    return new File(filePath);
}

From source file:jp.classmethod.aws.gradle.cloudformation.AmazonCloudFormationPlugin.java

private String createKey(String name, Object version, String prefix) {
    String path = name.substring(FilenameUtils.getPrefix(name).length());
    String baseName = FilenameUtils.getBaseName(name);
    String extension = FilenameUtils.getExtension(name);
    return String.format("%s/%s/%s-%s-%s%s", new Object[] { prefix, path, baseName, version, createTimestamp(),
            extension.length() > 0 ? "." + extension : "" });
}

From source file:com.cordys.coe.ac.emailio.archive.FileArchiver.java

/**
 * @see  com.cordys.coe.ac.emailio.archive.AbstractArchiver#postInit(int, XPathMetaInfo, String,
 *       IManagedComponent)/*www  .j  a v a  2 s.  c om*/
 */
@Override
protected void postInit(int iParameters, XPathMetaInfo xmi, String sOrganization, IManagedComponent mcParent) {
    String sArchiveFolder = getStringParameter(PARAM_ARCHIVE_FOLDER);

    if (!StringUtil.isSet(sArchiveFolder)) {
        sArchiveFolder = EmailIOConnectorConstants.DEPLOY_FOLDER + "/archiver";
    }

    if (FilenameUtils.getPrefix(sArchiveFolder).length() == 0) {
        // Relative path
        m_fArchive = new File(new File(EIBProperties.getInstallDir()), sArchiveFolder);
    } else {
        m_fArchive = new File(sArchiveFolder);
    }

    if (!m_fArchive.exists()) {
        m_fArchive.mkdirs();
    }

    // Get the max raw filesize (in megabytes
    String sZipLevel = getStringParameter(PARAM_ZIP_LEVEL);

    if (!StringUtil.isSet(sZipLevel)) {
        sZipLevel = "100";
    }
    m_iZipLevel = Integer.parseInt(sZipLevel);

    if (LOG.isDebugEnabled()) {
        LOG.debug("Location: " + m_fArchive.getAbsolutePath() + "\nZip level: " + m_iZipLevel);
    }
}