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

/**
 * Return the position of the host in MASK_HOSTS, or -1 if it isn't a known URL masker
 *///from  w w w .  j  a  va  2  s.  c om
public static int getMaskedId(Uri uri) {
    String host = uri.getHost();
    for (int i = 0; i < MASK_HOSTS.length; i++) {
        if (host.endsWith(MASK_HOSTS[i])) {
            if (MASK_HOSTS_SEG[i] == null) {
                return i;
            } else {
                List pathSegments = uri.getPathSegments();
                if (pathSegments == null)
                    return -1;
                if (pathSegments.size() > 0 && MASK_HOSTS_SEG[i].equals(pathSegments.get(0)))
                    return i;
            }
        }
    }
    return -1;
}

From source file:Main.java

public static boolean endsWithAny(String stringToMatch, String... stringToCheckEquals) {
    for (final String candidate : stringToCheckEquals) {
        if (stringToMatch.endsWith(candidate)) {
            return true;
        }//from w w  w  .j  ava  2s  .c om
    }
    return false;
}

From source file:Main.java

public static String getPermission(int permission) {
    StringBuilder permissionStr = new StringBuilder();
    String binaryString = Integer.toBinaryString(permission);
    binaryString = String.format("%16s", binaryString).replace(' ', '0');
    int len = binaryString.length();
    //PERMISSION_READ (0x00000001)
    if (binaryString.charAt(len - 1) == '1') {
        permissionStr.append("READ,");
    }//ww w. java 2  s .  co m
    //PERMISSION_READ_ENCRYPTED (0x00000002)
    if (binaryString.charAt(len - 2) == '1') {
        permissionStr.append("READ_ENCRYPTED,");
    }
    //PERMISSION_READ_ENCRYPTED_MITM (0x00000004)
    if (binaryString.charAt(len - 3) == '1') {
        permissionStr.append("READ_ENCRYPTED_MITM,");
    }

    //PERMISSION_WRITE (0x00000010)
    if (binaryString.charAt(len - 5) == '1') {
        permissionStr.append("WRITE,");
    }
    //PERMISSION_WRITE_ENCRYPTED (0x00000020)
    if (binaryString.charAt(len - 6) == '1') {
        permissionStr.append("WRITE_ENCRYPTED,");
    }
    //PERMISSION_WRITE_ENCRYPTED_MITM (0x00000040)
    if (binaryString.charAt(len - 7) == '1') {
        permissionStr.append("WRITE_ENCRYPTED_MITM,");
    }

    //PERMISSION_WRITE_SIGNED (0x00000080)
    if (binaryString.charAt(len - 8) == '1') {
        permissionStr.append("WRITE_ENCRYPTED_MITM,");
    }
    //PERMISSION_WRITE_SIGNED_MITM (0x00000100)
    if (binaryString.charAt(len - 9) == '1') {
        permissionStr.append("WRITE_SIGNED_MITM,");
    }

    String perStr = permissionStr.toString();
    if (perStr.endsWith(",")) {
        perStr = perStr.substring(0, perStr.length() - 1);
    }

    return perStr;
}

From source file:Main.java

public static String unquote(String s, String quote) {
    if (!TextUtils.isEmpty(s) && !TextUtils.isEmpty(quote)) {
        if (s.startsWith(quote) && s.endsWith(quote)) {
            return s.substring(1, s.length() - quote.length());
        }/*from   www .j  a  v a 2  s.  c o m*/
    }
    return s;
}

From source file:com.hortonworks.minicluster.util.StringAssertUtils.java

/**
 *
 * @param value/*  w ww .  ja v a2s  .c o  m*/
 * @param endsWith
 */
public static void assertNotEmptyAndNoSpacesAndEndsWith(String value, String endsWith) {
    assertNotEmptyAndNoSpaces(value);
    if (!value.endsWith(endsWith)) {
        throw new IllegalArgumentException("'value' must end with '" + endsWith + "'");
    }
}

From source file:controller.FTPServerController.java

public static List<String> findFilesXMLFTPServer(FTPClient ftpClient)
        throws UnsupportedEncodingException, IOException {

    List<String> listFileXML = new ArrayList<>();
    Map<String, String> mapXMLFiles = new HashMap<>();

    try {/*from  www  . j a va  2  s  .  c  om*/
        String[] allFiles = ftpClient.listNames();

        if (allFiles.length > 0) {
            System.out.println("Listing files '.xml':");

            for (String itemAllFilles : allFiles) {
                if (itemAllFilles.endsWith(".xml")) {
                    listFileXML.add(itemAllFilles);
                    System.out.println("    " + itemAllFilles);
                }
            }
        } else {
            System.out.println("No exists File .xml in this FTP Server!");
        }
    } catch (NullPointerException | SocketException e) {
        System.out.println(e.getMessage());
    }

    return listFileXML;
}

From source file:net.fabricmc.installer.util.MavenHandler.java

public static String getPath(String mavenServerURL, String packageName, String jarName, String version) {
    if (mavenServerURL.endsWith("/")) {
        mavenServerURL = mavenServerURL.substring(0, mavenServerURL.length() - 1);
    }//w  w  w .  j a  v a2 s  .c o m

    return mavenServerURL + "/" + packageName.replace('.', '/') + "/" + jarName + "/" + version + "/" + jarName
            + "-" + version + ".jar";
}

From source file:Main.java

/**
 * Find a download with the specified name.  Returns -1 if none was
 * found.//from   w  w w.  ja  va  2  s. c o m
 */
static long findPath(DownloadManager dm, String path) {
    DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterByStatus(
            DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING);
    Cursor c = dm.query(query);

    if (!c.moveToFirst())
        return -1;

    final int columnID = c.getColumnIndexOrThrow(DownloadManager.COLUMN_ID);
    final int columnLocalURI = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI);

    do {
        final String uri = c.getString(columnLocalURI);
        if (uri != null && uri.endsWith(path))
            return c.getLong(columnID);
    } while (c.moveToNext());

    return -1;
}

From source file:io.dataapps.chlorine.pattern.RegexFinder.java

static String removeCommas(String match) {
    if (match.endsWith(",")) {
        match = match.substring(0, match.length() - 1);
    }/*from w  w  w .  j  av  a 2s.  com*/
    if (match.startsWith(",")) {
        match = match.substring(1);
    }
    return match;
}

From source file:kyotocabinet.Loader.java

/**
 * Load the native library.//from w  w w  .j a v  a2  s  .c  o m
 */
static synchronized void load() {
    if (loaded) {
        return;
    }
    String lib = System.mapLibraryName("jkyotocabinet");
    if (lib.endsWith(".dll")) {
        // lib?lib
        URL url = Loader.class.getClassLoader().getResource(System.mapLibraryName("jkyotocabinet"));
        String libFileName = "./temp" + File.separatorChar + System.mapLibraryName("jkyotocabinet");
        File file = new File(libFileName);
        try {
            FileUtils.copyURLToFile(url, file);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        System.load(file.getAbsolutePath());
    } else {
        System.loadLibrary("jkyotocabinet");
    }
    loaded = true;
}