Example usage for org.apache.commons.lang3 StringUtils removeEnd

List of usage examples for org.apache.commons.lang3 StringUtils removeEnd

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils removeEnd.

Prototype

public static String removeEnd(final String str, final String remove) 

Source Link

Document

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

A null source string will return null .

Usage

From source file:org.apache.falcon.resource.AbstractEntityManager.java

/**
 * Given the location of data, returns the feed.
 * @param type type of the entity, is valid only for feeds.
 * @param instancePath location of the data
 * @return Feed Name, type of the data and cluster name.
 */// ww w. ja v a  2  s.co  m
public FeedLookupResult reverseLookup(String type, String instancePath) {
    try {
        EntityType entityType = EntityType.getEnum(type);
        if (entityType != EntityType.FEED) {
            LOG.error("Reverse Lookup is not supported for entitytype: {}", type);
            throw new IllegalArgumentException("Reverse lookup is not supported for " + type);
        }

        instancePath = StringUtils.trim(instancePath);
        String instancePathWithoutSlash = instancePath.endsWith("/") ? StringUtils.removeEnd(instancePath, "/")
                : instancePath;
        // treat strings with and without trailing slash as same for purpose of searching e.g.
        // /data/cas and /data/cas/ should be treated as same.
        String instancePathWithSlash = instancePathWithoutSlash + "/";
        FeedLocationStore store = FeedLocationStore.get();
        Collection<FeedLookupResult.FeedProperties> feeds = new ArrayList<>();
        Collection<FeedLookupResult.FeedProperties> res = store.reverseLookup(instancePathWithoutSlash);
        if (res != null) {
            feeds.addAll(res);
        }
        res = store.reverseLookup(instancePathWithSlash);
        if (res != null) {
            feeds.addAll(res);
        }
        FeedLookupResult result = new FeedLookupResult(APIResult.Status.SUCCEEDED, "SUCCESS");
        FeedLookupResult.FeedProperties[] props = feeds.toArray(new FeedLookupResult.FeedProperties[0]);
        result.setElements(props);
        return result;

    } catch (IllegalArgumentException e) {
        throw FalconWebException.newException(e, Response.Status.BAD_REQUEST);
    } catch (Throwable throwable) {
        LOG.error("reverse look up failed", throwable);
        throw FalconWebException.newException(throwable, Response.Status.INTERNAL_SERVER_ERROR);
    }
}

From source file:org.apache.falcon.service.SharedLibraryHostingService.java

@SuppressWarnings("ConstantConditions")
public static void pushLibsToHDFS(FileSystem fs, String src, Path target, FalconPathFilter pathFilter)
        throws IOException, FalconException {
    if (StringUtils.isEmpty(src)) {
        return;/*from  w w w .ja  v a2s  .  com*/
    }
    LOG.debug("Copying libs from {}", src);
    createTargetPath(fs, target);

    for (String srcPaths : src.split(",")) {
        File srcFile = new File(srcPaths);
        File[] srcFiles = new File[] { srcFile };
        if (srcFile.isDirectory()) {
            srcFiles = srcFile.listFiles();
        }

        for (File file : srcFiles) {
            Path path = new Path(file.getAbsolutePath());
            String jarName = StringUtils.removeEnd(path.getName(), ".jar");
            if (pathFilter != null) {
                if (!pathFilter.accept(path)) {
                    continue;
                }
                jarName = pathFilter.getJarName(path);
            }

            Path targetFile = new Path(target, jarName + ".jar");
            if (fs.exists(targetFile)) {
                FileStatus fstat = fs.getFileStatus(targetFile);
                if (fstat.getLen() == file.length()) {
                    continue;
                }
            }
            fs.copyFromLocalFile(false, true, new Path(file.getAbsolutePath()), targetFile);
            fs.setPermission(targetFile, HadoopClientFactory.READ_EXECUTE_PERMISSION);
            LOG.info("Copied {} to {} in {}", file.getAbsolutePath(), targetFile.toString(), fs.getUri());
        }
    }
}

From source file:org.apache.falcon.snapshots.replication.HdfsSnapshotReplicator.java

private String getStagingUri(String storageUrl, String dir) {
    storageUrl = StringUtils.removeEnd(storageUrl, Path.SEPARATOR);
    return storageUrl + Path.SEPARATOR + dir;
}

From source file:org.apache.falcon.snapshots.replication.HdfsSnapshotReplicator.java

private String getSnapshotDir(String dirName) {
    dirName = StringUtils.removeEnd(dirName, Path.SEPARATOR);
    return dirName + Path.SEPARATOR + HdfsSnapshotUtil.SNAPSHOT_DIR_PREFIX + Path.SEPARATOR;
}

From source file:org.apache.falcon.snapshots.retention.HdfsSnapshotEvictor.java

protected static void evictSnapshots(DistributedFileSystem fs, String dirName, String ageLimit,
        int numSnapshots) throws FalconException {
    try {// w w w  .j  a  v a2 s  .  c o m
        LOG.info("Started evicting snapshots on dir {}{} using policy {}, agelimit {}, numSnapshot {}",
                fs.getUri(), dirName, ageLimit, numSnapshots);

        long evictionTime = System.currentTimeMillis() - EvictionHelper.evalExpressionToMilliSeconds(ageLimit);

        dirName = StringUtils.removeEnd(dirName, Path.SEPARATOR);
        String snapshotDir = dirName + Path.SEPARATOR + HdfsSnapshotUtil.SNAPSHOT_DIR_PREFIX + Path.SEPARATOR;
        FileStatus[] snapshots = fs.listStatus(new Path(snapshotDir));
        if (snapshots.length <= numSnapshots) {
            // no eviction needed
            return;
        }

        // Sort by last modified time, ascending order.
        Arrays.sort(snapshots, new Comparator<FileStatus>() {
            @Override
            public int compare(FileStatus f1, FileStatus f2) {
                return Long.compare(f1.getModificationTime(), f2.getModificationTime());
            }
        });

        for (int i = 0; i < (snapshots.length - numSnapshots); i++) {
            // delete if older than ageLimit while retaining numSnapshots
            if (snapshots[i].getModificationTime() < evictionTime) {
                fs.deleteSnapshot(new Path(dirName), snapshots[i].getPath().getName());
            }
        }

    } catch (ELException ele) {
        LOG.warn("Unable to parse retention age limit {} {}", ageLimit, ele.getMessage());
        throw new FalconException("Unable to parse retention age limit " + ageLimit, ele);
    } catch (IOException ioe) {
        LOG.warn("Unable to evict snapshots from dir {} {}", dirName, ioe);
        throw new FalconException("Unable to evict snapshots from dir " + dirName, ioe);
    }

}

From source file:org.apache.marmotta.platform.ldp.util.AbstractResourceUriGenerator.java

protected AbstractResourceUriGenerator(LdpService ldpService, String container,
        RepositoryConnection connection) {
    this.ldpService = ldpService;
    this.container = StringUtils.removeEnd(container, "/");
    this.connection = connection;
}

From source file:org.apache.marmotta.platform.ldp.webservices.PreferHeader.java

/**
 * Parse a PreferHeader./*from ww w .j  a  v  a 2  s.  c  o m*/
 * @param headerValue the header value to parse
 * @return the parsed PreferHeader
 */
public static PreferHeader valueOf(String headerValue) {
    if (StringUtils.isBlank(headerValue)) {
        log.error("Empty Prefer-Header - what should I do now?");
        throw new InvalidArgumentException();
    }

    String pref = null, val = null;
    final Map<String, String> params = new LinkedHashMap<>();
    final String[] parts = headerValue.split("\\s*;\\s");
    for (int i = 0; i < parts.length; i++) {
        final String part = parts[i];
        final String[] kv = part.split("\\s*=\\s*", 2);
        if (i == 0) {
            pref = StringUtils.trimToNull(kv[0]);
            if (kv.length > 1) {
                val = StringUtils.trimToNull(StringUtils.removeStart(StringUtils.removeEnd(kv[1], "\""), "\""));
            }
        } else {
            String p, pval = null;
            p = StringUtils.trimToNull(kv[0]);
            if (kv.length > 1) {
                pval = StringUtils
                        .trimToNull(StringUtils.removeStart(StringUtils.removeEnd(kv[1], "\""), "\""));
            }
            params.put(p, pval);
        }
    }

    final PreferHeader header = new PreferHeader(pref);
    header.preferenceValue = val;
    header.params = params;

    return header;
}

From source file:org.apache.maven.plugin.surefire.util.DirectoryScanner.java

private String convertToJavaClassName(String test) {
    return StringUtils.removeEnd(test, ".class").replace(FS, ".");
}

From source file:org.apache.maven.plugin.surefire.util.DirectoryScanner.java

private static String[] processIncludesExcludes(List<String> list) {
    List<String> newList = new ArrayList<String>();
    for (Object aList : list) {
        String include = (String) aList;
        String[] includes = include.split(",");
        Collections.addAll(newList, includes);
    }/*from   w  w w  .j  a  v  a  2  s . c  o m*/

    String[] incs = new String[newList.size()];

    for (int i = 0; i < incs.length; i++) {
        String inc = newList.get(i);
        if (inc.endsWith(JAVA_SOURCE_FILE_EXTENSION)) {
            inc = StringUtils.removeEnd(inc, JAVA_SOURCE_FILE_EXTENSION) + JAVA_CLASS_FILE_EXTENSION;
        }
        incs[i] = inc;

    }
    return incs;
}

From source file:org.apache.maven.plugin.surefire.util.ScannerUtil.java

@Nonnull
public static String convertJarFileResourceToJavaClassName(@Nonnull String test) {
    return StringUtils.removeEnd(test, ".class").replace("/", ".");
}