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:com.excilys.ebi.utils.spring.log.logback.LogbackConfigurerTestExecutionListenerTest.java

/**
 * The logback-test.xml defines a Console output. Console output is
 * temporarily trapped so that we can check what is written.
 *//*from w w  w.j  ava  2 s  . c  o m*/
@Test
public void testConsoleLogger() {

    PrintStream stdout = System.out;
    String log = null;

    try {
        // replace console standard output
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(os);
        System.setOut(ps);

        logger.debug("something in DEBUG");

        log = os.toString();

    } finally {
        // restore console standard output
        System.setOut(stdout);
    }

    Assert.assertTrue("Output log is incorrect", log.contains(
            "DEBUG c.e.e.u.s.l.l.LogbackConfigurerTestExecutionListenerTest.testConsoleLogger - something in DEBUG"));
}

From source file:com.example.DatastoreSampleApplicationTests.java

@BeforeClass
public static void checkToRun() {
    assumeThat(System.getProperty("it.datastore")).as("Datastore sample integration tests are disabled. "
            + "Please use '-Dit.datastore=true' to enable them.").isEqualTo("true");
    systemOut = System.out;//www  .j  av  a 2s  .c o m
    baos = new ByteArrayOutputStream();
    TeeOutputStream out = new TeeOutputStream(systemOut, baos);
    System.setOut(new PrintStream(out));
}

From source file:com.azaptree.services.spring.application.SpringApplicationService.java

private static void logDebugSystemProperties(final Logger log) {
    Assert.notNull(log);/*from ww  w.  j a v a  2  s  .  co  m*/
    if (log.isDebugEnabled()) {
        final TreeMap<String, String> sysProps = new TreeMap<>();
        for (final Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
            sysProps.put(entry.getKey().toString(), entry.getValue().toString());
        }
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
        final PrintStream ps = new PrintStream(bos);
        for (final Map.Entry<String, String> entry : sysProps.entrySet()) {
            ps.print(entry.getKey());
            ps.print('=');
            ps.println(entry.getValue());
        }
        log.debug("System Properties:\n{}", bos);
    }
}

From source file:com.ccg.main.Telnet.java

public void TelnetMain(String username, String password, String hosts, ArrayList<String> commandsList) {
    try {/*from   w ww.  jav  a 2s  .c  o  m*/
        this.hosts = hosts;
        System.out.println("Status: " + hosts + "\t" + "Starting\t");
        // Connect to the specified server
        tc.connect(hosts, 23);
        tc.setKeepAlive(true);

        // Get input and output stream references
        file = new File(hosts + "-" + ft.format(date) + ".log");
        fos = new FileOutputStream(file, true);
        ps = new PrintStream(fos);
        in = tc.getInputStream();
        out = new PrintStream(tc.getOutputStream());

        // Log the user on
        readUntil("Username: ");
        write(username);
        readUntil("Password: ");
        write(password);
        // Advance to a prompt
        if (discoverHost == false) {
            readUntil(prompt);
            this.discoverHost = true;
            write(" ");
        }
        //readUntil(hostname);
        System.out.println("Status: " + hosts + "\t" + "Running\t");
        for (int i = 0; i < commandsList.size(); i++) {
            if (commandsList.get(i).toLowerCase().contains("exit")) {
                disconnect();
            } else {
                sendCommand(commandsList.get(i));
                sendCommand(" ");
            }
        }
        while (in.read() != -1) {
            //Thread.sleep(100);
            readUntil(hostname);
        }
        if (tc.isConnected() == false) {

        } else {
            disconnect();
        }
    } catch (Exception e) {
        if (e.toString().contains("Login invalid")) {
            System.out.println("Status: " + hosts + "\t" + "Login invalid\t");
        } else {
            e.printStackTrace();
        }
        disconnect();
    }
}

From source file:edu.rice.cs.bioinfo.programs.phylonet.PhyloNetAAT.java

private static void checkTest(String nexus, String expectedStdOut, String expectedStdError, String testFile)
        throws IOException {
    String faultMessage = testFile + " failed.";
    ByteArrayOutputStream display = new ByteArrayOutputStream();
    ByteArrayOutputStream error = new ByteArrayOutputStream();
    Program.run(new ByteArrayInputStream(nexus.getBytes()), new PrintStream(error), new PrintStream(display),
            _rand, BigDecimal.ZERO);
    Assert.assertEquals(faultMessage, expectedStdError, error.toString().replace("\r", ""));
    Assert.assertEquals(faultMessage, expectedStdOut, display.toString().replace("\r", ""));
}

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

@Test
public void writeToStdoutWithPrefix() 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 . j av  a 2 s  . c o m
        PacifyViaCommandline pacifyViaCommandline = new PacifyViaCommandline();

        result = pacifyViaCommandline.mainInternal(
                new String[] { "showUsedProperties", "--packagePath=" + packagePath, "--outputPrefix=###" });
    } finally {
        System.setOut(oldStdOut);
    }

    outContent.close();

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

From source file:flow.visibility.tapping.OpenDayLightUtils.java

/** Creating the Pane for Flow Entry */

public OpenDayLightUtils() {
    super("Installed Flow");

    FlowtextArea = new JTextArea(50, 10);
    FlowtextArea.setEditable(false);/*from ww  w.j  a  v a  2s .c o  m*/
    FlowtextArea.setFont(new Font("Courier New", Font.BOLD, 12));
    PrintStream FlowprintStream = new PrintStream(new CustomOutputStream(FlowtextArea));

    // re-assigns standard output stream and error output stream
    System.setOut(FlowprintStream);
    System.setErr(FlowprintStream);

    // creates the GUI
    setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.insets = new Insets(10, 10, 10, 10);
    constraints.anchor = GridBagConstraints.WEST;
    constraints.gridx = 0;
    constraints.gridy = 1;
    constraints.gridwidth = 2;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.weightx = 1.0;
    constraints.weighty = 1.0;

    /** Adding the Pane into Frame */

    scrollPane = new JScrollPane(FlowtextArea);
    this.add(scrollPane, constraints);

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setSize(400, 600);
    setLocationRelativeTo(null); // centers on screen
}

From source file:de.langmi.spring.batch.tutorials.helloworld.HelloWorldJobConfigurationManualTest.java

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

From source file:io.redlink.solrlib.standalone.test.StandaloneSolrServer.java

@Override
protected void before() throws Throwable {
    super.before();

    if (Objects.isNull(solrHome)) {
        solrHome = Files.createTempDirectory("testSolr");
    } else {//from   w w  w .j a  v  a2  s  .c o m
        Files.createDirectories(solrHome);
        deleteSolrHome = false;
    }
    try (PrintStream solrXml = new PrintStream(Files.newOutputStream(solrHome.resolve("solr.xml")))) {
        solrXml.println("<solr></solr>");
    }

    jetty = new JettySolrRunner(solrHome.toAbsolutePath().toString(), jettyConfig);
    jetty.start();
    logger.warn("Started StandaloneSolrServer {}", getBaseUrl());
}

From source file:gaffer.accumulo.utils.IngestUtils.java

/**
 * Given some split points, write a Base64 encoded splits file.
 * /*from   w ww .j  a  v a2 s  . c  o  m*/
 * @param splits  The split points
 * @param fs  The FileSystem in which to create the splits file
 * @param splitsFile  The location of the output splits file
 * @throws IOException
 */
public static void writeSplitsFile(Collection<Text> splits, FileSystem fs, Path splitsFile) throws IOException {
    PrintStream out = null;
    try {
        out = new PrintStream(new BufferedOutputStream(fs.create(splitsFile, true)));
        for (Text split : splits) {
            out.println(new String(Base64.encodeBase64(split.getBytes())));
        }
    } finally {
        IOUtils.closeStream(out);
    }
}