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

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

Introduction

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

Prototype

public static boolean equals(String filename1, String filename2) 

Source Link

Document

Checks whether two filenames are equal exactly.

Usage

From source file:integration.DeleteServiceFilesTest.java

/**
 * Gets a public repository on the OMERO data directory if one exists.
 * // w ww.java 2 s .c o  m
 * @return See above.
 * @throws Exception  Thrown if an error occurred.
 */
RepositoryPrx getLegacyRepository() throws Exception {
    RepositoryPrx legacy = null;
    RepositoryMap rm = factory.sharedResources().repositories();
    int repoCount = 0;
    String s = dataDir;
    for (OriginalFile desc : rm.descriptions) {
        String repoPath = desc.getPath().getValue() + desc.getName().getValue();
        s += "\nFound repository:" + desc.getPath().getValue() + desc.getName().getValue();
        if (FilenameUtils.equals(FilenameUtils.normalizeNoEndSeparator(dataDir),
                FilenameUtils.normalizeNoEndSeparator(repoPath))) {
            legacy = rm.proxies.get(repoCount);
            break;
        }
        repoCount++;
    }
    if (legacy == null) {
        throw new Exception("Unable to find legacy repository: " + s);
    }
    return legacy;
}

From source file:com.pdftron.pdf.utils.Utils.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static boolean isSdCardFile(Context context, File file) {
    if (!Utils.isKitKat()) {
        // not applicable for below kitkat
        return false;
    }// w ww  . j  a v  a 2  s .c  om
    if (file != null) {
        if (file.getParentFile() == null || file.getAbsolutePath().equals("/storage")) {
            // File cannot be on a SD-card
            return false;
        }
        final File storageDirectory = Environment.getExternalStorageDirectory();
        final File[] rootDirs = context.getExternalFilesDirs(null);
        if (rootDirs != null && rootDirs.length > 0) {
            for (File dir : rootDirs) {
                if (dir != null) {
                    try {
                        if (!FilenameUtils.equals(storageDirectory.getAbsolutePath(), dir.getAbsolutePath())
                                && !FileUtils.directoryContains(storageDirectory, dir)) {
                            while (dir.getParentFile() != null
                                    && !dir.getAbsolutePath().equalsIgnoreCase("/storage")) {
                                if (FilenameUtils.equals(file.getAbsolutePath(), dir.getAbsolutePath())
                                        || FileUtils.directoryContains(dir, file)) {
                                    // The current folder is on the SD-card
                                    return true;
                                }
                                dir = dir.getParentFile();
                            }
                        }
                    } catch (IOException ignored) {
                    }
                }
            }
        }
    }
    return false;
}

From source file:org.panbox.desktop.common.vfs.PanboxFSLinux.java

public synchronized void symlink(final String target, final String link) throws IOException {

    try {/* w w w  .  j  a  va  2  s.c  o  m*/
        // TODO: Here, we parse 3 times for the Share that manages the File
        VirtualFile vlink = getVirtualFileForFileName(link, true);
        String fullpath = FilenameUtils.getFullPath(link);
        String sharePath = FilenameUtils.normalize(fullpath.substring(0, fullpath.indexOf('/', 1) + 1));

        String shareloc = FilenameUtils.concat(fullpath, target);

        if (FilenameUtils.equals(sharePath, shareloc) || FilenameUtils.directoryContains(sharePath, shareloc)) {

            SecretKey sk = backingStorage.getObfuscationKeyForFile(shareloc);
            Obfuscator obfuscator = backingStorage.getObfuscator(shareloc);

            // create obfuscated symlink target
            String[] targetparts = target.split("/");
            StringBuffer res = new StringBuffer();

            if (target.startsWith(File.separator)) {
                res.append(File.separator);
            }

            for (int i = 0; i < targetparts.length; i++) {
                String cur = targetparts[i];
                if (cur.equals(".") || cur.equals("..")) {
                    res.append(cur);
                } else {
                    // append obfuscated part of path
                    res.append(obfuscator.obfuscate(cur, sk, true));
                }
                // append intermediary separators
                if (i < targetparts.length - 1) {
                    res.append(File.separator);
                }
            }

            if (target.endsWith(File.separator)) {
                res.append(File.separator);
            }

            String obfuscatedTarget = res.toString();
            Path ptarget = Paths.get(obfuscatedTarget);

            Path plink = Paths.get(vlink.getFileName());
            Files.createSymbolicLink(plink, ptarget);
            logger.debug("symlink, Target : " + obfuscatedTarget + ", Link: " + vlink.getFileName());
        } else {
            throw new IOException("Symlinks outside of shares are not supported.");
        }
    } catch (ObfuscationException e) {
        // logger.error("Could not obfuscate symlink target!", e);
        throw new IOException("Could not obfuscate symlink target!", e);
    }

}

From source file:org.panbox.desktop.common.vfs.PanboxFSLinux.java

public synchronized void readlink(final String path, final ByteBuffer buffer, final long size)
        throws IOException {

    try {/* w ww  .j a  v  a 2 s  .  co m*/
        // TODO: Here, we parse 3 times for the Share that manages the File
        String fullpath = FilenameUtils.getFullPath(path);
        String sharePath = FilenameUtils.normalize(fullpath.substring(0, fullpath.indexOf('/', 1) + 1));

        VirtualFile vpath = getVirtualFileForFileName(path);
        String target = Files.readSymbolicLink(vpath.getFile().toPath()).toString();

        String shareloc = FilenameUtils.concat(fullpath, target.toString());

        if (FilenameUtils.directoryContains(sharePath, shareloc) || FilenameUtils.equals(sharePath, shareloc)) {

            SecretKey sk = backingStorage.getObfuscationKeyForFile(shareloc);
            Obfuscator obfuscator = backingStorage.getObfuscator(shareloc);

            // create deobfuscated symlink target
            String[] targetparts = target.split("/");
            StringBuffer res = new StringBuffer();

            if (target.startsWith(File.separator)) {
                res.append(File.separator);
            }

            for (int i = 0; i < targetparts.length; i++) {
                String cur = targetparts[i];
                if (cur.equals(".") || cur.equals("..")) {
                    res.append(cur);
                } else {
                    // append obfuscated part of path
                    res.append(obfuscator.deObfuscate(cur, sk));
                }
                // append intermediary separators
                if (i < targetparts.length - 1) {
                    res.append(File.separator);
                }
            }

            if (target.endsWith(File.separator)) {
                res.append(File.separator);
            }

            byte[] ret = res.toString().getBytes();
            int realsize = Math.min(ret.length, (int) size);
            buffer.put(ret, 0, realsize);
            logger.debug("readline, Link : " + path + ", Target: " + res.toString());
        } else {
            throw new IOException("Symlinks outside of shares are not supported.");
        }
    } catch (ObfuscationException e) {
        throw new IOException("Error deobfuscating symlink contents!", e);
    }
}