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.creactiviti.piper.plugin.ffmpeg.Ffmpeg.java

@Override
public Object handle(Task aTask) throws Exception {
    List<String> options = aTask.getList("options", String.class);
    CommandLine cmd = new CommandLine("ffmpeg");
    options.forEach(o -> cmd.addArgument(o));
    log.debug("{}", cmd);
    DefaultExecutor exec = new DefaultExecutor();
    File tempFile = File.createTempFile("log", null);
    try (PrintStream stream = new PrintStream(tempFile);) {
        exec.setStreamHandler(new PumpStreamHandler(stream));
        int exitValue = exec.execute(cmd);
        return exitValue != 0 ? FileUtils.readFileToString(tempFile) : cmd.toString();
    } catch (ExecuteException e) {
        throw new ExecuteException(e.getMessage(), e.getExitValue(),
                new RuntimeException(FileUtils.readFileToString(tempFile)));
    } finally {//  w w  w  .  j  a  v a  2  s.  co  m
        FileUtils.deleteQuietly(tempFile);
    }
}

From source file:com.datatorrent.contrib.schema.parser.JsonParserTest.java

public JsonParserTest() {
    // So that the output is cleaner.
    System.setErr(new PrintStream(myOut));
}

From source file:au.com.jwatmuff.eventmanager.export.CSVExporter.java

public static void generatePlayerList(Database database, OutputStream out) {
    Collection<Player> players = database.findAll(Player.class, PlayerDAO.ALL);
    PrintStream ps = new PrintStream(out);

    Object[] columns = new Object[] { "id", "First Name", "Last Name", "Sex", "Grade", "DOB", "Team",
            "Home Number", "Work Number", "Mobile Number", "Street", "City", "Postcode", "State", "Email",
            "Emergency Name", "Emergency Phone", "Emergency Mobile", "Medical Conditions", "Medical Info",
            "Injury Info" };

    outputRow(columns, ps);//  w ww .  ja  va 2 s. c  o  m

    for (Player player : players) {
        Object[] fields1 = new Object[] { player.getVisibleID(), player.getFirstName(), player.getLastName(),
                player.getGender(), player.getGrade(), dateFormat.format(player.getDob()), player.getTeam() };

        PlayerDetails details = database.get(PlayerDetails.class, player.getDetailsID());
        Object[] fields2;
        if (details != null) {
            fields2 = new Object[] { details.getHomeNumber(), details.getWorkNumber(),
                    details.getMobileNumber(), details.getStreet(), details.getCity(), details.getPostcode(),
                    details.getState(), details.getEmail(), details.getEmergencyName(),
                    details.getEmergencyPhone(), details.getEmergencyMobile(), details.getMedicalConditions(),
                    details.getMedicalInfo(), details.getInjuryInfo() };
        } else {
            fields2 = new Object[14];
            Arrays.fill(fields2, null);
        }

        outputRow(ArrayUtils.addAll(fields1, fields2), ps);
    }
}

From source file:com.starit.diamond.server.service.task.DumpConfigInfoTask.java

/**
 * @param timerTaskService//from  w ww  .  j  a v  a2  s .com
 */
public DumpConfigInfoTask(TimerTaskService timerTaskService, List<ConfigInfo> configInfos) {
    this.timerTaskService = timerTaskService;
    this.configInfos = configInfos;
    try {
        err = new PrintStream(new FileOutputStream("DumpConfigInfoTask.Error.txt"));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.datatorrent.contrib.schema.formatter.JsonFormatterTest.java

public JsonFormatterTest() {
    // So that the output is cleaner.
    System.setErr(new PrintStream(myOut));
}

From source file:com.meetingninja.csse.database.GroupDatabaseAdapter.java

public static Group createGroup(Group g) throws IOException, MalformedURLException {
    // Server URL setup
    String _url = getBaseUri().build().toString();

    // establish connection
    URL url = new URL(_url);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();

    conn.setRequestMethod("POST");
    addRequestHeader(conn, true);/*ww w . j a  v a 2  s.co  m*/

    // prepare POST payload
    ByteArrayOutputStream json = new ByteArrayOutputStream();
    // this type of print stream allows us to get a string easily
    PrintStream ps = new PrintStream(json);
    // Create a generator to build the JSON string
    JsonGenerator jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8);

    // Build JSON Object
    jgen.writeStartObject();
    jgen.writeStringField(Keys.Group.TITLE, g.getGroupTitle());
    jgen.writeArrayFieldStart(Keys.Group.MEMBERS);
    for (User member : g.getMembers()) {
        jgen.writeStartObject();
        jgen.writeStringField(Keys.User.ID, member.getID());
        jgen.writeEndObject();

    }
    jgen.writeEndArray();
    jgen.writeEndObject();
    jgen.close();

    // Get JSON Object payload from print stream
    String payload = json.toString("UTF8");
    ps.close();

    // send payload
    int responseCode = sendPostPayload(conn, payload);
    String response = getServerResponse(conn);

    // prepare to get the id of the created Meeting
    // Map<String, String> responseMap = new HashMap<String, String>();

    /*
     * result should get valid={"meetingID":"##"}
     */
    String result = new String();
    if (!response.isEmpty()) {
        // responseMap = MAPPER.readValue(response,
        // new TypeReference<HashMap<String, String>>() {
        // });
        JsonNode groupNode = MAPPER.readTree(response);
        if (!groupNode.has(Keys.Group.ID)) {
            result = "invalid";
        } else
            result = groupNode.get(Keys.Group.ID).asText();
    }

    if (!result.equalsIgnoreCase("invalid"))
        g.setID(result);

    conn.disconnect();
    return g;
}

From source file:com.adaptris.util.stream.Slf4jLoggingOutputStreamTest.java

@Test
public void testLogInfo() throws Exception {
    PrintStream out = new PrintStream(new Slf4jLoggingOutputStream(LogLevel.INFO));
    out.println(TEXT);/*from   w  w  w . ja v a 2 s .c o  m*/
    out.flush();
    out.close();
}

From source file:brooklyn.util.stream.ThreadLocalPrintStream.java

/** sets the PrintStream that callers from this thread should see;
 * returns any previously custom PrintStream for this thread */
public PrintStream setThreadLocalPrintStream(OutputStream stream) {
    PrintStream old = customStream.get();
    if (!(stream instanceof PrintStream))
        stream = new PrintStream(stream);
    customStream.set((PrintStream) stream);
    return old;//from  w  ww. j av  a 2  s .  c o m
}

From source file:de.tudarmstadt.ukp.dkpro.core.io.text.TextWriterTest.java

@Test
public void testStdOut() throws Exception {
    final String text = "This is a test";

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    PrintStream originalOut = System.out;
    try {//from w  w  w  . jav  a 2s  . c om
        System.setOut(new PrintStream(baos));

        JCas jcas = JCasFactory.createJCas();
        jcas.setDocumentText(text);

        AnalysisEngineDescription writer = createEngineDescription(TextWriter.class);
        runPipeline(jcas, writer);

        System.out.close();
    } finally {
        System.setOut(originalOut);
    }

    assertEquals(text, baos.toString("UTF-8"));
}

From source file:edu.dfci.cccb.mev.stats.domain.cli.CliRFisherBuilder.java

@Override
public Fisher build() throws DatasetException {
    try (TemporaryFile fisher = new TemporaryFile();
            ByteArrayOutputStream script = new ByteArrayOutputStream();
            PrintStream s = new PrintStream(script)) {

        s.println("M=" + m());
        s.println("N=" + n());
        s.println("S=" + s());
        s.println("T=" + t());
        s.println("ALT_HYPOTHESIS=\"" + hypothesis() + "\"");
        s.println("IS_SIMULATED=" + valueOf(simulate()).toString().toUpperCase());
        s.println("FISHER_OUT=\"" + fisher.getAbsolutePath() + "\"");

        copy(getClass().getResourceAsStream("/fisher.r"), s);

        r.eval(script.toString());/*from  w w w.j a v  a2  s. c  o  m*/

        try (BufferedReader reader = new BufferedReader(new FileReader(fisher))) {
            reader.readLine();
            final double oddRatio = Double.parseDouble(reader.readLine().split("\t")[1]);
            final double pValue = Double.parseDouble(reader.readLine().split("\t")[1]);

            return new PojoFisher(oddRatio, pValue).name(this.name()).type(type());
        }
    } catch (IOException | ScriptException e) {
        throw new DatasetException(e);
    }
}