Example usage for java.util List get

List of usage examples for java.util List get

Introduction

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

Prototype

E get(int index);

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:co.mitro.core.util.RPCLogReplayer.java

public static void main(String[] args) throws IOException, InterruptedException, KeyManagementException,
        UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException {

    List<Request> requests = new ArrayList<>();
    ExecutorService executor = Executors.newFixedThreadPool(5);
    for (int i = 0; i < args.length; ++i) {
        String filename = args[i];
        System.err.println("Reading file: " + filename);
        JsonRecordReader rr = JsonRecordReader.MakeFromFilename(filename);
        JsonRecordReader.JsonLog log;/*from  www  . ja v  a2 s . c o  m*/
        try {
            while (null != (log = rr.readJson())) {
                if (Strings.isNullOrEmpty(log.payload.transactionId) && !log.payload.implicitBeginTransaction) {
                    // read only transaction
                    requests.add(new Request(log.metadata.endpoint, log.payload));
                }
            }
        } catch (EOFException e) {
            System.err.println("unexpected end of file; skipping");
        }
    }

    // run the simulation for a while.
    long scaling = 1000;
    double requestsPerMs = 353. / 9805199;
    long START_MS = 0;
    // run for 20 min
    long END_MS = 20 * 60 * 1000;
    long now = START_MS;
    int count = 0;
    while (now < END_MS) {
        double toSleep = nextExp(requestsPerMs * scaling);
        now += toSleep;
        ++count;
        Thread.sleep((long) toSleep);
        executor.execute(new SendQuery(requests.get(RNG.nextInt(requests.size()))));
        System.out.println("count: " + count + "\t time:" + now + "\t rate:" + (double) count / now);
    }
    executor.awaitTermination(1, TimeUnit.MINUTES);

}

From source file:com.stratio.decision.executables.DataFlowFromCsvMain.java

public static void main(String[] args) throws IOException, NumberFormatException, InterruptedException {
    if (args.length < 4) {
        log.info(//from w ww.ja va 2  s.c o m
                "Usage: \n param 1 - path to file \n param 2 - stream name to send the data \n param 3 - time in ms to wait to send each data \n param 4 - broker list");
    } else {
        Producer<String, String> producer = new Producer<String, String>(createProducerConfig(args[3]));
        Gson gson = new Gson();

        Reader in = new FileReader(args[0]);
        CSVParser parser = CSVFormat.DEFAULT.parse(in);

        List<String> columnNames = new ArrayList<>();
        for (CSVRecord csvRecord : parser.getRecords()) {

            if (columnNames.size() == 0) {
                Iterator<String> iterator = csvRecord.iterator();
                while (iterator.hasNext()) {
                    columnNames.add(iterator.next());
                }
            } else {
                StratioStreamingMessage message = new StratioStreamingMessage();

                message.setOperation(STREAM_OPERATIONS.MANIPULATION.INSERT.toLowerCase());
                message.setStreamName(args[1]);
                message.setTimestamp(System.currentTimeMillis());
                message.setSession_id(String.valueOf(System.currentTimeMillis()));
                message.setRequest_id(String.valueOf(System.currentTimeMillis()));
                message.setRequest("dummy request");

                List<ColumnNameTypeValue> sensorData = new ArrayList<>();
                for (int i = 0; i < columnNames.size(); i++) {

                    // Workaround
                    Object value = null;
                    try {
                        value = Double.valueOf(csvRecord.get(i));
                    } catch (NumberFormatException e) {
                        value = csvRecord.get(i);
                    }
                    sensorData.add(new ColumnNameTypeValue(columnNames.get(i), null, value));
                }

                message.setColumns(sensorData);

                String json = gson.toJson(message);
                log.info("Sending data: {}", json);
                producer.send(new KeyedMessage<String, String>(InternalTopic.TOPIC_DATA.getTopicName(),
                        STREAM_OPERATIONS.MANIPULATION.INSERT, json));

                log.info("Sleeping {} ms...", args[2]);
                Thread.sleep(Long.valueOf(args[2]));
            }
        }
        log.info("Program completed.");
    }
}

From source file:net.kolola.msgparsercli.MsgParseCLI.java

public static void main(String[] args) {

    // Parse options

    OptionParser parser = new OptionParser("f:a:bi?*");
    OptionSet options = parser.parse(args);

    // Get the filename
    if (!options.has("f")) {
        System.err.print("Specify a msg file with the -f option");
        System.exit(0);/*www.j a v a  2s  .co m*/
    }

    File file = new File((String) options.valueOf("f"));

    MsgParser msgp = new MsgParser();
    Message msg = null;

    try {
        msg = msgp.parseMsg(file);
    } catch (UnsupportedOperationException | IOException e) {
        System.err.print("File does not exist or is not a valid msg file");
        //e.printStackTrace();
        System.exit(1);
    }

    // Show info (as JSON)
    if (options.has("i")) {
        Map<String, Object> data = new HashMap<String, Object>();

        String date;

        try {
            Date st = msg.getClientSubmitTime();
            date = st.toString();
        } catch (Exception g) {
            try {
                date = msg.getDate().toString();
            } catch (Exception e) {
                date = "[UNAVAILABLE]";
            }
        }

        data.put("date", date);
        data.put("subject", msg.getSubject());
        data.put("from", "\"" + msg.getFromName() + "\" <" + msg.getFromEmail() + ">");
        data.put("to", "\"" + msg.getToRecipient().toString());

        String cc = "";
        for (RecipientEntry r : msg.getCcRecipients()) {
            if (cc.length() > 0)
                cc.concat("; ");

            cc.concat(r.toString());
        }

        data.put("cc", cc);

        data.put("body_html", msg.getBodyHTML());
        data.put("body_rtf", msg.getBodyRTF());
        data.put("body_text", msg.getBodyText());

        // Attachments
        List<Map<String, String>> atts = new ArrayList<Map<String, String>>();
        for (Attachment a : msg.getAttachments()) {
            HashMap<String, String> info = new HashMap<String, String>();

            if (a instanceof FileAttachment) {
                FileAttachment fa = (FileAttachment) a;

                info.put("type", "file");
                info.put("filename", fa.getFilename());
                info.put("size", Long.toString(fa.getSize()));
            } else {
                info.put("type", "message");
            }

            atts.add(info);
        }

        data.put("attachments", atts);

        JSONObject json = new JSONObject(data);

        try {
            System.out.print(json.toString(4));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    // OR return an attachment in BASE64
    else if (options.has("a")) {
        Integer anum = Integer.parseInt((String) options.valueOf("a"));

        Encoder b64 = Base64.getEncoder();

        List<Attachment> atts = msg.getAttachments();

        if (atts.size() <= anum) {
            System.out.print("Attachment " + anum.toString() + " does not exist");
        }

        Attachment att = atts.get(anum);

        if (att instanceof FileAttachment) {
            FileAttachment fatt = (FileAttachment) att;
            System.out.print(b64.encodeToString(fatt.getData()));
        } else {
            System.err.print("Attachment " + anum.toString() + " is a message - That's not implemented yet :(");
        }
    }
    // OR print the message body
    else if (options.has("b")) {
        System.out.print(msg.getConvertedBodyHTML());
    } else {
        System.err.print(
                "Specify either -i to return msg information or -a <num> to print an attachment as a BASE64 string");
    }

}

From source file:org.switchyard.quickstarts.rules.multi.RulesMultithreadBindingClient.java

/**
 * The main method.//from   w w  w.j av  a  2  s .  c  o m
 *
 * @param args the arguments
 * @throws Exception the exception
 */
public static void main(String[] args) throws Exception {

    List<List<Item>> items = new ArrayList<List<Item>>();

    List<Item> items0 = new ArrayList<Item>();
    items0.add(new Item(1, "DELLXX", 400));
    items0.add(new Item(2, "LENOVO%20XX", 700));
    items0.add(new Item(3, "SAMSUNG%20XX", 750));
    items0.add(new Item(4, "DELLXX", 400));

    List<Item> items1 = new ArrayList<Item>();
    items1.add(new Item(16, "LENOVO%20YY", 1700));
    items1.add(new Item(17, "SAMSUNG%20YY", 1750));
    items1.add(new Item(18, "DELL%20YY", 1400));

    List<Item> items2 = new ArrayList<Item>();
    items2.add(new Item(6, "LENOVO%20ZZ", 380));
    items2.add(new Item(7, "SAMSUNG%20ZZ", 730));
    items2.add(new Item(8, "DELL%20ZZ", 450));

    List<Item> items3 = new ArrayList<Item>();
    items3.add(new Item(9, "LENOVO%20XY", 50));
    items3.add(new Item(10, "SAMSUNG%20XY", 950));
    items3.add(new Item(11, "DELL%20XY", 400));

    List<Item> items4 = new ArrayList<Item>();
    items4.add(new Item(12, "LENOVO%20ZY", 200));
    items4.add(new Item(13, "SAMSUNG%20ZY", 175));
    items4.add(new Item(14, "DELL%20ZY", 100));

    items.add(items0);
    items.add(items1);
    items.add(items2);
    items.add(items3);
    items.add(items4);

    for (int i = 0; i < THREADS; i++) {
        (new Thread(new RulesMultithreadBindingClient(items.get(i), i))).start();
    }
}

From source file:com.roncoo.pay.app.reconciliation.ReconciliationTask.java

public static void main(String[] args) {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

    try {//from  ww  w. j a va 2 s .c o m
        // Spring?
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                new String[] { "spring-context.xml" });
        // ?SpringContextUtil
        final SpringContextUtil ctxUtil = new SpringContextUtil();
        ctxUtil.setApplicationContext(context);

        @SuppressWarnings("rawtypes")
        // ??(???????)
        List reconciliationInterList = ReconciliationInterface.getInterface();

        // ?biz
        ReconciliationFileDownBiz fileDownBiz = (ReconciliationFileDownBiz) SpringContextUtil
                .getBean("reconciliationFileDownBiz");
        ReconciliationFileParserBiz parserBiz = (ReconciliationFileParserBiz) SpringContextUtil
                .getBean("reconciliationFileParserBiz");
        ReconciliationCheckBiz checkBiz = (ReconciliationCheckBiz) SpringContextUtil
                .getBean("reconciliationCheckBiz");
        ReconciliationValidateBiz validateBiz = (ReconciliationValidateBiz) SpringContextUtil
                .getBean("reconciliationValidateBiz");
        RpAccountCheckBatchService batchService = (RpAccountCheckBatchService) SpringContextUtil
                .getBean("rpAccountCheckBatchService");
        BuildNoService buildNoService = (BuildNoService) SpringContextUtil.getBean("buildNoService");

        // ?????
        for (int num = 0; num < reconciliationInterList.size(); num++) {
            // ??
            ReconciliationInterface reconciliationInter = (ReconciliationInterface) reconciliationInterList
                    .get(num);
            if (reconciliationInter == null) {
                LOG.info("??" + reconciliationInter + "");
                continue;
            }
            // ???
            Date billDate = DateUtil.addDay(new Date(), -reconciliationInter.getBillDay());
            // ??
            String interfaceCode = reconciliationInter.getInterfaceCode();

            /** step1:? **/
            RpAccountCheckBatch batch = new RpAccountCheckBatch();
            Boolean checked = validateBiz.isChecked(interfaceCode, billDate);
            if (checked) {
                LOG.info("?[" + sdf.format(billDate) + "],?[" + interfaceCode
                        + "],????");
                continue;
            }
            // 
            batch.setCreater("reconciliationSystem");
            batch.setCreateTime(new Date());
            batch.setBillDate(billDate);
            batch.setBatchNo(buildNoService.buildReconciliationNo());
            batch.setBankType(interfaceCode);

            /** step2: **/
            File file = null;
            try {
                LOG.info("ReconciliationFileDownBiz,");
                file = fileDownBiz.downReconciliationFile(interfaceCode, billDate);
                if (file == null) {
                    continue;
                }
                LOG.info("?");
            } catch (Exception e) {
                LOG.error(":", e);
                batch.setStatus(BatchStatusEnum.FAIL.name());
                batch.setRemark("");
                batchService.saveData(batch);
                continue;
            }

            /** step3:? **/
            List<ReconciliationEntityVo> bankList = null;
            try {
                LOG.info("=ReconciliationFileParserBiz=>?>>>");

                // ?
                bankList = parserBiz.parser(batch, file, billDate, interfaceCode);
                // 
                if (BatchStatusEnum.ERROR.name().equals(batch.getStatus())) {
                    continue;
                }
                LOG.info("??");
            } catch (Exception e) {
                LOG.error("?:", e);
                batch.setStatus(BatchStatusEnum.FAIL.name());
                batch.setRemark("?");
                batchService.saveData(batch);
                continue;
            }

            /** step4:? **/
            try {
                checkBiz.check(bankList, interfaceCode, batch);
            } catch (Exception e) {
                LOG.error(":", e);
                batch.setStatus(BatchStatusEnum.FAIL.name());
                batch.setRemark("");
                batchService.saveData(batch);
                continue;
            }

        }

        /** step5:? **/
        // ???
        validateBiz.validateScratchPool();
    } catch (Exception e) {
        LOG.error("roncoo-app-reconciliation error:", e);
    }

}

From source file:mod.org.dcm4che2.tool.DcmSnd.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    CommandLine cl = parse(args);/*from  ww  w .  ja  v a  2  s.c  o  m*/
    DcmSnd dcmsnd = new DcmSnd(cl.hasOption("device") ? cl.getOptionValue("device") : "DCMSND");
    final List<String> argList = cl.getArgList();
    String remoteAE = argList.get(0);
    String[] calledAETAddress = split(remoteAE, '@');
    dcmsnd.setCalledAET(calledAETAddress[0]);
    if (calledAETAddress[1] == null) {
        dcmsnd.setRemoteHost("127.0.0.1");
        dcmsnd.setRemotePort(104);
    } else {
        String[] hostPort = split(calledAETAddress[1], ':');
        dcmsnd.setRemoteHost(hostPort[0]);
        dcmsnd.setRemotePort(toPort(hostPort[1]));
    }
    if (cl.hasOption("L")) {
        String localAE = cl.getOptionValue("L");
        String[] localPort = split(localAE, ':');
        if (localPort[1] != null) {
            dcmsnd.setLocalPort(toPort(localPort[1]));
        }
        String[] callingAETHost = split(localPort[0], '@');
        dcmsnd.setCalling(callingAETHost[0]);
        if (callingAETHost[1] != null) {
            dcmsnd.setLocalHost(callingAETHost[1]);
        }
    }
    dcmsnd.setOfferDefaultTransferSyntaxInSeparatePresentationContext(cl.hasOption("ts1"));
    dcmsnd.setSendFileRef(cl.hasOption("fileref"));
    if (cl.hasOption("username")) {
        String username = cl.getOptionValue("username");
        UserIdentity userId;
        if (cl.hasOption("passcode")) {
            String passcode = cl.getOptionValue("passcode");
            userId = new UserIdentity.UsernamePasscode(username, passcode.toCharArray());
        } else {
            userId = new UserIdentity.Username(username);
        }
        userId.setPositiveResponseRequested(cl.hasOption("uidnegrsp"));
        dcmsnd.setUserIdentity(userId);
    }
    dcmsnd.setStorageCommitment(cl.hasOption("stgcmt"));
    String remoteStgCmtAE = null;
    if (cl.hasOption("stgcmtae")) {
        try {
            remoteStgCmtAE = cl.getOptionValue("stgcmtae");
            String[] aet_hostport = split(remoteStgCmtAE, '@');
            String[] host_port = split(aet_hostport[1], ':');
            dcmsnd.setStgcmtCalledAET(aet_hostport[0]);
            dcmsnd.setRemoteStgcmtHost(host_port[0]);
            dcmsnd.setRemoteStgcmtPort(toPort(host_port[1]));
        } catch (Exception e) {
            exit("illegal argument of option -stgcmtae");
        }
    }
    if (cl.hasOption("set")) {
        String[] vals = cl.getOptionValues("set");
        for (int i = 0; i < vals.length; i++, i++) {
            dcmsnd.addCoerceAttr(Tag.toTag(vals[i]), vals[i + 1]);
        }
    }
    if (cl.hasOption("setuid")) {
        dcmsnd.setSuffixUID(cl.getOptionValues("setuid"));
    }
    if (cl.hasOption("connectTO"))
        dcmsnd.setConnectTimeout(parseInt(cl.getOptionValue("connectTO"),
                "illegal argument of option -connectTO", 1, Integer.MAX_VALUE));
    if (cl.hasOption("reaper"))
        dcmsnd.setAssociationReaperPeriod(parseInt(cl.getOptionValue("reaper"),
                "illegal argument of option -reaper", 1, Integer.MAX_VALUE));
    if (cl.hasOption("rspTO"))
        dcmsnd.setDimseRspTimeout(parseInt(cl.getOptionValue("rspTO"), "illegal argument of option -rspTO", 1,
                Integer.MAX_VALUE));
    if (cl.hasOption("acceptTO"))
        dcmsnd.setAcceptTimeout(parseInt(cl.getOptionValue("acceptTO"), "illegal argument of option -acceptTO",
                1, Integer.MAX_VALUE));
    if (cl.hasOption("releaseTO"))
        dcmsnd.setReleaseTimeout(parseInt(cl.getOptionValue("releaseTO"),
                "illegal argument of option -releaseTO", 1, Integer.MAX_VALUE));
    if (cl.hasOption("soclosedelay"))
        dcmsnd.setSocketCloseDelay(parseInt(cl.getOptionValue("soclosedelay"),
                "illegal argument of option -soclosedelay", 1, 10000));
    if (cl.hasOption("shutdowndelay"))
        dcmsnd.setShutdownDelay(parseInt(cl.getOptionValue("shutdowndelay"),
                "illegal argument of option -shutdowndelay", 1, 10000));
    if (cl.hasOption("anonymize"))
        dcmsnd.setAnonymize(Long.parseLong(cl.getOptionValue("anonymize")));
    if (cl.hasOption("rcvpdulen"))
        dcmsnd.setMaxPDULengthReceive(
                parseInt(cl.getOptionValue("rcvpdulen"), "illegal argument of option -rcvpdulen", 1, 10000)
                        * KB);
    if (cl.hasOption("sndpdulen"))
        dcmsnd.setMaxPDULengthSend(
                parseInt(cl.getOptionValue("sndpdulen"), "illegal argument of option -sndpdulen", 1, 10000)
                        * KB);
    if (cl.hasOption("sosndbuf"))
        dcmsnd.setSendBufferSize(
                parseInt(cl.getOptionValue("sosndbuf"), "illegal argument of option -sosndbuf", 1, 10000) * KB);
    if (cl.hasOption("sorcvbuf"))
        dcmsnd.setReceiveBufferSize(
                parseInt(cl.getOptionValue("sorcvbuf"), "illegal argument of option -sorcvbuf", 1, 10000) * KB);
    if (cl.hasOption("bufsize"))
        dcmsnd.setTranscoderBufferSize(
                parseInt(cl.getOptionValue("bufsize"), "illegal argument of option -bufsize", 1, 10000) * KB);
    if (cl.hasOption("batchsize"))
        dcmsnd.setBatchSize(Integer.parseInt(cl.getOptionValue("batchsize")));
    dcmsnd.setPackPDV(!cl.hasOption("pdv1"));
    dcmsnd.setTcpNoDelay(!cl.hasOption("tcpdelay"));
    if (cl.hasOption("async"))
        dcmsnd.setMaxOpsInvoked(
                parseInt(cl.getOptionValue("async"), "illegal argument of option -async", 0, 0xffff));
    if (cl.hasOption("lowprior"))
        dcmsnd.setPriority(CommandUtils.LOW);
    if (cl.hasOption("highprior"))
        dcmsnd.setPriority(CommandUtils.HIGH);
    System.out.println("Scanning files to send");
    long t1 = System.currentTimeMillis();
    for (int i = 1, n = argList.size(); i < n; ++i)
        dcmsnd.addFile(new File(argList.get(i)));
    long t2 = System.currentTimeMillis();
    if (dcmsnd.getNumberOfFilesToSend() == 0) {
        System.exit(2);
    }
    System.out.println("\nScanned " + dcmsnd.getNumberOfFilesToSend() + " files in " + ((t2 - t1) / 1000F)
            + "s (=" + ((t2 - t1) / dcmsnd.getNumberOfFilesToSend()) + "ms/file)");
    dcmsnd.configureTransferCapability();
    if (cl.hasOption("tls")) {
        String cipher = cl.getOptionValue("tls");
        if ("NULL".equalsIgnoreCase(cipher)) {
            dcmsnd.setTlsWithoutEncyrption();
        } else if ("3DES".equalsIgnoreCase(cipher)) {
            dcmsnd.setTls3DES_EDE_CBC();
        } else if ("AES".equalsIgnoreCase(cipher)) {
            dcmsnd.setTlsAES_128_CBC();
        } else {
            exit("Invalid parameter for option -tls: " + cipher);
        }

        if (cl.hasOption("tls1")) {
            dcmsnd.setTlsProtocol(TLS1);
        } else if (cl.hasOption("ssl3")) {
            dcmsnd.setTlsProtocol(SSL3);
        } else if (cl.hasOption("no_tls1")) {
            dcmsnd.setTlsProtocol(NO_TLS1);
        } else if (cl.hasOption("no_ssl3")) {
            dcmsnd.setTlsProtocol(NO_SSL3);
        } else if (cl.hasOption("no_ssl2")) {
            dcmsnd.setTlsProtocol(NO_SSL2);
        }
        dcmsnd.setTlsNeedClientAuth(!cl.hasOption("noclientauth"));

        if (cl.hasOption("keystore")) {
            dcmsnd.setKeyStoreURL(cl.getOptionValue("keystore"));
        }
        if (cl.hasOption("keystorepw")) {
            dcmsnd.setKeyStorePassword(cl.getOptionValue("keystorepw"));
        }
        if (cl.hasOption("keypw")) {
            dcmsnd.setKeyPassword(cl.getOptionValue("keypw"));
        }
        if (cl.hasOption("truststore")) {
            dcmsnd.setTrustStoreURL(cl.getOptionValue("truststore"));
        }
        if (cl.hasOption("truststorepw")) {
            dcmsnd.setTrustStorePassword(cl.getOptionValue("truststorepw"));
        }
        try {
            dcmsnd.initTLS();
        } catch (Exception e) {
            System.err.println("ERROR: Failed to initialize TLS context:" + e.getMessage());
            System.exit(2);
        }
    }
    while (dcmsnd.getLastSentFile() < dcmsnd.getNumberOfFilesToSend()) {
        try {
            dcmsnd.start();
        } catch (Exception e) {
            System.err.println("ERROR: Failed to start server for receiving " + "Storage Commitment results:"
                    + e.getMessage());
            System.exit(2);
        }
        try {
            t1 = System.currentTimeMillis();
            try {
                dcmsnd.open();
            } catch (Exception e) {
                System.err.println("ERROR: Failed to establish association:" + e.getMessage());
                System.exit(2);
            }
            t2 = System.currentTimeMillis();
            System.out.println("Connected to " + remoteAE + " in " + ((t2 - t1) / 1000F) + "s");

            t1 = System.currentTimeMillis();
            dcmsnd.send();
            t2 = System.currentTimeMillis();
            prompt(dcmsnd, (t2 - t1) / 1000F);
            if (dcmsnd.isStorageCommitment()) {
                t1 = System.currentTimeMillis();
                if (dcmsnd.commit()) {
                    t2 = System.currentTimeMillis();
                    System.out.println(
                            "Request Storage Commitment from " + remoteAE + " in " + ((t2 - t1) / 1000F) + "s");
                    System.out.println("Waiting for Storage Commitment Result..");
                    try {
                        DicomObject cmtrslt = dcmsnd.waitForStgCmtResult();
                        t1 = System.currentTimeMillis();
                        promptStgCmt(cmtrslt, ((t1 - t2) / 1000F));
                    } catch (InterruptedException e) {
                        System.err.println("ERROR:" + e.getMessage());
                    }
                }
            }
            dcmsnd.close();
            System.out.println("Released connection to " + remoteAE);
            if (remoteStgCmtAE != null) {
                t1 = System.currentTimeMillis();
                try {
                    dcmsnd.openToStgcmtAE();
                } catch (Exception e) {
                    System.err.println("ERROR: Failed to establish association:" + e.getMessage());
                    System.exit(2);
                }
                t2 = System.currentTimeMillis();
                System.out.println("Connected to " + remoteStgCmtAE + " in " + ((t2 - t1) / 1000F) + "s");
                t1 = System.currentTimeMillis();
                if (dcmsnd.commit()) {
                    t2 = System.currentTimeMillis();
                    System.out.println("Request Storage Commitment from " + remoteStgCmtAE + " in "
                            + ((t2 - t1) / 1000F) + "s");
                    System.out.println("Waiting for Storage Commitment Result..");
                    try {
                        DicomObject cmtrslt = dcmsnd.waitForStgCmtResult();
                        t1 = System.currentTimeMillis();
                        promptStgCmt(cmtrslt, ((t1 - t2) / 1000F));
                    } catch (InterruptedException e) {
                        System.err.println("ERROR:" + e.getMessage());
                    }
                }
                dcmsnd.close();
                System.out.println("Released connection to " + remoteStgCmtAE);
            }
        } finally {
            dcmsnd.stop();
        }
    }
}

From source file:com.upload.DcmSnd.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    CommandLine cl = parse(args);/*from   w w w .  j a v  a 2s  .  c om*/
    DcmSnd dcmsnd = new DcmSnd(cl.hasOption("device") ? cl.getOptionValue("device") : "DCMSND");
    final List<String> argList = cl.getArgList();
    String remoteAE = argList.get(0);
    String[] calledAETAddress = split(remoteAE, '@');
    dcmsnd.setCalledAET(calledAETAddress[0]);
    if (calledAETAddress[1] == null) {
        dcmsnd.setRemoteHost("127.0.0.1");
        dcmsnd.setRemotePort(104);
    } else {
        String[] hostPort = split(calledAETAddress[1], ':');
        dcmsnd.setRemoteHost(hostPort[0]);
        dcmsnd.setRemotePort(toPort(hostPort[1]));
    }
    if (cl.hasOption("L")) {
        String localAE = cl.getOptionValue("L");
        String[] localPort = split(localAE, ':');
        if (localPort[1] != null) {
            dcmsnd.setLocalPort(toPort(localPort[1]));
        }
        String[] callingAETHost = split(localPort[0], '@');
        dcmsnd.setCalling(callingAETHost[0]);
        if (callingAETHost[1] != null) {
            dcmsnd.setLocalHost(callingAETHost[1]);
        }
    }
    dcmsnd.setOfferDefaultTransferSyntaxInSeparatePresentationContext(cl.hasOption("ts1"));
    dcmsnd.setSendFileRef(cl.hasOption("fileref"));
    if (cl.hasOption("username")) {
        String username = cl.getOptionValue("username");
        UserIdentity userId;
        if (cl.hasOption("passcode")) {
            String passcode = cl.getOptionValue("passcode");
            userId = new UserIdentity.UsernamePasscode(username, passcode.toCharArray());
        } else {
            userId = new UserIdentity.Username(username);
        }
        userId.setPositiveResponseRequested(cl.hasOption("uidnegrsp"));
        dcmsnd.setUserIdentity(userId);
    }
    dcmsnd.setStorageCommitment(cl.hasOption("stgcmt"));
    String remoteStgCmtAE = null;
    if (cl.hasOption("stgcmtae")) {
        try {
            remoteStgCmtAE = cl.getOptionValue("stgcmtae");
            String[] aet_hostport = split(remoteStgCmtAE, '@');
            String[] host_port = split(aet_hostport[1], ':');
            dcmsnd.setStgcmtCalledAET(aet_hostport[0]);
            dcmsnd.setRemoteStgcmtHost(host_port[0]);
            dcmsnd.setRemoteStgcmtPort(toPort(host_port[1]));
        } catch (Exception e) {
            exit("illegal argument of option -stgcmtae");
        }
    }
    if (cl.hasOption("set")) {
        String[] vals = cl.getOptionValues("set");
        for (int i = 0; i < vals.length; i++, i++) {
            dcmsnd.addCoerceAttr(Tag.toTag(vals[i]), vals[i + 1]);
        }
    }
    if (cl.hasOption("setuid")) {
        dcmsnd.setSuffixUID(cl.getOptionValues("setuid"));
    }
    if (cl.hasOption("connectTO"))
        dcmsnd.setConnectTimeout(parseInt(cl.getOptionValue("connectTO"),
                "illegal argument of option -connectTO", 1, Integer.MAX_VALUE));
    if (cl.hasOption("reaper"))
        dcmsnd.setAssociationReaperPeriod(parseInt(cl.getOptionValue("reaper"),
                "illegal argument of option -reaper", 1, Integer.MAX_VALUE));
    if (cl.hasOption("rspTO"))
        dcmsnd.setDimseRspTimeout(parseInt(cl.getOptionValue("rspTO"), "illegal argument of option -rspTO", 1,
                Integer.MAX_VALUE));
    if (cl.hasOption("acceptTO"))
        dcmsnd.setAcceptTimeout(parseInt(cl.getOptionValue("acceptTO"), "illegal argument of option -acceptTO",
                1, Integer.MAX_VALUE));
    if (cl.hasOption("releaseTO"))
        dcmsnd.setReleaseTimeout(parseInt(cl.getOptionValue("releaseTO"),
                "illegal argument of option -releaseTO", 1, Integer.MAX_VALUE));
    if (cl.hasOption("soclosedelay"))
        dcmsnd.setSocketCloseDelay(parseInt(cl.getOptionValue("soclosedelay"),
                "illegal argument of option -soclosedelay", 1, 10000));
    if (cl.hasOption("shutdowndelay"))
        dcmsnd.setShutdownDelay(parseInt(cl.getOptionValue("shutdowndelay"),
                "illegal argument of option -shutdowndelay", 1, 10000));
    if (cl.hasOption("anonymize"))
        dcmsnd.setAnonymize(Long.parseLong(cl.getOptionValue("anonymize")));
    if (cl.hasOption("rcvpdulen"))
        dcmsnd.setMaxPDULengthReceive(
                parseInt(cl.getOptionValue("rcvpdulen"), "illegal argument of option -rcvpdulen", 1, 10000)
                        * KB);
    if (cl.hasOption("sndpdulen"))
        dcmsnd.setMaxPDULengthSend(
                parseInt(cl.getOptionValue("sndpdulen"), "illegal argument of option -sndpdulen", 1, 10000)
                        * KB);
    if (cl.hasOption("sosndbuf"))
        dcmsnd.setSendBufferSize(
                parseInt(cl.getOptionValue("sosndbuf"), "illegal argument of option -sosndbuf", 1, 10000) * KB);
    if (cl.hasOption("sorcvbuf"))
        dcmsnd.setReceiveBufferSize(
                parseInt(cl.getOptionValue("sorcvbuf"), "illegal argument of option -sorcvbuf", 1, 10000) * KB);
    if (cl.hasOption("bufsize"))
        dcmsnd.setTranscoderBufferSize(
                parseInt(cl.getOptionValue("bufsize"), "illegal argument of option -bufsize", 1, 10000) * KB);
    if (cl.hasOption("batchsize"))
        dcmsnd.setBatchSize(Integer.parseInt(cl.getOptionValue("batchsize")));
    dcmsnd.setPackPDV(!cl.hasOption("pdv1"));
    dcmsnd.setTcpNoDelay(!cl.hasOption("tcpdelay"));
    if (cl.hasOption("async"))
        dcmsnd.setMaxOpsInvoked(
                parseInt(cl.getOptionValue("async"), "illegal argument of option -async", 0, 0xffff));
    if (cl.hasOption("lowprior"))
        dcmsnd.setPriority(CommandUtils.LOW);
    if (cl.hasOption("highprior"))
        dcmsnd.setPriority(CommandUtils.HIGH);
    System.out.println("Scanning files to send");
    long t1 = System.currentTimeMillis();
    for (int i = 1, n = argList.size(); i < n; ++i)
        dcmsnd.addFile(new File(argList.get(i)));
    long t2 = System.currentTimeMillis();
    if (dcmsnd.getNumberOfFilesToSend() == 0) {
        // System.exit(2);
    }
    System.out.println("\nScanned " + dcmsnd.getNumberOfFilesToSend() + " files in " + ((t2 - t1) / 1000F)
            + "s (=" + ((t2 - t1) / dcmsnd.getNumberOfFilesToSend()) + "ms/file)");
    dcmsnd.configureTransferCapability();
    if (cl.hasOption("tls")) {
        String cipher = cl.getOptionValue("tls");
        if ("NULL".equalsIgnoreCase(cipher)) {
            dcmsnd.setTlsWithoutEncyrption();
        } else if ("3DES".equalsIgnoreCase(cipher)) {
            dcmsnd.setTls3DES_EDE_CBC();
        } else if ("AES".equalsIgnoreCase(cipher)) {
            dcmsnd.setTlsAES_128_CBC();
        } else {
            exit("Invalid parameter for option -tls: " + cipher);
        }

        if (cl.hasOption("tls1")) {
            dcmsnd.setTlsProtocol(TLS1);
        } else if (cl.hasOption("ssl3")) {
            dcmsnd.setTlsProtocol(SSL3);
        } else if (cl.hasOption("no_tls1")) {
            dcmsnd.setTlsProtocol(NO_TLS1);
        } else if (cl.hasOption("no_ssl3")) {
            dcmsnd.setTlsProtocol(NO_SSL3);
        } else if (cl.hasOption("no_ssl2")) {
            dcmsnd.setTlsProtocol(NO_SSL2);
        }
        dcmsnd.setTlsNeedClientAuth(!cl.hasOption("noclientauth"));

        if (cl.hasOption("keystore")) {
            dcmsnd.setKeyStoreURL(cl.getOptionValue("keystore"));
        }
        if (cl.hasOption("keystorepw")) {
            dcmsnd.setKeyStorePassword(cl.getOptionValue("keystorepw"));
        }
        if (cl.hasOption("keypw")) {
            dcmsnd.setKeyPassword(cl.getOptionValue("keypw"));
        }
        if (cl.hasOption("truststore")) {
            dcmsnd.setTrustStoreURL(cl.getOptionValue("truststore"));
        }
        if (cl.hasOption("truststorepw")) {
            dcmsnd.setTrustStorePassword(cl.getOptionValue("truststorepw"));
        }
        try {
            dcmsnd.initTLS();
        } catch (Exception e) {
            System.err.println("ERROR: Failed to initialize TLS context:" + e.getMessage());
            // System.exit(2);
        }
    }
    while (dcmsnd.getLastSentFile() < dcmsnd.getNumberOfFilesToSend()) {
        try {
            dcmsnd.start();
        } catch (Exception e) {
            System.err.println("ERROR: Failed to start server for receiving " + "Storage Commitment results:"
                    + e.getMessage());
            //  System.exit(2);
        }
        try {
            t1 = System.currentTimeMillis();
            try {
                dcmsnd.open();
            } catch (Exception e) {
                System.err.println("ERROR: Failed to establish association:" + e.getMessage());
                // System.exit(2);
            }
            t2 = System.currentTimeMillis();
            System.out.println("Connected to " + remoteAE + " in " + ((t2 - t1) / 1000F) + "s");

            t1 = System.currentTimeMillis();
            dcmsnd.send();
            t2 = System.currentTimeMillis();
            prompt(dcmsnd, (t2 - t1) / 1000F);
            if (dcmsnd.isStorageCommitment()) {
                t1 = System.currentTimeMillis();
                if (dcmsnd.commit()) {
                    t2 = System.currentTimeMillis();
                    System.out.println(
                            "Request Storage Commitment from " + remoteAE + " in " + ((t2 - t1) / 1000F) + "s");
                    System.out.println("Waiting for Storage Commitment Result..");
                    try {
                        DicomObject cmtrslt = dcmsnd.waitForStgCmtResult();
                        t1 = System.currentTimeMillis();
                        promptStgCmt(cmtrslt, ((t1 - t2) / 1000F));
                    } catch (InterruptedException e) {
                        System.err.println("ERROR:" + e.getMessage());
                    }
                }
            }
            dcmsnd.close();
            System.out.println("Released connection to " + remoteAE);
            if (remoteStgCmtAE != null) {
                t1 = System.currentTimeMillis();
                try {
                    dcmsnd.openToStgcmtAE();
                } catch (Exception e) {
                    System.err.println("ERROR: Failed to establish association:" + e.getMessage());
                    // System.exit(2);
                }
                t2 = System.currentTimeMillis();
                System.out.println("Connected to " + remoteStgCmtAE + " in " + ((t2 - t1) / 1000F) + "s");
                t1 = System.currentTimeMillis();
                if (dcmsnd.commit()) {
                    t2 = System.currentTimeMillis();
                    System.out.println("Request Storage Commitment from " + remoteStgCmtAE + " in "
                            + ((t2 - t1) / 1000F) + "s");
                    System.out.println("Waiting for Storage Commitment Result..");
                    try {
                        DicomObject cmtrslt = dcmsnd.waitForStgCmtResult();
                        t1 = System.currentTimeMillis();
                        promptStgCmt(cmtrslt, ((t1 - t2) / 1000F));
                    } catch (InterruptedException e) {
                        System.err.println("ERROR:" + e.getMessage());
                    }
                }
                dcmsnd.close();
                System.out.println("Released connection to " + remoteStgCmtAE);
            }
        } finally {
            dcmsnd.stop();
        }
    }
}

From source file:movierecommend.MovieRecommend.java

public static void main(String[] args) throws ClassNotFoundException, SQLException {
    String url = "jdbc:sqlserver://localhost;databaseName=MovieDB;integratedSecurity=true";
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    Connection conn = DriverManager.getConnection(url);

    Statement stm = conn.createStatement();
    ResultSet rsRecnik = stm.executeQuery("SELECT Recnik FROM Recnik WHERE (ID_Zanra = 1)"); //citam recnik iz baze za odredjeni zanr
    String recnik[] = null;/*from  w  w  w .j a va 2s . c om*/

    while (rsRecnik.next()) {
        recnik = rsRecnik.getString("Recnik").split(","); //delim recnik na reci

    }

    ResultSet rsFilmovi = stm.executeQuery(
            "SELECT TOP (200) Naziv_Filma, LemmaPlots, " + "ID_Filma FROM Film WHERE (ID_Zanra = 1)");
    List<Film> listaFilmova = new ArrayList<>();
    Film f = null;
    int rb = 0;
    while (rsFilmovi.next()) {
        f = new Film(rb, Integer.parseInt(rsFilmovi.getString("ID_Filma")), rsFilmovi.getString("Naziv_Filma"),
                rsFilmovi.getString("LemmaPlots"));
        listaFilmova.add(f);
        rb++;

    }
    //kreiranje vektorskog modela
    M = MatrixUtils.createRealMatrix(recnik.length, listaFilmova.size());
    System.out.println("Prva tezinska matrica");

    for (int i = 0; i < recnik.length; i++) {
        String recBaza = recnik[i];
        for (Film film : listaFilmova) {
            for (String lemmaRec : film.getPlotLema()) {
                if (recBaza.equals(lemmaRec)) {
                    M.setEntry(i, film.getRb(), M.getEntry(i, film.getRb()) + 1);
                }
            }
        }
    }
    //racunanje tf-idf
    System.out.println("td-idf");
    M = LSA.calculateTfIdf(M);
    System.out.println("SVD");
    //SVD
    SingularValueDecomposition svd = new SingularValueDecomposition(M);
    RealMatrix V = svd.getV();
    RealMatrix Vk = V.getSubMatrix(0, V.getRowDimension() - 1, 0, brojDimenzija - 1); //dimenzija je poslednji argument
    //kosinusna slicnost
    System.out.println("Cosin simmilarity");
    CallableStatement stmTop = conn.prepareCall("{call Dodaj_TopList(?,?,?)}");

    for (int j = 0; j < listaFilmova.size(); j++) {
        Film fl = listaFilmova.get(j);
        List<Film> lFilmova1 = new ArrayList<>();
        lFilmova1.add(listaFilmova.get(j));
        double sim = 0.0;
        for (int k = 0; k < listaFilmova.size(); k++) {
            // System.out.println(listaFilmova.size());                
            sim = LSA.cosinSim(j, k, Vk.transpose());
            listaFilmova.get(k).setSimilarity(sim);
            lFilmova1.add(listaFilmova.get(k));
        }
        Collections.sort(lFilmova1);
        for (int k = 2; k < 13; k++) {
            stmTop.setString(1, fl.getID() + "");
            stmTop.setString(2, lFilmova1.get(k).getID() + "");
            stmTop.setString(3, lFilmova1.get(k).getSimilarity() + "");
            stmTop.execute();
        }

    }

    stm.close();
    rsRecnik.close();
    rsFilmovi.close();
    conn.close();

}

From source file:com.microsoft.gittf.client.clc.Main.java

public static void main(String[] args) {
    // Configure logging, use the standard TFS SDK logging.
    System.setProperty("teamexplorer.application", ProductInformation.getProductName()); //$NON-NLS-1$
    LoggingConfiguration.configure();/*  w  ww .j  a v  a2  s.  co m*/

    final Log log = LogFactory.getLog(ProductInformation.getProductName());

    try {
        ArgumentCollection mainArguments = new ArgumentCollection();

        try {
            mainArguments = ArgumentParser.parse(args, ARGUMENTS,
                    ArgumentParserOptions.ALLOW_UNKNOWN_ARGUMENTS);
        } catch (ArgumentParserException e) {
            console.getErrorStream().println(e.getLocalizedMessage());
            console.getErrorStream().println(getUsage());
            System.exit(ExitCode.FAILURE);
        }

        if (mainArguments.contains("version")) //$NON-NLS-1$
        {
            console.getOutputStream().println(Messages.formatString("Main.ApplicationVersionFormat", //$NON-NLS-1$
                    ProductInformation.getProductName(), ProductInformation.getBuildNumber()));

            return;
        }

        /*
         * Special case "--help command" handling - convert to
         * "help command"
         */
        if (mainArguments.contains("help") && mainArguments.contains("command")) //$NON-NLS-1$ //$NON-NLS-2$
        {
            HelpCommand helpCommand = new HelpCommand();
            helpCommand.setArguments(ArgumentParser.parse(new String[] {
                    ((FreeArgumentCollection) mainArguments.getArgument("command")).getValues()[0] //$NON-NLS-1$                
            }, helpCommand.getPossibleArguments()));

            helpCommand.setConsole(console);
            helpCommand.run();
            return;
        } else if (mainArguments.contains("help") || !mainArguments.contains("command")) //$NON-NLS-1$ //$NON-NLS-2$
        {
            showHelp();
            return;
        }

        // Set the verbosity of the console from the arguments.
        if (mainArguments.contains("quiet")) //$NON-NLS-1$
        {
            console.setVerbosity(Verbosity.QUIET);
        } else if (mainArguments.contains("verbose")) //$NON-NLS-1$
        {
            console.setVerbosity(Verbosity.VERBOSE);
        }

        /*
         * Parse the free arguments into the command name and arguments to
         * pass to it. Add any unmatched arguments that were specified on
         * the command line before the argument. (eg, for
         * "git-tf --bare clone", we parsed the "--bare" as an unmatched
         * argument to the main command. We instead want to add the "--bare"
         * as an argument to "clone".)
         */
        String[] fullCommand = ((FreeArgumentCollection) mainArguments.getArgument("command")).getValues(); //$NON-NLS-1$
        String[] additionalArguments = mainArguments.getUnknownArguments();

        String commandName = fullCommand[0];
        String[] commandArgs = new String[additionalArguments.length + (fullCommand.length - 1)];

        if (additionalArguments.length > 0) {
            System.arraycopy(additionalArguments, 0, commandArgs, 0, additionalArguments.length);
        }

        if (fullCommand.length > 1) {
            System.arraycopy(fullCommand, 1, commandArgs, mainArguments.getUnknownArguments().length,
                    fullCommand.length - 1);
        }

        // Locate the specified command by name
        List<CommandDefinition> possibleCommands = new ArrayList<CommandDefinition>();

        for (CommandDefinition c : COMMANDS) {
            if (c.getName().equals(commandName)) {
                possibleCommands.clear();
                possibleCommands.add(c);
                break;
            } else if (c.getName().startsWith(commandName)) {
                possibleCommands.add(c);
            }
        }

        if (possibleCommands.size() == 0) {
            printError(Messages.formatString("Main.CommandNotFoundFormat", commandName, //$NON-NLS-1$
                    ProductInformation.getProductName()));
            System.exit(1);
        }

        if (possibleCommands.size() > 1) {
            printError(Messages.formatString("Main.AmbiguousCommandFormat", commandName, //$NON-NLS-1$
                    ProductInformation.getProductName()));

            for (CommandDefinition c : possibleCommands) {
                printError(Messages.formatString("Main.AmbiguousCommandListFormat", c.getName()), false); //$NON-NLS-1$
            }

            System.exit(1);
        }

        // Instantiate the command
        final CommandDefinition commandDefinition = possibleCommands.get(0);
        Command command = null;

        try {
            command = commandDefinition.getType().newInstance();
        } catch (Exception e) {
            printError(Messages.formatString("Main.CommandCreationFailedFormat", commandName)); //$NON-NLS-1$
            System.exit(1);
        }

        // Set the console
        command.setConsole(console);

        // Parse the arguments
        ArgumentCollection argumentCollection = null;

        try {
            argumentCollection = ArgumentParser.parse(commandArgs, command.getPossibleArguments());
        } catch (ArgumentParserException e) {
            Main.printError(e.getLocalizedMessage());
            Main.printError(getUsage(command));

            log.error("Could not parse arguments", e); //$NON-NLS-1$
            System.exit(1);
        }

        // Handle the --help argument directly
        if (argumentCollection.contains("help")) //$NON-NLS-1$
        {
            command.showHelp();
            System.exit(0);
        }

        // Set the verbosity of the console from the arguments.
        if (argumentCollection.contains("quiet")) //$NON-NLS-1$
        {
            console.setVerbosity(Verbosity.QUIET);
        } else if (argumentCollection.contains("verbose")) //$NON-NLS-1$
        {
            console.setVerbosity(Verbosity.VERBOSE);
        }

        command.setArguments(argumentCollection);

        System.exit(command.run());

    } catch (Exception e) {
        printError(e.getLocalizedMessage());
        log.warn(MessageFormat.format("Error executing command: {0}", getCommandLine(args)), e); //$NON-NLS-1$
    }
}

From source file:CourserankConnector.java

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

    //MaxentTagger tagger = new MaxentTagger("models/english-left3words-distsim.tagger");
    /////from  w  ww . j a v  a  2  s.  co m
    //CLIENT INITIALIZATION
    ImportData importCourse = new ImportData();
    HttpClient httpclient = new DefaultHttpClient();
    httpclient = WebClientDevWrapper.wrapClient(httpclient);
    try {
        /*
         httpclient.getCredentialsProvider().setCredentials(
            new AuthScope(null, -1),
            new UsernamePasswordCredentials("eadrian", "eactresp1"));
        */
        //////////////////////////////////////////////////
        //Get Course Bulletin Departments page
        List<Course> courses = new ArrayList<Course>();

        HttpGet httpget = new HttpGet("http://explorecourses.stanford.edu");

        System.out.println("executing request" + httpget.getRequestLine());
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();

        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        String bulletinpage = "";

        //STORE RETURNED HTML TO BULLETINPAGE

        if (entity != null) {
            //System.out.println("Response content length: " + entity.getContentLength());
            InputStream i = entity.getContent();
            BufferedReader br = new BufferedReader(new InputStreamReader(i));
            String line;
            while ((line = br.readLine()) != null) {
                bulletinpage += line;
                //System.out.println(line);
            }
            br.close();
            i.close();
        }
        EntityUtils.consume(entity);

        ///////////////////////////////////////////////////////////////////////////////
        //Login to Courserank

        httpget = new HttpGet("https://courserank.com/stanford/main");

        System.out.println("executing request" + httpget.getRequestLine());
        response = httpclient.execute(httpget);
        entity = response.getEntity();

        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        String page = "";
        if (entity != null) {
            System.out.println("Response content length: " + entity.getContentLength());
            InputStream i = entity.getContent();
            BufferedReader br = new BufferedReader(new InputStreamReader(i));
            String line;
            while ((line = br.readLine()) != null) {
                page += line;
                //System.out.println(line);
            }
            br.close();
            i.close();
        }
        EntityUtils.consume(entity);
        ////////////////////////////////////////////////////
        //POST REQUEST LOGIN

        HttpPost post = new HttpPost("https://www.courserank.com/stanford/main");

        List<NameValuePair> pairs = new ArrayList<NameValuePair>(2);

        pairs.add(new BasicNameValuePair("RT", ""));
        pairs.add(new BasicNameValuePair("action", "login"));
        pairs.add(new BasicNameValuePair("password", "trespass"));
        pairs.add(new BasicNameValuePair("username", "eaconte@stanford.edu"));
        post.setEntity(new UrlEncodedFormEntity(pairs));
        System.out.println("executing request" + post.getRequestLine());
        HttpResponse resp = httpclient.execute(post);
        HttpEntity ent = resp.getEntity();

        System.out.println("----------------------------------------");
        if (ent != null) {
            System.out.println("Response content length: " + ent.getContentLength());
            InputStream i = ent.getContent();
            BufferedReader br = new BufferedReader(new InputStreamReader(i));
            String line;
            while ((line = br.readLine()) != null) {
                //System.out.println(line);
            }
            br.close();
            i.close();
        }
        EntityUtils.consume(ent);
        ///////////////////////////////////////////////////
        //THIS STEP MAY NOT BE NEEDED BUT GETS MAIN PROFILE PAGE

        HttpGet gethome = new HttpGet("https://www.courserank.com/stanford/home");

        System.out.println("executing request" + gethome.getRequestLine());
        HttpResponse gresp = httpclient.execute(gethome);
        HttpEntity gent = gresp.getEntity();

        System.out.println("----------------------------------------");
        if (ent != null) {
            System.out.println("Response content length: " + gent.getContentLength());
            InputStream i = gent.getContent();
            BufferedReader br = new BufferedReader(new InputStreamReader(i));
            String line;
            while ((line = br.readLine()) != null) {
                //System.out.println(line);
            }
            br.close();
            i.close();
        }

        /////////////////////////////////////////////////////////////////////////////////
        //Parse Bulletin

        String results = getToken(bulletinpage, "RESULTS HEADER", "Additional Searches");
        String[] depts = results.split("href");

        //SPLIT FOR EACH DEPARTMENT LINK, ITERATE
        boolean ready = false;
        for (int i = 1; i < depts.length; i++) {
            //EXTRACT LINK, DEPARTMENT NAME AND ABBREVIATION
            String dept = new String(depts[i]);
            String abbr = getToken(dept, "(", ")");
            String name = getToken(dept, ">", "(");
            name.trim();
            //System.out.println(tagger.tagString(name));
            String link = getToken(dept, "=\"", "\">");
            System.out.println(name + " : " + abbr + " : " + link);

            System.out.println("======================================================================");

            if (i <= 10 || i >= 127) //values to keep it to undergraduate courses. Excludes law, med, business, overseas
                continue;
            /*if (i<=46)
               continue; */ //Start at BIOHOP
            /*if (abbr.equals("INTNLREL"))
               ready = true;
            if (!ready)
               continue;*/
            //Construct department course search URL
            //Then request page
            String URL = "http://explorecourses.stanford.edu/" + link
                    + "&filter-term-Autumn=on&filter-term-Winter=on&filter-term-Spring=on";
            httpget = new HttpGet(URL);

            //System.out.println("executing request" + httpget.getRequestLine());
            response = httpclient.execute(httpget);
            entity = response.getEntity();

            //ystem.out.println("----------------------------------------");
            //System.out.println(response.getStatusLine());
            String rpage = "";
            if (entity != null) {
                //System.out.println("Response content length: " + entity.getContentLength());
                InputStream in = entity.getContent();
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
                String line;
                while ((line = br.readLine()) != null) {
                    rpage += line;
                    //System.out.println(line);
                }
                br.close();
                in.close();
            }
            EntityUtils.consume(entity);

            //Process results page
            List<Course> deptCourses = new ArrayList<Course>();
            List<Course> result = processResultPage(rpage);
            deptCourses.addAll(result);

            //While there are more result pages, keep going
            boolean more = (!(result.size() == 0) && (result.get((result.size() - 1)).courseNumber < 299));
            boolean morepages = anotherPage(rpage);
            while (morepages && more) {
                URL = nextURL(URL);
                httpget = new HttpGet(URL);

                //System.out.println("executing request" + httpget.getRequestLine());
                response = httpclient.execute(httpget);
                entity = response.getEntity();

                //System.out.println("----------------------------------------");
                //System.out.println(response.getStatusLine());
                rpage = "";
                if (entity != null) {
                    //System.out.println("Response content length: " + entity.getContentLength());
                    InputStream in = entity.getContent();
                    BufferedReader br = new BufferedReader(new InputStreamReader(in));
                    String line;
                    while ((line = br.readLine()) != null) {
                        rpage += line;
                        //System.out.println(line);
                    }
                    br.close();
                    in.close();
                }
                EntityUtils.consume(entity);
                morepages = anotherPage(rpage);
                result = processResultPage(rpage);
                deptCourses.addAll(result);
                more = (!(result.size() == 0) && (result.get((result.size() - 1)).courseNumber < 299));
                /*String mores = more? "yes": "no";
                String pagess = morepages?"yes":"no";
                System.out.println("more: "+mores+" morepages: "+pagess);
                System.out.println("more");*/
            }

            //Get course ratings for all department courses via courserank
            deptCourses = getRatings(httpclient, abbr, deptCourses);
            for (int j = 0; j < deptCourses.size(); j++) {
                Course c = deptCourses.get(j);
                System.out.println("" + c.title + " : " + c.rating);
                c.tags = name;
                c.code = c.code.trim();
                c.department = name;
                c.deptAB = abbr;
                c.writeToDatabase();
                //System.out.println(tagger.tagString(c.title));
            }

        }

        if (!page.equals(""))
            return;

        ///////////////////////////////////////////////////
        //Get Course Bulletin Department courses 

        /*
                
         httpget = new HttpGet("https://courserank.com/stanford/main");
                
         System.out.println("executing request" + httpget.getRequestLine());
         response = httpclient.execute(httpget);
         entity = response.getEntity();
                
         System.out.println("----------------------------------------");
         System.out.println(response.getStatusLine());
         page = "";
         if (entity != null) {
        System.out.println("Response content length: " + entity.getContentLength());
        InputStream i = entity.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(i));
        String line;
        while ((line = br.readLine()) != null) {
           page +=line;
           //System.out.println(line);
        }
        br.close();
        i.close();
         }
         EntityUtils.consume(entity);
         ////////////////////////////////////////////////////
         //POST REQUEST LOGIN
                 
                 
         HttpPost post = new HttpPost("https://www.courserank.com/stanford/main");
                 
         List<NameValuePair> pairs = new ArrayList<NameValuePair>(2);
                 
                 
         pairs.add(new BasicNameValuePair("RT", ""));
         pairs.add(new BasicNameValuePair("action", "login"));
         pairs.add(new BasicNameValuePair("password", "trespass"));
         pairs.add(new BasicNameValuePair("username", "eaconte@stanford.edu"));
         post.setEntity(new UrlEncodedFormEntity(pairs));
         System.out.println("executing request" + post.getRequestLine());
         HttpResponse resp = httpclient.execute(post);
         HttpEntity ent = resp.getEntity();
                 
         System.out.println("----------------------------------------");
         if (ent != null) {
        System.out.println("Response content length: " + ent.getContentLength());
        InputStream i = ent.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(i));
        String line;
        while ((line = br.readLine()) != null) {
           //System.out.println(line);
        }
        br.close();
        i.close();
         }
         EntityUtils.consume(ent);
         ///////////////////////////////////////////////////
         //THIS STEP MAY NOT BE NEEDED BUT GETS MAIN PROFILE PAGE
                 
         HttpGet gethome = new HttpGet("https://www.courserank.com/stanford/home");
                 
                 
         System.out.println("executing request" + gethome.getRequestLine());
         HttpResponse gresp = httpclient.execute(gethome);
         HttpEntity gent = gresp.getEntity();
                 
         System.out.println("----------------------------------------");
         if (ent != null) {
        System.out.println("Response content length: " + gent.getContentLength());
        InputStream i = gent.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(i));
        String line;
        while ((line = br.readLine()) != null) {
           //System.out.println(line);
        }
        br.close();
        i.close();
         }
                 
                 
         ////////////////////////////////////////
         //GETS FIRST PAGE OF RESULTS
         EntityUtils.consume(gent);
                 
         post = new HttpPost("https://www.courserank.com/stanford/search_results");
                 
         pairs = new ArrayList<NameValuePair>(2);
                 
                 
         pairs.add(new BasicNameValuePair("filter_term_currentYear", "on"));
         pairs.add(new BasicNameValuePair("query", ""));
         post.setEntity(new UrlEncodedFormEntity(pairs));
         System.out.println("executing request" + post.getRequestLine());
         resp = httpclient.execute(post);
         ent = resp.getEntity();
                 
         System.out.println("----------------------------------------");
                 
         String rpage = "";
         if (ent != null) {
        System.out.println("Response content length: " + ent.getContentLength());
        InputStream i = ent.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(i));
        String line;
        while ((line = br.readLine()) != null) {
           rpage += line;
           System.out.println(line);
        }
        br.close();
        i.close();
         }
         EntityUtils.consume(ent);
                 
         ////////////////////////////////////////////////////
         //PARSE FIRST PAGE OF RESULTS
                 
         //int index = rpage.indexOf("div class=\"searchItem");
         String []classSplit = rpage.split("div class=\"searchItem");
         for (int i=1; i<classSplit.length; i++) {
            String str = classSplit[i];
                    
            //ID
            String CID = getToken(str, "course?id=","\">");
                    
            // CODE 
            String CODE = getToken(str,"class=\"code\">" ,":</");
                    
            //TITLE 
            String NAME = getToken(str, "class=\"title\">","</");
                    
            //DESCRIP
            String DES = getToken(str, "class=\"description\">","</");
                    
            //TERM
            String TERM = getToken(str, "Terms:", "|");
                    
            //UNITS
            String UNITS = getToken(str, "Units:", "<br/>");
                
            //WORKLOAD
                    
            String WLOAD = getToken(str, "Workload:", "|");
                    
            //GER
            String GER = getToken(str, "GERs:", "</d");
                    
            //RATING
            int searchIndex = 0;
            float rating = 0;
            while (true) {
          int ratingIndex = str.indexOf("large_Full", searchIndex);
          if (ratingIndex ==-1) {
             int halfratingIndex = str.indexOf("large_Half", searchIndex);
             if (halfratingIndex == -1)
                break;
             else
                rating += .5;
             break;
          }
          searchIndex = ratingIndex+1;
          rating++;
                     
            }
            String RATING = ""+rating;
                    
            //GRADE
            String GRADE = getToken(str, "div class=\"unofficialGrade\">", "</");
            if (GRADE.equals("NOT FOUND")) {
          GRADE = getToken(str, "div class=\"officialGrade\">", "</");
            }
                    
            //REVIEWS
            String REVIEWS = getToken(str, "class=\"ratings\">", " ratings");
                    
                    
            System.out.println(""+CODE+" : "+NAME + " : "+CID);
            System.out.println("----------------------------------------");
            System.out.println("Term: "+TERM+" Units: "+UNITS+ " Workload: "+WLOAD + " Grade: "+ GRADE);
            System.out.println("Rating: "+RATING+ " Reviews: "+REVIEWS);
            System.out.println("==========================================");
            System.out.println(DES);
            System.out.println("==========================================");
                    
                    
                    
         }
                 
                 
         ///////////////////////////////////////////////////
         //GETS SECOND PAGE OF RESULTS
         post = new HttpPost("https://www.courserank.com/stanford/search_results");
                 
         pairs = new ArrayList<NameValuePair>(2);
                 
                 
         pairs.add(new BasicNameValuePair("filter_term_currentYear", "on"));
         pairs.add(new BasicNameValuePair("page", "2"));
         pairs.add(new BasicNameValuePair("query", ""));
         post.setEntity(new UrlEncodedFormEntity(pairs));
         System.out.println("executing request" + post.getRequestLine());
         resp = httpclient.execute(post);
         ent = resp.getEntity();
                 
         System.out.println("----------------------------------------");
         if (ent != null) {
        System.out.println("Response content length: " + ent.getContentLength());
        InputStream i = ent.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(i));
        String line;
        while ((line = br.readLine()) != null) {
           //System.out.println(line);
        }
        br.close();
        i.close();
         }
         EntityUtils.consume(ent);
                 
         /*
         httpget = new HttpGet("https://github.com/");
                
         System.out.println("executing request" + httpget.getRequestLine());
         response = httpclient.execute(httpget);
         entity = response.getEntity();
                
         System.out.println("----------------------------------------");
         System.out.println(response.getStatusLine());
         page = "";
         if (entity != null) {
        System.out.println("Response content length: " + entity.getContentLength());
        InputStream i = entity.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(i));
        String line;
        while ((line = br.readLine()) != null) {
           page +=line;
           System.out.println(line);
        }
        br.close();
        i.close();
         }*/
        EntityUtils.consume(entity);

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