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

public static boolean enclosed(String line, String s) {
    return line.startsWith(s) && line.endsWith(s);
}

From source file:Main.java

/**
 * Checks if this directory has a file with suffix suffix
 * @param f - directory//  w  ww  . j a v  a2 s.c  o  m
 * @return
 */
public static boolean hasFileWithSuffix(File f, String suffix) {
    if (f.isDirectory()) {
        for (String s : f.list()) {
            if (s.endsWith(suffix))
                return true;
        }
        return false;
    } else {
        return false;
    }
}

From source file:Main.java

public static boolean isFileAncestorOf(String parentPath, String childPath) {
    if (!parentPath.endsWith(File.separator)) {
        parentPath += File.separator;
    }/*from  w  ww. j a  v  a2  s .c  om*/
    if (!childPath.endsWith(File.separator)) {
        childPath += File.separator;
    }
    return childPath.startsWith(parentPath);
}

From source file:Main.java

public static boolean isASFFile(String in) {
    in = in.toLowerCase(Locale.US);
    return in.endsWith(".asf") || in.endsWith(".wm");
}

From source file:Main.java

public static byte[] downloadImage(String imageUrl) {
    if (imageUrl.endsWith(".jpg") || imageUrl.endsWith(".bmp") || imageUrl.endsWith(".png")
            || imageUrl.endsWith(".gif")) {
        try {//from   ww w.j  a  v  a2  s .c om
            URL url = new URL(imageUrl);
            URLConnection urlConn = url.openConnection();
            InputStream is = urlConn.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is);
            ByteArrayBuffer baf = new ByteArrayBuffer(50);
            int current = 0;

            while ((current = bis.read()) != -1) {
                baf.append((byte) current);
            }

            return baf.toByteArray();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return null;
}

From source file:Main.java

public static boolean isLosslessSupported(File f) {
    String s = f.toString();
    if (s.endsWith(".flac") || s.endsWith(".FLAC"))
        return true;
    else if (s.endsWith(".ape") || s.endsWith(".APE"))
        return true;
    else if (s.endsWith(".wav") || s.endsWith(".WAV"))
        return true;
    else if (s.endsWith(".wv") || s.endsWith(".WV"))
        return true;
    else if (s.endsWith(".mpc") || s.endsWith(".MPC"))
        return true;
    else if (s.endsWith(".m4a") || s.endsWith(".M4A"))
        return true;
    else//w  w  w.j  a v  a2  s.  co m
        return false;
}

From source file:Main.java

/**
 * Removes suffix string of String parameter and returns it back, otherwise returns null if suffix is invalid i.e. doesn't exist at the end like a suffix should
 * @param stringToTrimSuffixOf//from ww w  . ja  v a 2s  .  com
 * @param suffixStringToRemove
 * @return
 */
public static String sansSuffixOfString(String stringToTrimSuffixOf, String suffixStringToRemove) {
    if (stringToTrimSuffixOf.endsWith(suffixStringToRemove)) {
        return stringToTrimSuffixOf.substring(0, stringToTrimSuffixOf.length() - suffixStringToRemove.length());
    } else {
        return null;
    }
}

From source file:Main.java

/**
 * Tells if the zip data should only be stored and not be compressed.
 * @param name The name of the zip entry
 * @return <code>true</code> for store only and <code>false</code> for compress.
 *///from w w  w . j a  v a  2 s  . com
public static boolean isStoreOnlyFile(String name) {
    name = name.toLowerCase();
    if (name.endsWith(".jpg") || name.endsWith(".jpeg")) {
        return true;
    } else if (name.endsWith(".png")) {
        return true;
    } else if (name.endsWith(".gif")) {
        return true;
    } else if (name.endsWith(".zip") || name.endsWith(".rar")) {
        return true;
    }
    return false;
}

From source file:Main.java

public static String getMucNumId(String mucId) {
    if (!TextUtils.isEmpty(mucId)) {
        if (mucId.endsWith(MUC_TAIL)) {
            return mucId.substring(0, mucId.lastIndexOf(MUC_TAIL));
        }//from  w w  w. j a va  2 s  . c  o m
    }
    return mucId;
}

From source file:Main.java

static String encodeBase64String(byte[] binaryData) {
    String encodedString = Base64.encodeBase64String(binaryData);

    if (encodedString.endsWith("\r\n")) {
        encodedString = encodedString.substring(0, encodedString.length() - 2);
    }/*  w  w w  . ja v  a 2  s.  co  m*/
    return encodedString;
}