Example usage for java.util List isEmpty

List of usage examples for java.util List isEmpty

Introduction

In this page you can find the example usage for java.util List isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:com.mtea.macrotea_httpclient_study.ClientFormLogin.java

public static void main(String[] args) throws Exception {

    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {/*w ww.ja v a2s  .  c  o m*/
        HttpGet httpget = new HttpGet("https://portal.sun.com/portal/dt");

        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();

        System.out.println("Login form get: " + response.getStatusLine());
        //??
        EntityUtils.consume(entity);

        System.out.println("?cookies:");
        List<Cookie> cookies = httpclient.getCookieStore().getCookies();
        if (cookies.isEmpty()) {
            System.out.println("None");
        } else {
            for (int i = 0; i < cookies.size(); i++) {
                System.out.println("- " + cookies.get(i).toString());
            }
        }

        HttpPost httpost = new HttpPost("https://portal.sun.com/amserver/UI/Login?"
                + "org=self_registered_users&" + "goto=/portal/dt&" + "gotoOnFail=/portal/dt?error=true");

        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("IDToken1", "username"));
        nvps.add(new BasicNameValuePair("IDToken2", "password"));

        //?
        httpost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));

        response = httpclient.execute(httpost);
        entity = response.getEntity();

        System.out.println("Login form get: " + response.getStatusLine());
        EntityUtils.consume(entity);

        System.out.println("Post logon cookies:");
        cookies = httpclient.getCookieStore().getCookies();
        if (cookies.isEmpty()) {
            System.out.println("None");
        } else {
            for (int i = 0; i < cookies.size(); i++) {
                System.out.println("- " + cookies.get(i).toString());
            }
        }

    } finally {
        //??httpclient???
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:de.oth.keycloak.TestRun.java

public static void main(String[] args) {
    try {/*from  w  w  w.  j  av  a  2 s.  c o  m*/
        String server = "http://localhost:8888/auth";
        String realm = "master";
        String user = "keycloak_admin";
        String pwd = "k6ycloakAdmin";
        String clientStr = "admin-cli";
        String secret = null;
        String initFileStr = "conf/test_init1.json";
        File initFile = new File(initFileStr);
        if (!initFile.isFile()) {
            URL url = TestRun.class.getClassLoader().getResource(initFileStr);
            if (url != null) {
                initFile = new File(url.getFile());
                if (!initFile.isFile()) {
                    log.error("init file does not exist: " + initFile);
                    System.exit(1);
                }
            } else {
                log.error("init file does not exist: " + initFile);
                System.exit(1);
            }
        }
        Keycloak keycloak = (secret == null) ? Keycloak.getInstance(server, realm, user, pwd, clientStr)
                : Keycloak.getInstance(server, realm, user, pwd, clientStr, secret);

        ObjectMapper mapper = new ObjectMapper();
        RealmsConfig realmsConfig = mapper.readValue(initFile, RealmsConfig.class);

        if (realmsConfig != null) {
            List<RealmConfig> realmList = realmsConfig.getRealms();
            if (realmList == null || realmList.isEmpty()) {
                log.error("no realms config found 1");
                return;
            }
            for (RealmConfig realmConf : realmList) {
                InitKeycloakServer.addRealm(keycloak, realmConf);
            }
        } else
            log.error("no realms config found 2");
    } catch (Exception e) {
        log.error(e.getClass().getName() + ": " + e.getMessage());
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:com.dlmu.heipacker.crawler.client.ClientFormLogin.java

public static void main(String[] args) throws Exception {

    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {//from   w  w w  . jav  a 2s  .c o m
        HttpGet httpget = new HttpGet("https://portal.sun.com/portal/dt");

        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();

        System.out.println("Login form get: " + response.getStatusLine());
        EntityUtils.consume(entity);

        System.out.println("Initial set of cookies:");
        List<Cookie> cookies = httpclient.getCookieStore().getCookies();
        if (cookies.isEmpty()) {
            System.out.println("None");
        } else {
            for (int i = 0; i < cookies.size(); i++) {
                System.out.println("- " + cookies.get(i).toString());
            }
        }

        HttpPost httpost = new HttpPost("https://portal.sun.com/amserver/UI/Login?"
                + "org=self_registered_users&" + "goto=/portal/dt&" + "gotoOnFail=/portal/dt?error=true");

        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("IDToken1", "username"));
        nvps.add(new BasicNameValuePair("IDToken2", "password"));

        httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));

        response = httpclient.execute(httpost);
        entity = response.getEntity();

        System.out.println("Login form get: " + response.getStatusLine());
        EntityUtils.consume(entity);

        System.out.println("Post logon cookies:");
        cookies = httpclient.getCookieStore().getCookies();
        if (cookies.isEmpty()) {
            System.out.println("None");
        } else {
            for (int i = 0; i < cookies.size(); i++) {
                System.out.println("- " + cookies.get(i).toString());
            }
        }

    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:jdbc.ClientFormLogin.java

public static void main(String[] args) throws Exception {
    BasicCookieStore cookieStore = new BasicCookieStore();
    CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
    java.net.CookieManager cm = new java.net.CookieManager();
    java.net.CookieHandler.setDefault(cm);

    try {/*ww w. j  ava  2s . c  om*/
        HttpGet httpget = new HttpGet("http://www.cophieu68.vn/export/excel.php?id=AAA");
        CloseableHttpResponse response1 = httpclient.execute(httpget);
        try {
            HttpEntity entity = response1.getEntity();

            System.out.println("Login form get: " + response1.getStatusLine());
            EntityUtils.consume(entity);

            System.out.println("Initial set of cookies:");
            List<Cookie> cookies = cookieStore.getCookies();
            if (cookies.isEmpty()) {
                System.out.println("None");
            } else {
                for (int i = 0; i < cookies.size(); i++) {
                    System.out.println("- " + cookies.get(i).toString());
                }
            }
        } finally {
            response1.close();
        }

        HttpUriRequest login = RequestBuilder.post()
                .setUri(new URI("http://www.cophieu68.vn/export/excel.php?id=AAA"))
                .addParameter("username", "hello_nguyenson@live.com").addParameter("tpassword", "19931994")
                .build();
        CloseableHttpResponse response2 = httpclient.execute(login);

        try {
            HttpEntity entity = response2.getEntity();

            System.out.println("Login form get: " + response2.getStatusLine());
            EntityUtils.consume(entity);

            System.out.println("Post logon cookies:");
            List<Cookie> cookies = cookieStore.getCookies();

            if (cookies.isEmpty()) {
                System.out.println("None");
            } else {
                for (int i = 0; i < cookies.size(); i++) {
                    System.out.println("- " + cookies.get(i).toString());
                }
            }

        } finally {
            response2.close();
        }
    } finally {
        httpclient.close();
    }
}

From source file:dk.dren.hunspell.HunspellMain.java

public static void main(String[] args) {
    try {/*from w  w w .  jav  a2s. c o  m*/
        if (args.length == 1 && args[0].equals("-libname")) {
            System.out.println(Hunspell.libName());

        } else {

            System.out.println("Loading Hunspell");

            File dir = new File("src/main/resources/dict");
            String dirPath = dir.getCanonicalPath() + "/pt_BR";

            Hunspell.Dictionary d = Hunspell.getInstance().getDictionary(dirPath);

            System.out.println("Hunspell library and dictionary loaded");

            String words[] = { "subnutido", "isso", "nao" };

            for (int i = 0; i < words.length; i++) {

                String word = words[i];
                if (d.misspelled(word)) {
                    List<String> suggestions = d.suggest(word);
                    print("misspelled: " + word);
                    if (suggestions.isEmpty()) {
                        print("\tNo suggestions.");
                    } else {
                        print("\tTry:");
                        for (String s : suggestions) {
                            print(" " + s);
                        }
                    }
                    println("");
                } else {
                    println("ok: " + word);
                }
            }
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}

From source file:io.fluo.webindex.data.Copy.java

public static void main(String[] args) throws Exception {

    if (args.length != 3) {
        log.error("Usage: Copy <pathsFile> <range> <dest>");
        System.exit(1);// w  ww.  j  a va  2s  .  co  m
    }
    final String hadoopConfDir = IndexEnv.getHadoopConfDir();
    final List<String> copyList = IndexEnv.getPathsRange(args[0], args[1]);
    if (copyList.isEmpty()) {
        log.error("No files to copy given {} {}", args[0], args[1]);
        System.exit(1);
    }

    DataConfig dataConfig = DataConfig.load();

    SparkConf sparkConf = new SparkConf().setAppName("webindex-copy");
    try (JavaSparkContext ctx = new JavaSparkContext(sparkConf)) {

        FileSystem hdfs = FileSystem.get(ctx.hadoopConfiguration());
        Path destPath = new Path(args[2]);
        if (!hdfs.exists(destPath)) {
            hdfs.mkdirs(destPath);
        }

        log.info("Copying {} files (Range {} of paths file {}) from AWS to HDFS {}", copyList.size(), args[1],
                args[0], destPath.toString());

        JavaRDD<String> copyRDD = ctx.parallelize(copyList, dataConfig.getNumExecutorInstances());

        final String prefix = DataConfig.CC_URL_PREFIX;
        final String destDir = destPath.toString();

        copyRDD.foreachPartition(iter -> {
            FileSystem fs = IndexEnv.getHDFS(hadoopConfDir);
            iter.forEachRemaining(ccPath -> {
                try {
                    Path dfsPath = new Path(destDir + "/" + getFilename(ccPath));
                    if (fs.exists(dfsPath)) {
                        log.error("File {} exists in HDFS and should have been previously filtered",
                                dfsPath.getName());
                    } else {
                        String urlToCopy = prefix + ccPath;
                        log.info("Starting copy of {} to {}", urlToCopy, destDir);
                        try (OutputStream out = fs.create(dfsPath);
                                BufferedInputStream in = new BufferedInputStream(
                                        new URL(urlToCopy).openStream())) {
                            IOUtils.copy(in, out);
                        }
                        log.info("Created {}", dfsPath.getName());
                    }
                } catch (IOException e) {
                    log.error("Exception while copying {}", ccPath, e);
                }
            });
        });
    }
}

From source file:com.iblsoft.iwxxm.webservice.Main.java

public static void main(String[] args) throws Exception {
    parseCommandLine(args);/*from  w  ww .  j a va2 s .  co  m*/
    if (commandLine.hasOption("s")) {
        runAsService();
    } else if (commandLine.hasOption("v")) {
        List<String> files = commandLine.getArgList();
        if (files.isEmpty()) {
            printHelp();
        } else {
            validateFiles(files);
        }
    } else {
        printHelp();
    }
}

From source file:com.doculibre.constellio.utils.license.ApplyLicenseUtils.java

/**
 * @param args//ww w.  j a v  a  2s .  co m
 */
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    URL licenceHeaderURL = ApplyLicenseUtils.class.getResource("LICENSE_HEADER");
    File binDir = ClasspathUtils.getClassesDir();
    File projectDir = binDir.getParentFile();
    //        File dryrunDir = new File(projectDir, "dryrun");
    File licenceFile = new File(licenceHeaderURL.toURI());
    List<String> licenceLines = readLines(licenceFile);
    //        for (int i = 0; i < licenceLines.size(); i++) {
    //            String licenceLine = licenceLines.get(i);
    //            licenceLines.set(i, " * " + licenceLine);
    //        }
    //        licenceLines.add(0, "/**");
    //        licenceLines.add(" */");

    List<File> javaFiles = (List<File>) org.apache.commons.io.FileUtils.listFiles(projectDir,
            new String[] { "java" }, true);
    for (File javaFile : javaFiles) {
        if (isValidPackage(javaFile)) {
            List<String> javaFileLines = readLines(javaFile);
            if (!javaFileLines.isEmpty()) {
                boolean modified = false;
                String firstLineTrim = javaFileLines.get(0).trim();
                if (firstLineTrim.startsWith("package")) {
                    modified = true;
                    javaFileLines.addAll(0, licenceLines);
                } else if (firstLineTrim.startsWith("/**")) {
                    int indexOfEndCommentLine = -1;
                    loop2: for (int i = 0; i < javaFileLines.size(); i++) {
                        String javaFileLine = javaFileLines.get(i);
                        if (javaFileLine.indexOf("*/") != -1) {
                            indexOfEndCommentLine = i;
                            break loop2;
                        }
                    }
                    if (indexOfEndCommentLine != -1) {
                        modified = true;
                        int i = 0;
                        loop3: for (Iterator<String> it = javaFileLines.iterator(); it.hasNext();) {
                            it.next();
                            if (i <= indexOfEndCommentLine) {
                                it.remove();
                            } else {
                                break loop3;
                            }
                            i++;
                        }
                        javaFileLines.addAll(0, licenceLines);
                    } else {
                        throw new RuntimeException(
                                "Missing end comment for file " + javaFile.getAbsolutePath());
                    }
                }

                if (modified) {
                    //                        String outputFilePath = javaFile.getPath().substring(projectDir.getPath().length());
                    //                        File outputFile = new File(dryrunDir, outputFilePath);
                    //                        outputFile.getParentFile().mkdirs();
                    //                        System.out.println(outputFile.getPath());
                    //                        FileOutputStream fos = new FileOutputStream(outputFile);
                    System.out.println(javaFile.getPath());
                    FileOutputStream fos = new FileOutputStream(javaFile);
                    IOUtils.writeLines(javaFileLines, "\n", fos);
                    IOUtils.closeQuietly(fos);
                }
            }
        }
    }
}

From source file:httpclient.client.ClientFormLogin.java

public static void main(String[] args) throws Exception {

    // prepare parameters
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setUserAgent(params, Constants.BROWSER_TYPE);
    HttpProtocolParams.setUseExpectContinue(params, true);
    DefaultHttpClient httpclient = new DefaultHttpClient(params);

    String loginURL = "http://10.1.1.251/login.asp";
    HttpGet httpget = new HttpGet(loginURL);
    HttpResponse response = httpclient.execute(httpget);
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        entity.consumeContent();/*from   www. j  a  v a  2  s  .  co  m*/
    }
    System.out.println("Initial set of cookies:");
    List<Cookie> cookies = httpclient.getCookieStore().getCookies();
    if (cookies.isEmpty()) {
        System.out.println("None");
    } else {
        for (int i = 0; i < cookies.size(); i++) {
            System.out.println("- " + cookies.get(i).toString());
        }
    }

    HttpPost httpost = new HttpPost(loginURL);
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("name", "fangdj"));
    nvps.add(new BasicNameValuePair("passwd", "1111"));

    httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

    response = httpclient.execute(httpost);
    entity = response.getEntity();
    for (Header h : response.getAllHeaders()) {
        System.out.println(h);
    }
    System.out.println("Login form get: " + response.getStatusLine());
    if (entity != null) {
        entity.consumeContent();
    }

    System.out.println("Post logon cookies:");
    cookies = httpclient.getCookieStore().getCookies();
    if (cookies.isEmpty()) {
        System.out.println("None");
    } else {
        for (int i = 0; i < cookies.size(); i++) {
            System.out.println("- " + cookies.get(i).toString());
        }
    }

    String mainURL = "http://10.1.1.251/ONWork/Record_save.asp";

    HttpPost mainHttPost = new HttpPost(mainURL);
    List<NameValuePair> mainNvps = new ArrayList<NameValuePair>();
    mainNvps.add(new BasicNameValuePair("EMP_NO", "13028"));
    mainNvps.add(new BasicNameValuePair("pwd", "1111"));
    mainNvps.add(new BasicNameValuePair("cmd2", "Apply"));

    httpost.setEntity(new UrlEncodedFormEntity(mainNvps, HTTP.UTF_8));

    response = httpclient.execute(mainHttPost);
    System.out.println(Tools.InputStreamToString(response.getEntity().getContent()));
    // When HttpClient instance is no longer needed, 
    // shut down the connection manager to ensure
    // immediate deallocation of all system resources
    httpclient.getConnectionManager().shutdown();
}

From source file:com.da.img.ClientFormLogin.java

public static void main(String[] args) throws Exception {

    DefaultHttpClient httpclient = new DefaultHttpClient();

    try {/*from  www  . j  a  v a 2s.  c o m*/
        HttpGet httpget = new HttpGet("http://www.soraven.info/index.php");

        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        //System.out.println( EntityUtils.toString(entity));
        System.out.println("Login form get: " + response.getStatusLine());
        EntityUtils.consume(entity);

        System.out.println("Initial set of cookies:");
        List<Cookie> cookies = httpclient.getCookieStore().getCookies();
        if (cookies.isEmpty()) {
            System.out.println("None");
        } else {
            for (int i = 0; i < cookies.size(); i++) {
                System.out.println("-1 " + cookies.get(i).toString());
            }
        }

        HttpPost httpost = new HttpPost("http://www.soraven.info/common/include/login.php");
        Header header1 = new BasicHeader("Accept",
                "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,application/msword, */*");
        Header header2 = new BasicHeader("Referer", "http://www.soraven.info/index.php");
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("p_userid", "bimohani"));
        nvps.add(new BasicNameValuePair("p_passwd", "cw8904"));
        nvps.add(new BasicNameValuePair("x", "12"));
        nvps.add(new BasicNameValuePair("y", "20"));
        httpost.setHeader(header1);
        httpost.setHeader(header2);
        httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));

        //Thread.sleep(2000);
        response = httpclient.execute(httpost);
        entity = response.getEntity();

        System.out.println("Login form get: " + response.getStatusLine());

        System.out.println(EntityUtils.toString(entity));
        EntityUtils.consume(entity);

        System.out.println("Post logon cookies:");
        cookies = httpclient.getCookieStore().getCookies();
        if (cookies.isEmpty()) {
            System.out.println("None");
        } else {
            for (int i = 0; i < cookies.size(); i++) {
                System.out.println("-2 " + cookies.get(i).toString());
            }
        }

    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
    }
}