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

static public boolean stringEndsWithArray(String string, String[] array) {
    boolean endsWith = false;

    for (String i : array) {
        endsWith = string.endsWith(i);
        if (endsWith)
            break;
    }/* w ww .  j a v  a 2s . c o  m*/

    return endsWith;

}

From source file:com.github.mjeanroy.junit.servers.samples.jetty.java.IndexWithRulesTest.java

private static EmbeddedJettyConfiguration initConfiguration() {
    try {//  ww w .  ja v a  2 s.  c om
        String current = new File(".").getCanonicalPath();
        if (!current.endsWith("/")) {
            current += "/";
        }

        String path = current.endsWith(PATH) ? current : current + PATH;

        return EmbeddedJettyConfiguration.builder().withWebapp(path + "src/main/webapp")
                .withClasspath(path + "target/classes").build();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.github.mjeanroy.junit.servers.samples.tomcat.java.IndexWithRulesTest.java

private static EmbeddedTomcatConfiguration initConfiguration() {
    try {// w  w w .  j  av  a2  s. c  om
        String current = new File(".").getCanonicalPath();
        if (!current.endsWith("/")) {
            current += "/";
        }

        String path = current.endsWith(PATH) ? current : current + PATH;

        return EmbeddedTomcatConfiguration.builder().withWebapp(path + "src/main/webapp")
                .withClasspath(path + "target/classes").build();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.github.mjeanroy.junit.servers.samples.tomcat.webxml.IndexWithRulesTest.java

private static EmbeddedTomcatConfiguration initConfiguration() {
    try {//from www .j  a v a  2 s  .c o m
        String current = new File(".").getCanonicalPath();
        if (!current.endsWith("/")) {
            current += "/";
        }

        String path = current.endsWith(PATH) ? current : current + PATH;

        return EmbeddedTomcatConfiguration.builder().withWebapp(path + "src/main/webapp")
                .withClasspath(path + "target/classes").disableNaming().build();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.addthis.hydra.store.compress.CompressedStream.java

public static @Nonnull InputStream decompressInputStream(@Nonnull InputStream in, @Nonnull String name)
        throws IOException {
    if (name.endsWith(CompressionType.GZIP.suffix)) {
        in = new GZIPInputStreamX(in, BUFFER_SIZE);
    } else if (name.endsWith(CompressionType.LZF.suffix)) {
        in = new LZFInputStream(in);
    } else if (name.endsWith(CompressionType.SNAPPY.suffix)) {
        in = new SnappyInputStream(in);
    } else if (name.endsWith(CompressionType.BZIP2.suffix)) {
        in = new BZip2CompressorInputStream(in, true);
    } else if (name.endsWith(CompressionType.LZMA.suffix)) {
        in = new LZMAInputStream(in);
    } else if (name.endsWith(CompressionType.XZ.suffix)) {
        in = new XZInputStream(in);
    }/*  w  w  w  . j ava  2s  .  co m*/
    return in;
}

From source file:edu.umd.cs.guitar.testcase.plugin.edg.ClassDB.java

/**
 * Generates a database containing class information about given application classes
 * @param appClasses The classes of an application as directories to class-files or as path to jar-files
 * @return Database containing class information
 *//*  w w  w .j  a v a 2s  .c o m*/
public static Map<String, Class> create(String[] appClasses) {
    ClassDBVisitor cv = new ClassDBVisitor();
    for (String s : appClasses) {
        File f = new File(s);
        if (f.isDirectory()) {
            Collection<File> files = FileUtils.listFiles(f, new String[] { "class" }, true);
            for (File cf : files) {
                try {
                    ClassReader cr = new ClassReader(new FileInputStream(cf));
                    cr.accept(cv, 0);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        } else if (f.isFile() && s.toLowerCase().endsWith(".jar")) {
            try {
                ZipFile zf = new ZipFile(f);
                Enumeration<? extends ZipEntry> en = zf.entries();
                while (en.hasMoreElements()) {
                    ZipEntry e = en.nextElement();
                    String name = e.getName();
                    if (name.endsWith(".class")) {
                        new ClassReader(zf.getInputStream(e)).accept(cv, 0);
                    }
                }
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    }
    return cv.getClassDb();
}

From source file:eu.sisob.uma.restserver.FileSystemManager.java

/**
 *
 * @param code_task_folder_dir/*w  ww  .  j  a  v a 2  s . co  m*/
 * @param filename_prefix
 * @param filename_ext
 * @return
 */
public static File getFileIfExists(File code_task_folder_dir, final String filename_prefix,
        final String filename_ext) {

    List<File> list = null;
    if (code_task_folder_dir.exists()) {

        list = Arrays.asList(code_task_folder_dir.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return name.startsWith(filename_prefix) && name.endsWith(filename_ext);
            }
        }));
    }

    return (list != null && list.size() == 1 ? list.get(0) : null);

}

From source file:Main.java

/**
 * Returns SSID of Wifi hotspot device connected with.
 * @param context//from www.ja v  a  2  s  .  co  m
 * @return
 */
public static String getCurrentWifiConnectionSSID(Context context) {
    final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    final WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (wifiInfo == null)
        return null;

    String ssid = wifiInfo.getSSID();
    if (android.os.Build.VERSION.SDK_INT >= 16) {
        if (ssid.startsWith("\"") && ssid.endsWith("\"")) {
            ssid = ssid.substring(1, ssid.length() - 1);
        }
    }
    return ssid;
}

From source file:Main.java

/**
 * Returns the path only (without file name).
 * @param file/* ww w.  j a v  a2s  .  c  o m*/
 * @return
 */
public static File getPathWithoutFilename(File file) {
    if (file != null) {
        if (file.isDirectory()) {
            // no file to be split off. Return everything
            return file;
        } else {
            String filename = file.getName();
            String filepath = file.getAbsolutePath();

            // Construct path without file name.
            String pathwithoutname = filepath.substring(0, filepath.length() - filename.length());
            if (pathwithoutname.endsWith("/")) {
                pathwithoutname = pathwithoutname.substring(0, pathwithoutname.length() - 1);
            }
            return new File(pathwithoutname);
        }
    }
    return null;
}

From source file:kr.ac.kaist.wala.hybridroid.analysis.resource.AndroidDecompiler.java

public static String decompile(String apk) {
    if (!apk.endsWith(".apk"))
        throw new InternalError("only support apk file : " + apk);
    File apkFile = new File(apk);
    if (!apkFile.exists())
        throw new InternalError("the file does not exist : " + apk);

    try {//w w w  . j  a  v  a 2  s  .  c om
        String path = apkFile.getCanonicalPath();
        String toPath = path.substring(0, path.length() - 4);
        String[] cmds = { "-f", "d", path, "-o", toPath };
        //         String apktool = Shell.walaProperties.getProperty(WalaProperties.ANDROID_APK_TOOL);
        //         File f = new File(apktool);
        //         if(!f.exists() || !f.isFile()){
        //            throw new InternalError("Cannot find APK tool: " + apktool);
        //         }
        //         String[] cmd = {"java", "-jar", apktool, "-f", "d", path, "-o", toPath};
        //         ProcessBuilder pb = new ProcessBuilder();
        //         pb.command(cmd);
        ////         System.out.println(pb.command().toString());
        //         Process p = pb.start();
        //         BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        //         BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        //         
        //         String r = null;
        //         while((r = br.readLine()) != null){
        //            System.out.println(r);
        //         }
        //         
        //         while((r = bre.readLine()) != null){
        //            System.err.println(r);
        //         }
        //         
        //         int res = p.waitFor();
        //         if(res != 0){
        //            throw new InternalError("failed to decompile: " + path);
        //         }
        brut.apktool.Main.main(cmds);
        if (!SystemUtils.IS_OS_WINDOWS)
            permission(toPath);
        return toPath;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}