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:org.obiba.mica.file.FileUtils.java

public static String normalizePath(String path) {
    String nPath = path.startsWith("/") ? path : String.format("/%s", path);

    if (!isRoot(nPath) && nPath.endsWith("/"))
        nPath = nPath.replaceAll("[/]+$", "");

    return nPath;
}

From source file:com.asakusafw.cleaner.log.LogMessageLoader.java

/**
 * ??/*from   w ww.  ja  v a2s  .com*/
 * ????????
 * <p>
 * ????.properties?????
 * ???????????
 * </p>
 * @param manager ?
 * @throws IOException ?????
 */
static void loadFile(LogMessageManager manager) throws IOException {
    // ?
    InputStream in = null;
    Properties props = new Properties();
    try {
        in = LogMessageLoader.class.getClassLoader().getResourceAsStream(Constants.LOG_MESSAGE_FILE);
        props.load(in);
        Enumeration<?> keys = props.propertyNames();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            if (key.endsWith(LEVEL_KEY_END)) {
                String messageId = LogMessageLoader.getMessageId(key, LEVEL_KEY_END);
                manager.putLevel(messageId, props.getProperty(key));
            } else if (key.endsWith(TEMPLATE_KEY_END)) {
                String messageId = LogMessageLoader.getMessageId(key, TEMPLATE_KEY_END);
                manager.putTemplate(messageId, props.getProperty(key));
            } else if (key.endsWith(SIZE_KEY_END)) {
                String messageId = LogMessageLoader.getMessageId(key, SIZE_KEY_END);
                String sizeStr = props.getProperty(key);
                if (NumberUtils.isNumber(sizeStr)) {
                    manager.putSize(messageId, Integer.valueOf(sizeStr));
                }
            }
        }
    } catch (IOException ex) {
        throw new IOException(
                "??????????"
                        + Constants.LOG_MESSAGE_FILE,
                ex);
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:com.fengduo.bee.commons.core.lang.ClassLoaderUtils.java

public static List<?> load(String classpath, ClassFilter filter) throws Exception {
    List<Object> objs = new ArrayList<Object>();
    URL resource = ClassLoaderUtils.class.getClassLoader().getResource(classpath);
    logger.debug("Search from {} ...", resource.getPath());
    List<String> classnameArray;
    if ("jar".equalsIgnoreCase(resource.getProtocol())) {
        String file = resource.getFile();
        String jarName = file.substring(file.indexOf("/"), (file.lastIndexOf("jar") + 3));
        classnameArray = getClassNamesInPackage(jarName, classpath);
    } else {/* w  w w. j a v  a 2s .c  o  m*/
        Collection<File> listFiles = FileUtils.listFiles(new File(resource.getPath()), null, false);
        String classNamePrefix = classpath.replaceAll("/", ".");
        classnameArray = new ArrayList<String>();
        for (File file : listFiles) {
            String name = file.getName();
            if (name.endsWith(".class") == false) {
                continue;
            }
            if (StringUtils.contains(name, '$')) {
                logger.warn("NOT SUPPORT INNERT CLASS" + file.getAbsolutePath());
                continue;
            }
            String classname = classNamePrefix + "." + StringUtils.remove(name, ".class");
            classnameArray.add(classname);
        }
    }

    for (String classname : classnameArray) {
        try {
            Class<?> loadClass = ClassLoaderUtils.class.getClassLoader().loadClass(classname);
            if (filter != null && !filter.filter(loadClass)) {
                logger.error("{}  {} ", classname, filter);
                continue;
            }
            // if (ClassLoaderUtil.class.isAssignableFrom(loadClass) == false) {
            // logger.error("{} ?????", classname);
            // continue;
            // }
            Object newInstance = loadClass.newInstance();
            objs.add(newInstance);
            logger.debug("load {}/{}.class success", resource.getPath(), classname);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("load " + resource.getPath() + "/" + classname + ".class failed", e);
        }
    }
    return objs;
}

From source file:Main.java

private static String unquote(String s) {
    if (s == null || s.length() == 0)
        return s;
    if (s.startsWith("\""))
        s = s.substring(1);/*from w ww  . j a v a2s.  co  m*/
    if (s.endsWith("\""))
        s = s.substring(0, s.length() - 1);
    return s;
}

From source file:com.pursuer.reader.easyrss.network.url.AbsURL.java

protected static String appendParams(final String str, final String param) {
    if (str.length() == 0 || str.endsWith("&")) {
        return str + param;
    } else {//ww w  . j a v  a2s  .  c o m
        return str + "&" + param;
    }
}

From source file:com.firewallid.util.FIFile.java

public static String generateFullPath(String folderfullpath, String name) {
    String fullPath;//from  w w w  .  j ava2 s .  com
    if (folderfullpath.endsWith(File.separator)) {
        fullPath = folderfullpath + name;
    } else {
        fullPath = folderfullpath + File.separator + name;
    }
    return fullPath;
}

From source file:fr.eo.util.dumper.JSONDumper.java

private static Object getFieldValue(RequestDefinitionBean request, int pos, ResultSet rs, String fieldName)
        throws SQLException {
    String str = String.valueOf(rs.getObject(fieldName)).trim();
    if (str.endsWith(".0")) {
        str = str.substring(0, str.length() - 2);
    }//from   ww w .j ava 2  s  . co m
    if (str.equals("null") || str.isEmpty()) {
        return null;
    }
    if (request.compressedStrPos.contains(pos)) {
        str = getCompressedString(str);
    } else if (request.numberPos.contains(pos)) {
        Number number = rs.getDouble(fieldName);
        if (number.longValue() == number.doubleValue()) {
            return number.longValue();
        }
        return number.doubleValue();
    } else if (request.fieldStrPos.contains(pos)) {
        str = formatString(str);
    }

    return str;
}

From source file:com.intuit.cto.selfservice.service.Util.java

/**
 * Extract files from a package on the classpath into a directory.
 * @param packagePath e.g. "com/stuff" (always forward slash not backslash, never dot)
 * @param toDir directory to extract to//from  w w w .  j  ava 2s.co  m
 * @return int the number of files copied
 * @throws java.io.IOException if something goes wrong, including if nothing was found on classpath
 */
public static int extractFromClasspathToFile(String packagePath, File toDir) throws IOException {
    String locationPattern = "classpath*:" + packagePath + "/**";
    ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
    Resource[] resources = resourcePatternResolver.getResources(locationPattern);
    if (resources.length == 0) {
        throw new IOException("Nothing found at " + locationPattern);
    }
    int counter = 0;
    for (Resource resource : resources) {
        if (resource.isReadable()) { // Skip hidden or system files
            URL url = resource.getURL();
            String path = url.toString();
            if (!path.endsWith("/")) { // Skip directories
                int p = path.lastIndexOf(packagePath) + packagePath.length();
                path = path.substring(p);
                File targetFile = new File(toDir, path);
                long len = resource.contentLength();
                if (!targetFile.exists() || targetFile.length() != len) { // Only copy new files
                    FileUtils.copyURLToFile(url, targetFile);
                    counter++;
                }
            }
        }
    }
    logger.info("Unpacked {} files from {} to {}", new Object[] { counter, locationPattern, toDir });
    return counter;
}

From source file:com.turkcell.curio.utils.CurioUtil.java

/**
 * Gets request type according to the request url.
 * //from  w  w w . j av  a 2  s .  c  om
 * @param url
 * @return
 */
public static int getRequestType(String url) {
    int type = -1;
    if (url.endsWith(Constants.SERVER_URL_SUFFIX_SESSION_START)) {
        type = 0;
    } else if (url.endsWith(Constants.SERVER_URL_SUFFIX_SESSION_END)) {
        type = 1;
    } else if (url.endsWith(Constants.SERVER_URL_SUFFIX_SCREEN_START)) {
        type = 2;
    } else if (url.endsWith(Constants.SERVER_URL_SUFFIX_SCREEN_END)) {
        type = 3;
    } else if (url.endsWith(Constants.SERVER_URL_SUFFIX_SEND_EVENT)) {
        type = 4;
    } else if (url.endsWith(Constants.SERVER_URL_SUFFIX_EVENT_END)) {
        type = 7;
    }

    return type;
}

From source file:eu.scape_project.hawarp.utils.StringUtils.java

/**
 * Creates a normalised directory string. Parts will be normalised to a
 * directory string which only has a trailing file path separator. The parts
 * are then concatenated to the final output string.
 *
 * @param dirs Directory strings//  w w w.  j av  a 2s. c om
 * @return
 */
public static String normdir(String... dirs) {
    String outDir = "";
    for (String dir : dirs) {
        String dirPart = (dir.startsWith(File.separator) ? dir.substring(1) : dir);
        outDir += ((dirPart.endsWith(File.separator)) ? dirPart : dirPart + File.separator);
    }
    return outDir;
}