Example usage for java.io PrintStream PrintStream

List of usage examples for java.io PrintStream PrintStream

Introduction

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

Prototype

public PrintStream(File file) throws FileNotFoundException 

Source Link

Document

Creates a new print stream, without automatic line flushing, with the specified file.

Usage

From source file:fi.jumi.core.stdout.SystemOutErrTest.java

@Test
public void sets_the_real_stdout() {
    PrintStream newStream = new PrintStream(new NullOutputStream());

    systemOutErr.setOut(newStream);/*from  ww  w . ja  va  2 s .c o m*/

    assertThat(System.out, is(newStream));
}

From source file:alluxio.cli.fs.command.ChownCommandTest.java

@Before
public void setupStreams() {
    System.setOut(new PrintStream(mOutput));
    System.setErr(new PrintStream(mError));
}

From source file:com.github.odiszapc.casskit.repair.ProbeRunner.java

@Override
public void execute() throws Exception {
    NodeProbe probe = new NodeProbe(opt(HOST), opt(JMX_PORT));
    PrintStream devNull = new PrintStream(NULL_OUTPUT_STREAM);
    probe.forceRepairRangeAsync(devNull, opt(KEYSPACE), opt(SEQ), opt(LOCAL), opt(TOKEN_FROM), opt(TOKEN_TO),
            opt(COLUMN_FAMILY));// w ww  . ja v a2s. co  m
}

From source file:org.timer4method.test.Timer4MethodTest.java

@Before
public void setUpStreams() {
    System.setOut(new PrintStream(outContent));
}

From source file:Main.java

/**
 * Sends Gps data to emulator, and the start value has an offset.
 * //w  w w  . j a  v a 2 s.  c  o m
 * @param number send times
 * @param offset is used to compute the start latitude and longitude
 * @param pause pause interval between each sending
 */
public static void sendGps(int number, int offset, int pause) {
    if (number < 1) {
        return;
    }

    int pauseInterval = TINY_WAIT_TIME;
    if (pause != -1) {
        pauseInterval = pause;
    }

    // If it's a real device, does not send simulated GPS signal.
    if (!isEmulator) {
        return;
    }

    PrintStream out = null;
    Socket socket = null;
    try {
        socket = new Socket(ANDROID_LOCAL_IP, emulatorPort);
        out = new PrintStream(socket.getOutputStream());
        double longitude = START_LONGITUDE + offset * DELTA_LONGITUDE;
        double latitude = START_LATITUDE + offset * DELTA_LADITUDE;
        for (int i = 0; i < number; i++) {
            out.println("geo fix " + longitude + " " + latitude);
            longitude += DELTA_LONGITUDE;
            latitude += DELTA_LADITUDE;
            Thread.sleep(pauseInterval);
        }
        // Wait the GPS signal can be obtained by MyTracks.
        Thread.sleep(SHORT_WAIT_TIME);
    } catch (UnknownHostException e) {
        System.exit(-1);
    } catch (IOException e) {
        System.exit(-1);
    } catch (InterruptedException e) {
        System.exit(-1);
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

From source file:com.example.PollingReceiverTest.java

@BeforeClass
public static void prepare() {
    assumeThat("PUB/SUB-sample integration tests are disabled. Please use '-Dit.pubsub=true' "
            + "to enable them. ", System.getProperty("it.pubsub"), is("true"));

    systemOut = System.out;/*w  ww. j a va 2 s  .  c om*/
    baos = new ByteArrayOutputStream();
    TeeOutputStream out = new TeeOutputStream(systemOut, baos);
    System.setOut(new PrintStream(out));
}

From source file:com.cyberway.issue.util.SurtPrefixSet.java

/**
 * Allow class to be used as a command-line tool for converting 
 * URL lists (or naked host or host/path fragments implied
 * to be HTTP URLs) to implied SURT prefix form. 
 * /*from   w  ww.java  2s  .c o  m*/
 * Read from stdin or first file argument. Writes to stdout. 
 *
 * @param args cmd-line arguments: may include input file
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    InputStream in = args.length > 0 ? new BufferedInputStream(new FileInputStream(args[0])) : System.in;
    PrintStream out = args.length > 1 ? new PrintStream(new BufferedOutputStream(new FileOutputStream(args[1])))
            : System.out;
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String line;
    while ((line = br.readLine()) != null) {
        if (line.indexOf("#") > 0)
            line = line.substring(0, line.indexOf("#"));
        line = line.trim();
        if (line.length() == 0)
            continue;
        out.println(prefixFromPlain(line));
    }
    br.close();
    out.close();
}

From source file:Main.java

private static List<Integer> getAllRelatedPids(final int pid) {
    List<Integer> result = new ArrayList<Integer>(Arrays.asList(pid));
    // use 'ps' to get this pid and all pids that are related to it (e.g.
    // spawned by it)
    try {/*w  w w  .  jav a  2  s.  c o m*/

        final Process suProcess = Runtime.getRuntime().exec("su");

        new Thread(new Runnable() {

            @Override
            public void run() {
                PrintStream outputStream = null;
                try {
                    outputStream = new PrintStream(new BufferedOutputStream(suProcess.getOutputStream(), 8192));
                    outputStream.println("ps");
                    outputStream.println("exit");
                    outputStream.flush();
                } finally {
                    if (outputStream != null) {
                        outputStream.close();
                    }
                }

            }
        }).run();

        if (suProcess != null) {
            try {
                suProcess.waitFor();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        BufferedReader bufferedReader = null;
        try {
            bufferedReader = new BufferedReader(new InputStreamReader(suProcess.getInputStream()), 8192);
            while (bufferedReader.ready()) {
                String[] line = SPACES_PATTERN.split(bufferedReader.readLine());
                if (line.length >= 3) {
                    try {
                        if (pid == Integer.parseInt(line[2])) {
                            result.add(Integer.parseInt(line[1]));
                        }
                    } catch (NumberFormatException ignore) {
                    }
                }
            }
        } finally {
            if (bufferedReader != null) {
                bufferedReader.close();
            }
        }
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    return result;
}

From source file:app.common.X3DViewer.java

/**
 * View an X3D file using an external X3DOM player
 *
 * @param grid/*from w w w  .ja v a2s.  c o  m*/
 * @param smoothSteps
 * @param maxDecimateError
 * @throws IOException
 */
public static void viewX3DOM(Grid grid, int smoothSteps, double maxDecimateError) throws IOException {
    // TODO: Make thread safe using tempDir
    String dest = "/tmp/ringpopper/";
    File dir = new File(dest);
    dir.mkdirs();

    String pf = "x3dom/x3dom.css";
    String dest_pf = dest + pf;
    File dest_file = new File(dest_pf);
    File src_file = new File("src/html/" + pf);
    if (!dest_file.exists()) {
        System.out.println("Copying file: " + src_file + " to dir: " + dest);
        FileUtils.copyFile(src_file, dest_file, true);
    }

    pf = "x3dom/x3dom.js";
    dest_pf = dest + pf;
    dest_file = new File(dest_pf);
    src_file = new File("src/html/" + pf);
    if (!dest_file.exists()) {
        System.out.println("Copying file: " + src_file + " to dir: " + dest);
        FileUtils.copyFile(src_file, dest_file, true);
    }
    File f = new File("/tmp/ringpopper/out.xhtml");
    FileOutputStream fos = new FileOutputStream(f);
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    PrintStream ps = new PrintStream(bos);

    try {
        ps.println(
                "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
        ps.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
        ps.println("<head>");
        ps.println("<meta http-equiv=\"X-UA-Compatible\" content=\"chrome=1\" />");
        ps.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />");
        ps.println("<title>Ring Popper Demo</title>");
        //            ps.println("<link rel='stylesheet' type='text/css' href='http://www.x3dom.org/x3dom/release/x3dom.css'></link>");
        ps.println("<link rel='stylesheet' type='text/css' href='x3dom/x3dom.css'></link>");
        ps.println("</head>");
        ps.println("<body>");

        ps.println("<p class='case'>");
        GridSaver.writeIsosurfaceMaker(grid, bos, "x3d", smoothSteps, maxDecimateError);

        //            ps.println("<script type='text/javascript' src='http://www.x3dom.org/x3dom/release/x3dom.js'></script>");
        ps.println("<script type='text/javascript' src='x3dom/x3dom.js'></script>");

        ps.println("</p>");
        ps.println("</body></html>");
    } finally {
        bos.flush();
        bos.close();
        fos.close();
    }

    Desktop.getDesktop().browse(f.toURI());
}

From source file:com.ibm.research.rdf.store.cmd.GeneratePredicateMappings.java

@Override
public void doWork(Connection conn) {
    // TODO Auto-generated method stub
    try {//w w  w .j a  v a2  s  .  c om

        PrintStream ps = new PrintStream(new BufferedOutputStream(System.out, 1000000));

        StoreManager.generatePredicateMappings(conn, Backend.valueOf(params.get("-backend")),
                params.get("-schema"), storeName, ps, Context.defaultContext);
        ps.close();

    } catch (RdfStoreException e) {
        log.error(e);
        System.out.println(e.getLocalizedMessage());
    } catch (Exception e) {
        log.error(e);
        System.out.println(e.getLocalizedMessage());
    }
}