Example usage for java.lang String startsWith

List of usage examples for java.lang String startsWith

Introduction

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

Prototype

public boolean startsWith(String prefix) 

Source Link

Document

Tests if this string starts with the specified prefix.

Usage

From source file:Main.java

public static String getPlatformName(String hwRev) {
    String platformName;//from   w ww.j  a v  a 2  s .  c  o  m
    if (hwRev.startsWith("snowy")) {
        platformName = "basalt";
    } else if (hwRev.startsWith("spalding")) {
        platformName = "chalk";
    } else if (hwRev.startsWith("silk")) {
        platformName = "diorite";
    } else if (hwRev.startsWith("robert")) {
        platformName = "emery";
    } else {
        platformName = "aplite";
    }
    return platformName;
}

From source file:Main.java

public static String extractDomain(String url, boolean aggressive) {
    if (url.startsWith("http://"))
        url = url.substring("http://".length());
    else if (url.startsWith("https://"))
        url = url.substring("https://".length());

    if (aggressive) {
        if (url.startsWith("www."))
            url = url.substring("www.".length());

        // strip mobile from start
        if (url.startsWith("m."))
            url = url.substring("m.".length());
    }/*  ww  w .  j a  v  a  2  s  .  c  o  m*/

    int slashIndex = url.indexOf('/');
    if (slashIndex > 0)
        url = url.substring(0, slashIndex);

    return url;
}

From source file:Main.java

/**
 * Ensure a given path has a given prefix (e.g. file:///) - if it doesn't
 * then join the prefix to the string, otherwise return it as is
 * /*from www.  j av a  2s . c  o  m*/
 * @param 
 */
public static String ensurePathHasPrefix(String prefix, String path) {
    if (path.startsWith(prefix)) {
        return path;
    } else {
        return joinPaths(new String[] { prefix, path });
    }
}

From source file:org.lorislab.smonitor.util.RSClientUtil.java

public static void handleException(String guid, Exception ex) throws ServiceException {
    if (ex instanceof ClientResponseFailure) {
        ClientResponseFailure e = (ClientResponseFailure) ex;
        ClientResponse response = e.getResponse();
        if (response.getResponseStatus().equals(Response.Status.FORBIDDEN)) {
            throw new ServiceException(guid, "Authentification failed", e);
        }//ww w.  j a v a 2 s  .  co  m
        throw new ServiceException(guid,
                "Error in the communication to the server " + response.getResponseStatus().getStatusCode(), e);
    } else {
        String msg = ex.getMessage();
        if (msg.startsWith(ClientProtocolException.class.getName())) {
            throw new ServiceException(guid, "The server is not valid address.", ex);
        }
        throw new ServiceException(guid, "Could not connect to the server", ex);
    }
}

From source file:Main.java

public static boolean isMacOS() {

    String lcOSName = System.getProperty("os.name").toLowerCase();
    return lcOSName.startsWith("mac os x");
}

From source file:Main.java

public static boolean isVideo(String filename) {
    String mimeType = getMimeType(filename);
    if (mimeType != null && mimeType.startsWith("video/")) {
        return true;
    } else {//from ww  w  . j av  a 2 s .  c o m
        return false;
    }
}

From source file:Util.java

private static void fillGetterMethods(Class<?> pojoClass, Map<String, Method> baseMap) {
    if (pojoClass.getSuperclass() != Object.class)
        fillGetterMethods(pojoClass.getSuperclass(), baseMap);

    Method[] methods = pojoClass.getDeclaredMethods();
    for (int i = 0; i < methods.length; i++) {
        Method m = methods[i];// w ww  .java 2 s .  co  m
        if (!Modifier.isStatic(m.getModifiers()) && m.getParameterTypes().length == 0
                && m.getReturnType() != null && Modifier.isPublic(m.getModifiers())) {
            String name = m.getName();
            if (name.startsWith(IS))
                baseMap.put(toProperty(IS.length(), name), m);
            else if (name.startsWith(GET))
                baseMap.put(toProperty(GET.length(), name), m);
        }
    }
}

From source file:Main.java

static public String cleanValue(String value) {
    String cleanValue = value;/*from  w  w  w.  jav a  2  s.  c o  m*/
    if (value.startsWith("\"")) {
        cleanValue = value.substring(1);
    }
    if (value.endsWith("\"")) {
        cleanValue = cleanValue.substring(0, cleanValue.length() - 1);
    }
    if (cleanValue.startsWith("<![CDATA[") && cleanValue.endsWith("]]>")) {
        cleanValue = cleanValue.substring(9, cleanValue.length() - 3);
    }
    return cleanValue.trim();
}

From source file:Main.java

public static String getDtdAsString(String uri) throws IOException {
    Reader in = null;/* www .j a  va 2  s  .co  m*/
    if ((uri.startsWith("http")) || (uri.startsWith("ftp")) || (uri.startsWith("file:")))
        in = new InputStreamReader(new URL(uri).openStream());
    else {
        in = new FileReader(uri);
    }
    StringWriter out = new StringWriter();
    char[] buffer = new char[4096];
    for (int count = in.read(buffer); count != -1; count = in.read(buffer)) {
        out.write(buffer, 0, count);
    }
    return out.getBuffer().toString();
}

From source file:Main.java

public static String getCpuInfo() {
    try {/*  w  w  w  .jav a 2 s  .  c  o m*/
        String arc = System.getProperty("os.arch").toUpperCase();
        if (arc.startsWith("ARM")) {
            arc = "ARM";
        } else if (arc.startsWith("MIPS")) {
            arc = "MIPS";
        } else if (arc.startsWith("X86") || arc.endsWith("86")) {
            arc = "X86";
        } else {
            arc = "ARM";
        }
        return arc;
    } catch (Exception e) {
        return "ARM";
    }
}