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_stderr() {
    PrintStream newStream = new PrintStream(new NullOutputStream());

    systemOutErr.setErr(newStream);// w w  w. j  a  v a 2  s .  c  o  m

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

From source file:net.jns3.core.AutomatedTelnetClient.java

public AutomatedTelnetClient(String server, int port) {
    try {//from  w  ww.  j a  v  a2 s . c  om
        telnet.connect(server, port);
        in = telnet.getInputStream();
        out = new PrintStream(telnet.getOutputStream());
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
}

From source file:net.nicholaswilliams.java.licensing.licensor.interfaces.cli.TestPeriods.java

@Before
public void setUp() {
    this.outputStream = new ByteArrayOutputStream();

    PrintStream printStream = new PrintStream(outputStream);

    this.periods = new Periods(25, printStream);
}

From source file:javancss.ParseDebugTest.java

@Override
protected Javancss measureTestFile(int testFileId) {
    Logger logger = Logger.getLogger("javancss");
    logger.setLevel(Level.FINEST);

    PrintStream stdout = System.out;
    PrintStream stderr = System.err;

    try {//from www . j  av  a 2 s .c  om
        System.setOut(new PrintStream(new NullOutputStream()));
        System.setErr(new PrintStream(new NullOutputStream()));

        return super.measureTestFile(testFileId);
    } finally {
        logger.setLevel(Level.OFF);
        System.setOut(stdout);
        System.setErr(stderr);
    }
}

From source file:ape_test.CLITest.java

/**
 * This test just checks to see if the start of the help dialog is printed
 * Since the help dialog will continue to be updated, it's not worth constantly changing this test
 *//*from   w w  w. ja v a 2  s  .co  m*/
public void testHelpDialog() {
    PrintStream originalOut = System.out;
    OutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);
    System.setOut(ps);

    String[] theArgs = new String[1];
    theArgs[0] = "-h";
    Main.main(theArgs);
    System.setOut(originalOut);
    assertEquals("usage: ape", (os.toString()).substring(0, 10));
}

From source file:com.geewhiz.pacify.commandline.TestShowUsedProperties.java

@Test
public void writeToStdout() throws Exception {

    PrintStream oldStdOut = System.out;

    ByteArrayOutputStream outContent = new ByteArrayOutputStream();
    System.setOut(new PrintStream(outContent));

    File testBasePath = new File("target/test-classes/testShowUsedProperties");
    File packagePath = new File(testBasePath, "package");

    int result = 0;
    try {/*from   ww w.  ja v  a  2  s  .co m*/
        PacifyViaCommandline pacifyViaCommandline = new PacifyViaCommandline();
        result = pacifyViaCommandline
                .mainInternal(new String[] { "showUsedProperties", "--packagePath=" + packagePath });
    } finally {
        System.setOut(oldStdOut);
    }

    outContent.close();

    Assert.assertEquals("ShowUsedProperties should not return an error.", 0, result);
    Assert.assertEquals(FileUtils.readFileToString(new File(testBasePath + "/expectedResult/result.txt")),
            outContent.toString());
}

From source file:Main.java

/**
 * Sends Gps data to emulator, and the start value has an offset.
 * //from w  w  w . j a  va  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 = PAUSE_DEFAULT;
    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:fr.ybonnel.FruitShopTest.java

private void oneTest(int expectedResult, String... articles) {
    InputStream reader = new ReaderInputStream(
            new StringReader(Stream.of(articles).collect(Collectors.joining("\n")) + "\nexit\n"));

    ByteArrayOutputStream stream = new ByteArrayOutputStream();

    new FruitShop().caisse(reader, new PrintStream(stream));

    String result = new String(stream.toByteArray());

    String[] lines = result.split("\\n");

    String lastTotal = lines[lines.length - 2];

    System.out.println(result);/*  w w w .j av  a  2s.  c om*/

    assertEquals(expectedResult, Integer.parseInt(lastTotal));

}

From source file:com.facebook.stetho.dumpapp.RawDumpappHandler.java

@Override
protected HttpEntity getResponseEntity(HttpRequest request, InputStream bufferedInput, HttpResponse response)
        throws IOException {
    ByteArrayOutputStream stdoutBuffer = new ByteArrayOutputStream();

    try {//from w  w  w .j  a  va 2  s .  c o m
        PrintStream stdout = new PrintStream(stdoutBuffer);
        try {
            ByteArrayOutputStream stderrBuffer = new ByteArrayOutputStream();
            PrintStream stderr = new PrintStream(stderrBuffer);

            try {
                int exitCode = getDumper().dump(bufferedInput, stdout, stderr, getArgs(request));
                response.addHeader(RESPONSE_HEADER_EXIT_CODE, String.valueOf(exitCode));
            } finally {
                stderr.close();
                if (stderrBuffer.size() > 0) {
                    System.err.write(stderrBuffer.toByteArray());
                }
            }
        } finally {
            stdout.close();
        }
    } finally {
        bufferedInput.close();
    }

    return createResponseEntity(stdoutBuffer.toByteArray());
}

From source file:au.org.ala.delta.translation.TypeSetterTest.java

@Before
public void setUp() {

    _bytes = new ByteArrayOutputStream();
    PrintStream pout = new PrintStream(_bytes);
    _typeSetter = new PrintFile(pout, _lineWidth);
}