Example usage for java.io PrintStream println

List of usage examples for java.io PrintStream println

Introduction

In this page you can find the example usage for java.io PrintStream println.

Prototype

public void println(Object x) 

Source Link

Document

Prints an Object and then terminate the line.

Usage

From source file:MainClass.java

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

    System.setProperty("javax.net.ssl.trustStore", "clienttrust");
    SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    Socket s = ssf.createSocket("127.0.0.1", 8888);

    OutputStream outs = s.getOutputStream();
    PrintStream out = new PrintStream(outs);
    InputStream ins = s.getInputStream();
    BufferedReader in = new BufferedReader(new InputStreamReader(ins));

    out.println("Hi,How are u!");
    out.println("");
    String line = null;/* w w w  . j a  va  2 s.c  om*/
    while ((line = in.readLine()) != null) {
        System.out.println(line);
    }

    in.close();
    out.close();
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    FileOutputStream fouts = null;
    System.setProperty("javax.net.ssl.trustStore", "clienttrust");
    SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    Socket s = ssf.createSocket("127.0.0.1", 5432);

    OutputStream outs = s.getOutputStream();
    PrintStream out = new PrintStream(outs);
    InputStream ins = s.getInputStream();
    BufferedReader in = new BufferedReader(new InputStreamReader(ins));

    out.println(args[0]);
    fouts = new FileOutputStream("result.html");
    //  fouts = new FileOutputStream("result.gif");
    int kk;/*from www .j  a v  a 2  s .co m*/
    while ((kk = ins.read()) != -1) {
        fouts.write(kk);
    }
    in.close();
    fouts.close();
}

From source file:com.googlecode.shutdownlistener.ShutdownUtility.java

public static void main(String[] args) throws Exception {
    final ShutdownConfiguration config = ShutdownConfiguration.getInstance();

    final String command;
    if (args.length > 0) {
        command = args[0];//from   w  ww  . ja  v a 2s. c  o  m
    } else {
        command = config.getStatusCommand();
    }

    System.out.println("Calling " + config.getHost() + ":" + config.getPort() + " with command: " + command);

    final InetAddress hostAddress = InetAddress.getByName(config.getHost());
    final Socket shutdownConnection = new Socket(hostAddress, config.getPort());
    try {
        shutdownConnection.setSoTimeout(5000);
        final BufferedReader reader = new BufferedReader(
                new InputStreamReader(shutdownConnection.getInputStream()));
        final PrintStream writer = new PrintStream(shutdownConnection.getOutputStream());
        try {
            writer.println(command);
            writer.flush();

            while (true) {
                final String line = reader.readLine();
                if (line == null) {
                    break;
                }

                System.out.println(line);
            }
        } finally {
            IOUtils.closeQuietly(reader);
            IOUtils.closeQuietly(writer);
        }
    } finally {
        try {
            shutdownConnection.close();
        } catch (IOException ioe) {
        }
    }

}

From source file:cc.wikitools.lucene.ScoreWikipediaArticle.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(//from w  ww . j  av  a2 s  . c  om
            OptionBuilder.withArgName("path").hasArg().withDescription("index location").create(INDEX_OPTION));
    options.addOption(
            OptionBuilder.withArgName("num").hasArg().withDescription("article id").create(ID_OPTION));
    options.addOption(
            OptionBuilder.withArgName("string").hasArg().withDescription("article title").create(TITLE_OPTION));
    options.addOption(
            OptionBuilder.withArgName("string").hasArg().withDescription("query text").create(QUERY_OPTION));

    CommandLine cmdline = null;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (!(cmdline.hasOption(ID_OPTION) || cmdline.hasOption(TITLE_OPTION)) || !cmdline.hasOption(INDEX_OPTION)
            || !cmdline.hasOption(QUERY_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(ScoreWikipediaArticle.class.getName(), options);
        System.exit(-1);
    }

    File indexLocation = new File(cmdline.getOptionValue(INDEX_OPTION));
    if (!indexLocation.exists()) {
        System.err.println("Error: " + indexLocation + " does not exist!");
        System.exit(-1);
    }

    String queryText = cmdline.getOptionValue(QUERY_OPTION);

    WikipediaSearcher searcher = new WikipediaSearcher(indexLocation);
    PrintStream out = new PrintStream(System.out, true, "UTF-8");

    if (cmdline.hasOption(ID_OPTION)) {
        out.println("score: "
                + searcher.scoreArticle(queryText, Integer.parseInt(cmdline.getOptionValue(ID_OPTION))));
    } else {
        out.println("score: " + searcher.scoreArticle(queryText, cmdline.getOptionValue(TITLE_OPTION)));
    }

    searcher.close();
    out.close();
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    ServerSocket ssock = new ServerSocket(1234);
    Socket sock = ssock.accept();
    ssock.close();//from w w w  .j  a v a 2 s  .co m

    PrintStream pstream = new PrintStream(sock.getOutputStream());
    pstream.print("count? ");
    BufferedReader input = new BufferedReader(new InputStreamReader(sock.getInputStream()));
    String line = input.readLine();
    pstream.println("");
    int count = Integer.parseInt(line);
    for (int i = count; i >= 0; i--) {
        pstream.println(i);
    }
    pstream.close();
    sock.close();
}

From source file:cc.twittertools.index.ExtractTweetidsFromIndex.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(//from www  . ja v  a  2s . c o  m
            OptionBuilder.withArgName("dir").hasArg().withDescription("index location").create(INDEX_OPTION));

    CommandLine cmdline = null;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (!cmdline.hasOption(INDEX_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(ExtractTweetidsFromIndex.class.getName(), options);
        System.exit(-1);
    }

    File indexLocation = new File(cmdline.getOptionValue(INDEX_OPTION));
    if (!indexLocation.exists()) {
        System.err.println("Error: " + indexLocation + " does not exist!");
        System.exit(-1);
    }

    IndexReader reader = DirectoryReader.open(FSDirectory.open(indexLocation));
    PrintStream out = new PrintStream(System.out, true, "UTF-8");
    for (int i = 0; i < reader.maxDoc(); i++) {
        Document doc = reader.document(i);
        out.println(doc.getField(StatusField.ID.name).stringValue() + "\t"
                + doc.getField(StatusField.SCREEN_NAME.name).stringValue());
    }
    out.close();
    reader.close();
}

From source file:cc.wikitools.lucene.FindWikipediaArticleId.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(//from  w w w . ja v  a 2 s . co  m
            OptionBuilder.withArgName("path").hasArg().withDescription("index location").create(INDEX_OPTION));
    options.addOption(
            OptionBuilder.withArgName("string").hasArg().withDescription("article title").create(TITLE_OPTION));

    CommandLine cmdline = null;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (!cmdline.hasOption(TITLE_OPTION) || !cmdline.hasOption(INDEX_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(FindWikipediaArticleId.class.getName(), options);
        System.exit(-1);
    }

    File indexLocation = new File(cmdline.getOptionValue(INDEX_OPTION));
    if (!indexLocation.exists()) {
        System.err.println("Error: " + indexLocation + " does not exist!");
        System.exit(-1);
    }

    String title = cmdline.getOptionValue(TITLE_OPTION);

    PrintStream out = new PrintStream(System.out, true, "UTF-8");

    WikipediaSearcher searcher = new WikipediaSearcher(indexLocation);
    int id = searcher.getArticleId(title);

    out.println(title + ": id = " + id);

    searcher.close();
    out.close();
}

From source file:com.datastax.brisk.demo.pricer.Pricer.java

public static void main(String[] arguments) throws Exception {
    long latency, oldLatency;
    int epoch, total, oldTotal, keyCount, oldKeyCount;

    try {/* www  .j  av  a2s  .co  m*/
        session = new Session(arguments);
    } catch (IllegalArgumentException e) {
        printHelpMessage();
        return;
    }

    session.createKeySpaces();

    int threadCount = session.getThreads();
    Thread[] consumers = new Thread[threadCount];
    PrintStream out = session.getOutputStream();

    out.println("total,interval_op_rate,interval_key_rate,avg_latency,elapsed_time");

    int itemsPerThread = session.getKeysPerThread();
    int modulo = session.getNumKeys() % threadCount;

    // creating required type of the threads for the test
    for (int i = 0; i < threadCount; i++) {
        if (i == threadCount - 1)
            itemsPerThread += modulo; // last one is going to handle N + modulo items

        consumers[i] = new Consumer(itemsPerThread);
    }

    new Producer().start();

    // starting worker threads
    for (int i = 0; i < threadCount; i++) {
        consumers[i].start();
    }

    // initialization of the values
    boolean terminate = false;
    latency = 0;
    epoch = total = keyCount = 0;

    int interval = session.getProgressInterval();
    int epochIntervals = session.getProgressInterval() * 10;
    long testStartTime = System.currentTimeMillis();

    while (!terminate) {
        Thread.sleep(100);

        int alive = 0;
        for (Thread thread : consumers)
            if (thread.isAlive())
                alive++;

        if (alive == 0)
            terminate = true;

        epoch++;

        if (terminate || epoch > epochIntervals) {
            epoch = 0;

            oldTotal = total;
            oldLatency = latency;
            oldKeyCount = keyCount;

            total = session.operations.get();
            keyCount = session.keys.get();
            latency = session.latency.get();

            int opDelta = total - oldTotal;
            int keyDelta = keyCount - oldKeyCount;
            double latencyDelta = latency - oldLatency;

            long currentTimeInSeconds = (System.currentTimeMillis() - testStartTime) / 1000;
            String formattedDelta = (opDelta > 0) ? Double.toString(latencyDelta / (opDelta * 1000)) : "NaN";

            out.println(String.format("%d,%d,%d,%s,%d", total, opDelta / interval, keyDelta / interval,
                    formattedDelta, currentTimeInSeconds));
        }
    }
}

From source file:AnotherBeerServer.java

public static void main(String args[]) throws Exception {
    ServerSocket ssock = new ServerSocket(1234);
    System.out.println("Listening");
    Socket sock = ssock.accept();
    ssock.close(); // no more connects

    PrintStream ps = new PrintStream(sock.getOutputStream());

    // ask for count
    ps.print("count? ");
    BufferedReader input = new BufferedReader(new InputStreamReader(sock.getInputStream()));

    // read and parse it
    String line = input.readLine();
    ps.println("");
    int count = Integer.parseInt(line);
    for (int i = count; i >= 0; i--) {
        ps.println(i + " Java Source and Support.");
    }/* w  w w  .j a va2  s  . c o  m*/
    ps.close();
    sock.close();
}

From source file:master.utilities.PopulationFunctionFromJSON.java

/**
 * Main method for debugging.// w  ww .j a v a2s  .c  om
 * 
 * @param args 
 * @throws java.lang.Exception 
 */
public static void main(String[] args) throws Exception {

    PopulationFunctionFromJSON instance = new PopulationFunctionFromJSON();
    instance.initByName("fileName", "/home/tim/work/articles/volzpaper/SimulatedData/SIR_1000sims.json",
            "popSizeExpression", "(I-1)/(2*0.00075*S)", "origin", new RealParameter("66.5499977474"), "trajNum",
            1, "popSizeStart", 0.0, "popSizeEnd", 0.0);

    // Write pop sizes and intensities out
    PrintStream outf = new PrintStream("test.txt");
    outf.println("t N intensity invIntensity");
    double dt = 66.5499977474 / 1000;
    for (int i = 0; i <= 1000; i++) {
        double t = dt * i;
        double N = instance.getPopSize(t);
        double intensity = instance.getIntensity(t);
        double invIntensity = instance.getInverseIntensity(intensity);

        outf.format("%g %g %g %g\n", t, N, intensity, invIntensity);
    }
    outf.println();

}