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 Document stringToDocument(final String source) {
    String tmp = source.trim();
    if (!tmp.startsWith("<?xml")) {
        tmp = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + tmp;
    }//w ww. java2 s .c om
    String encode = "utf-8";
    Pattern p = Pattern.compile("<?.*encoding=\"([^ ]*)\".*?>");
    Matcher m = p.matcher(tmp);
    if (m.find()) {
        encode = m.group(1);
    }
    try {
        return DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new ByteArrayInputStream(tmp.getBytes(encode)));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

/** Returns the talker ID and sentence ID as a single String, ex: "GPGGA". */
public static String getType(String nmeaSentence) {
    if (nmeaSentence != null && !nmeaSentence.isEmpty() && nmeaSentence.startsWith("$")) {
        return nmeaSentence.substring(1, 6);
    } else {/*from ww w.  j  a  v a 2 s.  c om*/
        return "Unknown";
    }
}

From source file:com.cisco.cta.taxii.adapter.settings.PropertySourceHelper.java

public static MockPropertySource exclude(MockPropertySource all, String excludePrefix) {
    MockPropertySource source = new MockPropertySource();
    for (String key : all.getPropertyNames()) {
        if (!key.startsWith(excludePrefix)) {
            source.setProperty(key, all.getProperty(key));
        }//from   www  .j a  v a2 s  . c o m
    }
    return source;
}

From source file:com.taobao.itest.listener.ResourceLocationProcessingUtil.java

public static String[] modifyLocations(Class<?> clazz, String... locations) {
    String[] modifiedLocations = new String[locations.length];
    for (int i = 0; i < locations.length; i++) {
        String path = locations[i];
        if (path.startsWith("/")) {
            modifiedLocations[i] = ResourceUtils.CLASSPATH_URL_PREFIX + path;
        } else if (!ResourcePatternUtils.isUrl(path)) {
            modifiedLocations[i] = ResourceUtils.CLASSPATH_URL_PREFIX + "/"
                    + StringUtils.cleanPath(ClassUtils.classPackageAsResourcePath(clazz) + "/" + path);
        } else {//from  w  w w . jav  a  2s. c o  m
            modifiedLocations[i] = StringUtils.cleanPath(path);
        }
    }
    return modifiedLocations;
}

From source file:Main.java

private static boolean isStartWithIs(final String fieldName) {
    return fieldName != null && fieldName.startsWith("is");
}

From source file:net.sf.janos.util.EntryHelper.java

/**
 * Creates an Entry for the given url./*from   ww w  . j  a v a 2 s.c om*/
 * @param url the String representation of the url. format: [[scheme:]//]host[:port]/resource
 * @return An entry that refers to the given url resource
 */
public static final Entry createEntryForUrl(String url) {
    String res;
    if (url.startsWith("http:")) {
        // replace protocol part
        res = "x-rincon-mp3radio:" + url.substring(5);
    } else if (url.startsWith("//")) {
        res = "x-rincon-mp3radio:" + url;
    } else {
        res = "x-rincon-mp3radio://" + url;
    }
    LogFactory.getLog(EntryHelper.class).debug("Created Entry for url: " + url);
    return new Entry("URL:" + url, url, "URL:", "URL", "", "", "object.item.audioItem.audioBroadcast", res);

}

From source file:Main.java

public static boolean isUcos(String cid) {
    ////from   ww  w  .  java2s.c o  m
    if (!TextUtils.isEmpty(cid) && cid.length() == 12 && cid.startsWith("6001"))
        return false;

    return !TextUtils.isEmpty(cid) && cid.length() == 12
            && (cid.startsWith("20") || cid.startsWith("21") || cid.startsWith("60") || cid.startsWith("61"));
}

From source file:Main.java

public static String getModel(String hwRev) {
    //TODO: get real data?
    String model;//  w w w  .  j a v a2 s.co m
    if (hwRev.startsWith("snowy")) {
        model = "pebble_time_black";
    } else if (hwRev.startsWith("spalding")) {
        model = "pebble_time_round_black_20mm";
    } else {
        model = "pebble_black";
    }
    return model;
}

From source file:Main.java

/**
 * @param context/*from  w  ww. ja va  2 s .c om*/
 * @param filePath file path relative to assets, like request_init1/search_index.json
 * @return
 */
public static String readAssert(Context context, String filePath) {
    try {
        if (filePath.startsWith(File.separator)) {
            filePath = filePath.substring(File.separator.length());
        }
        AssetManager assetManager = context.getAssets();
        InputStream inputStream = assetManager.open(filePath);
        DataInputStream stream = new DataInputStream(inputStream);
        int length = stream.available();
        byte[] buffer = new byte[length];
        stream.readFully(buffer);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byteArrayOutputStream.write(buffer);
        stream.close();
        return byteArrayOutputStream.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.smallnn.input.FileUtil.java

public static File tildeExpand(String path) {
    if (path.startsWith("~")) {
        path = path.replaceFirst("~", getUserHome().getAbsolutePath());
    }//from   www . j  ava  2 s.co  m
    return new File(path);
}