Example usage for java.lang String endsWith

List of usage examples for java.lang String endsWith

Introduction

In this page you can find the example usage for java.lang String endsWith.

Prototype

public boolean endsWith(String suffix) 

Source Link

Document

Tests if this string ends with the specified suffix.

Usage

From source file:Main.java

/**
 * Returns GET url with appended parameters.
 *
 * @param url//from ww  w. j av a  2  s .  com
 * @param params
 * @return
 */
public static String toGetUrl(String url, Bundle params) {
    if (params != null) {
        if (!url.endsWith("?")) {
            url = url + "?";
        }

        for (String key : params.keySet()) {
            url = url + key + "=" + params.getString(key) + "&";
        }
    }
    return url;
}

From source file:Main.java

public static String getParentPath(String remotePath) {
    String parentPath = new File(remotePath).getParent();
    parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR;
    return parentPath;
}

From source file:Main.java

private static URL getRootUrlForClass(Class<?> cls) {
    ClassLoader classLoader = cls.getClassLoader();
    String resource = cls.getName().replace('.', '/') + ".class";
    if (classLoader == null) {
        // A null class loader means the bootstrap class loader. In this case we use the
        // system class loader. This is safe since we can assume that the system class
        // loader uses parent first as delegation policy.
        classLoader = ClassLoader.getSystemClassLoader();
    }/*w  w  w  . j  a v a 2  s .  co  m*/
    URL url = classLoader.getResource(resource);
    if (url == null) {
        return null;
    }
    String file = url.getFile();
    if (file.endsWith(resource)) {
        try {
            return new URL(url.getProtocol(), url.getHost(), url.getPort(),
                    file.substring(0, file.length() - resource.length()));
        } catch (MalformedURLException ex) {
            return null;
        }
    } else {
        return null;
    }
}

From source file:Main.java

static public InputStream createInputStream(File file) throws IOException {
    String filename = file.getName().toLowerCase();
    if (filename.endsWith(".gz")) {
        // a buffered output stream sped processing up by 4X! in prod
        GZIPInputStream gis = new GZIPInputStream(new FileInputStream(file), 1024 * 1024); // 1 MB buffer
        return new BufferedInputStream(gis, 1024 * 1024); // 1 MB buffer
        /**        } else if (filename.endsWith(".lzf")) {
         // a buffered output stream is not necessary
         return new LZFInputStream(new FileInputStream(file));
         *///from www . ja  v a 2 s. c om
    } else {
        return null;
    }
}

From source file:Main.java

private static boolean checkEndsWithInStringArray(String checkItsEnd, String[] fileEndings) {
    for (String aEnd : fileEndings) {
        if (checkItsEnd.endsWith(aEnd))
            return true;
    }/*from w ww . j a  v a 2  s  .c  o m*/
    return false;
}

From source file:it.serasoft.pdi.PDITools.java

private static void startAnalysis(File f, boolean followLinks) {

    String name = f.getName();

    if (name.endsWith(EXT_PDI_JOB)) {
        ParseJob pje = new ParseJob(f, 0, followLinks);
        pje.parse();//from   ww  w  .ja v a 2s  .  com
    } else if (name.endsWith(EXT_PDI_TRANSFORMATION)) {
        ParseTransformation parseTransf = new ParseTransformation(f, 0, followLinks);
        parseTransf.parse();
    }
}

From source file:Main.java

public static <T> Set<Class<T>> findClassesAssignableFrom(String packageName, Class<T> assignableFrom)
        throws IOException, ClassNotFoundException {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    Set<Class<T>> classes = new HashSet<Class<T>>();
    String path = packageName.replace('.', '/');
    URL resource = loader.getResource(path);
    if (resource != null) {
        String filePath = resource.getFile();
        if (filePath != null && new File(filePath).isDirectory()) {
            for (String file : new File(filePath).list()) {
                if (file.endsWith(".class")) {
                    String name = packageName + '.' + file.substring(0, file.indexOf(".class"));
                    Class<T> clazz = (Class<T>) Class.forName(name);
                    if (assignableFrom.isAssignableFrom(clazz))
                        classes.add(clazz);
                }//from ww w  .  j  a  v a  2s .c om
            }
        }
    }
    return classes;
}

From source file:Main.java

public static String uuidToString(UUID uuid) {
    String uuidString = uuid.toString();

    if (uuidString.startsWith(BASE_UUID_START) && uuidString.endsWith(BASE_UUID_END)) {
        return uuidString.substring(4, 8);
    }//from  w  ww  . jav a2s .  co m

    return uuidString;
}

From source file:Main.java

private static String removeQuotesIfPresent(String inputString) {
    int startIndex = inputString.startsWith("\"") ? 1 : 0;
    int endIndex = inputString.endsWith("\"") ? inputString.length() - 1 : inputString.length();
    return inputString.substring(startIndex, endIndex);
}

From source file:Main.java

public static String getDexClassName(String dottedClassName) {
    if (dottedClassName == null || dottedClassName.isEmpty())
        throw new RuntimeException("Empty class name detected");

    String slashedName = dottedClassName.replace('.', '/');
    if (slashedName.startsWith("L") && slashedName.endsWith(";"))
        return slashedName;
    return "L" + slashedName + ";";
}