Example usage for org.apache.commons.lang StringUtils substringBeforeLast

List of usage examples for org.apache.commons.lang StringUtils substringBeforeLast

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substringBeforeLast.

Prototype

public static String substringBeforeLast(String str, String separator) 

Source Link

Document

Gets the substring before the last occurrence of a separator.

Usage

From source file:de.tudarmstadt.ukp.csniper.resbuild.stuff.FilterPipe.java

public static void main(String[] args) throws IOException {
    List<String> files = new ArrayList<String>();
    int i = 0;//from w ww. j  a va  2 s  . c om
    for (File file : FileUtils.listFiles(new File(base), new String[] { "csv" }, true)) {
        String text = FileUtils.readFileToString(file, "UTF-8");
        files.add(StringUtils.substringBeforeLast(file.getName(), ".") + ".xml");
        if (StringUtils.containsAny(text, "")) {
            files.remove(StringUtils.substringBeforeLast(file.getName(), ".") + ".xml");
        }
        i++;
        if (i % 100 == 0) {
            System.out.println("ok:" + i);
        }
    }

    FileUtils.writeLines(new File("D:\\hadoop\\output\\BNC_new\\exclusions.txt"), "UTF-8", files);
}

From source file:com.intellij.lang.jsgraphql.endpoint.ide.completion.JSGraphQLEndpointImportUtil.java

public static String getImportName(Project project, PsiFile file) {
    final VirtualFile entryFile = JSGraphQLConfigurationProvider.getService(project).getEndpointEntryFile();
    final VirtualFile entryFileDir = entryFile != null ? entryFile.getParent() : null;
    final String name = StringUtils.substringBeforeLast(file.getName(), ".");
    return getImportName(entryFileDir, file.getVirtualFile(), name);
}

From source file:com.mmj.app.web.tools.PicTools.java

/**
 * ??//from w w w . j a v a2  s.  c  o  m
 * 
 * @param url
 * @param picSize
 * @return
 */
public static String processURL(String url, String suffix) {
    if (StringUtils.isEmpty(url)) {
        return StringUtils.EMPTY;
    }
    if (StringUtils.isEmpty(suffix)) {
        return url;
    }
    String pefix = url;
    if (StringUtils.contains(url, "=")) {
        pefix = StringUtils.substringBeforeLast(url, "=");
    } else if (StringUtils.contains(url, "=C")) {
        pefix = StringUtils.substringBeforeLast(url, "=C");
    } else {
        pefix = StringUtils.substringBeforeLast(url, DOT);
    }
    String dotStr = StringUtils.substringAfterLast(url, DOT);
    return pefix + suffix + DOT + dotStr;
}

From source file:com.github.dbourdette.otto.web.util.SizeInBytes.java

public static SizeInBytes fromValue(String value) {
    if (StringUtils.isEmpty(value)) {
        throw new IllegalArgumentException("value is not a valid size");
    }/*from w w w.  j  a v  a2  s. c o  m*/

    long multiplier = 1;

    if (value.endsWith("M")) {
        value = StringUtils.substringBeforeLast(value, "M");
        multiplier = SCALE * SCALE;
    } else if (value.endsWith("K")) {
        value = StringUtils.substringBeforeLast(value, "K");
        multiplier = SCALE;
    } else if (value.endsWith("B")) {
        value = StringUtils.substringBeforeLast(value, "B");
    }

    try {
        return new SizeInBytes(Long.parseLong(value) * multiplier);
    } catch (Exception e) {
        throw new IllegalArgumentException("value is not a valid size");
    }
}

From source file:DuplicatedMusicCleaner.java

public static void cleanupFolder(File folder) throws IOException {
    // System.out.println("Evaluate " + folder.getAbsolutePath());
    String[] fileNames = folder.list();
    Map<String, String> fileNamesWithoutExtension = new HashMap<String, String>();
    for (String fileName : fileNames) {
        File file = new File(folder, fileName);
        String nameWithoutExtension = StringUtils.substringBeforeLast(file.getName(), ".");
        fileNamesWithoutExtension.put(nameWithoutExtension, file.getAbsolutePath());
    }/*w  w  w .  ja  v a  2 s .c  o  m*/

    for (String fileName : fileNames) {
        // System.out.println("Evaluate " + fileName);
        File file = new File(folder, fileName);
        if (file.isDirectory()) {
            cleanupFolder(file);
        } else {

            String nameWithoutExtension = StringUtils.substringBeforeLast(file.getName(), ".");
            String suffix = " 1";
            if (nameWithoutExtension.endsWith(suffix)) {
                String nameWithoutSuffix = StringUtils.substringBeforeLast(nameWithoutExtension, suffix);
                if (fileNamesWithoutExtension.keySet().contains(nameWithoutSuffix)) {
                    File originalFile = new File(fileNamesWithoutExtension.get(nameWithoutSuffix));
                    long originalFileLength = originalFile.length();
                    long fileLength = file.length();
                    if (originalFileLength == fileLength) {
                        System.err.println("Delete " + file.getName());
                        FileUtils.deleteQuietly(file);
                        // FileUtils.moveFile(file, new
                        // File(file.getAbsoluteFile() + ".todelete"));
                    }
                }
            }
            /*
             * if(file.getName().endsWith(".todelete")) { String newFileName
             * = StringUtils.substringBeforeLast(file.getName(),
             * ".todelete"); File parent = file.getParentFile(); File
             * parentParent = parent.getParentFile(); newFileName =
             * parentParent.getName() + "_" + parent.getName() + "_" +
             * newFileName;
             * 
             * File target = new File("/Users/cyrilleleclerc/todelete",
             * newFileName); System.out.println(target);
             * FileUtils.moveFile(file, target);
             * 
             * }
             */
        }
    }

}

From source file:com.tesora.dve.common.PEUrl.java

public static String stripUrlParameters(final String url) {
    return StringUtils.substringBeforeLast(url.trim(), URL_PARAMETER_SEPARATOR);
}

From source file:edu.mayo.cts2.framework.plugin.service.bprdf.dao.id.ValueSetName.java

/**
 * Parses the.//  www. ja  v a  2s  .  c o  m
 *
 * @param name the name
 * @return the code system name
 */
public static ValueSetName parse(String name) {
    String acronym = StringUtils.substringBeforeLast(name, SEPARATOR);
    String ontologyId = StringUtils.substringAfterLast(name, SEPARATOR);

    return new ValueSetName(acronym, ontologyId);
}

From source file:edu.mayo.cts2.framework.plugin.service.bprdf.dao.id.CodeSystemVersionName.java

/**
 * Parses the.//  w ww  . j  a v a 2 s . c o  m
 *
 * @param name the name
 * @return the code system version name
 */
public static CodeSystemVersionName parse(String name) {
    String acronym = StringUtils.substringBeforeLast(name, SEPARATOR);
    String id = StringUtils.substringAfterLast(name, SEPARATOR);

    return new CodeSystemVersionName(acronym, id);
}

From source file:hr.fer.spocc.util.BasePropertyConstants.java

/**
 * Return the property name based on the specified prefix.
 * For example, if the prefix is "some.example." or "some.example", 
 * "some.example" will be returned. /*from  ww  w . ja v  a 2  s  .com*/
 * 
 * @param prefix the prefix
 * @return property name
 */
protected static String prefixToPropertyName(String prefix) {
    return StringUtils.substringBeforeLast(prefix, SEPARATOR);
}

From source file:com.spotify.docker.CompositeImageName.java

/**
 * An image name can be a plain image name or in the composite format &lt;name&gt;:&lt;tag&gt and
 * this factory method makes sure that we get the plain image name as well as all the desired tags
 * for an image, including any composite tag.
 *///from w w  w.jav  a  2  s.  c  om
static CompositeImageName create(final String imageName, final List<String> imageTags)
        throws MojoExecutionException {

    final String name = StringUtils.substringBeforeLast(imageName, ":");
    if (StringUtils.isBlank(name)) {
        throw new MojoExecutionException("imageName not set!");
    }

    final List<String> tags = new ArrayList<>();
    final String tag = StringUtils.substringAfterLast(imageName, ":");
    if (StringUtils.isNotBlank(tag)) {
        tags.add(tag);
    }
    if (imageTags != null) {
        tags.addAll(imageTags);
    }
    if (tags.size() == 0) {
        throw new MojoExecutionException("No tag included in imageName and no imageTags set!");
    }
    return new CompositeImageName(name, tags);
}