Example usage for java.io PrintStream close

List of usage examples for java.io PrintStream close

Introduction

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

Prototype

public void close() 

Source Link

Document

Closes the stream.

Usage

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

@Test
public void testLogError() throws Exception {
    PrintStream out = new PrintStream(new Slf4jLoggingOutputStream(LogLevel.ERROR));
    out.println(TEXT);//  w w  w . j av  a  2s. c  o m
    out.flush();
    out.close();
}

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

@Test
public void testLogFatal() throws Exception {
    PrintStream out = new PrintStream(new Slf4jLoggingOutputStream(LogLevel.FATAL));
    out.println(TEXT);/* w ww . j a  v  a 2s .co  m*/
    out.flush();
    out.close();
}

From source file:com.redhat.rhn.manager.satellite.ConfigureCertificateCommand.java

protected void writeStringToFile() throws FileNotFoundException {
    String tmpDir = System.getProperty("java.io.tmpdir");

    this.certificateFileName = tmpDir + "/cert_text" + RandomStringUtils.randomAlphanumeric(13) + ".cert";

    FileOutputStream out = new FileOutputStream(this.certificateFileName);
    PrintStream printer = new PrintStream(out);
    try {//  w  w w.j  a v  a 2s.  c o m
        printer.println(this.certificateText);
    } finally {
        printer.close();
    }
}

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

@Override
public void doWork(Connection conn) {
    // TODO Auto-generated method stub
    try {//from ww  w. ja va2s .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());
    }
}

From source file:edu.oregonstate.eecs.mcplan.experiments.PolicyComparison.java

@Override
public void setup(final Environment env, final P params, final I world) {
    env_ = env;/*  w  w  w  .  ja va  2s  . c  o m*/
    params_ = params;
    world_ = world;

    final Environment pi_env = new Environment.Builder().root_directory(new File(env_.root_directory, "a0"))
            .rng(new MersenneTwister(env_.rng.nextLong())).finish();
    pi_env.root_directory.mkdir();
    pi_ = pi_factory_.create(pi_env, params, world);
    final Environment phi_env = new Environment.Builder().root_directory(new File(env_.root_directory, "a1"))
            .rng(new MersenneTwister(env_.rng.nextLong())).finish();
    phi_env.root_directory.mkdir();
    phi_ = phi_factory_.create(phi_env, params, world);

    end_state = new EndScoreRecorder<A>();
    timer = new ExecutionTimer<S, A>(Player.values().length);

    try {
        final PrintStream pout = new PrintStream(new File(env.root_directory, "parameters.csv"));
        params_.writeCsv(pout);
        pout.close();

        final PrintStream iout = new PrintStream(new File(env.root_directory, "instance.csv"));
        world_.writeCsv(iout);
        iout.close();
    } catch (final FileNotFoundException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.izforge.izpack.compiler.packager.impl.AbstractPackagerTest.java

/**
 * Helper to create a temporary text file containing the specified text.
 *
 * @param text the text// w  w w.  j av a  2 s.co  m
 * @return the new file
 * @throws IOException for any I/O error
 */
private File createTextFile(String text) throws IOException {
    File file = File.createTempFile("data", ".txt");
    PrintStream printStream = new PrintStream(file);
    printStream.print(text);
    printStream.close();
    return file;
}

From source file:edu.msu.cme.rdp.readseq.utils.ResampleSeqFile.java

public static void selectOne(File infile, int num_of_seqs, int subregion_length, File outfile)
        throws IOException {

    IndexedSeqReader reader = new IndexedSeqReader(infile);
    PrintStream out = new PrintStream(new FileOutputStream(outfile));
    Object[] seqIdSet = reader.getSeqIdSet().toArray();
    HashSet<Integer> selectedIndexSet = randomSelectIndices(seqIdSet, num_of_seqs);
    // get the  seq
    Sequence seq;//w  w  w. j av a2 s .  c o m
    if (subregion_length == 0) {
        for (int index : selectedIndexSet) {
            seq = reader.readSeq((String) seqIdSet[index]);
            out.println(">" + seqIdSet[index] + "\t" + seq.getDesc() + "\n" + seq.getSeqString());
        }
    } else {
        for (int index : selectedIndexSet) {
            seq = reader.readSeq((String) seqIdSet[index]);
            if (seq.getSeqString().length() >= subregion_length) {
                int rdmIndex = (int) (Math
                        .floor(Math.random() * (seq.getSeqString().length() - subregion_length)));
                out.println(">" + seqIdSet[index] + "\t" + seq.getDesc() + "\n"
                        + seq.getSeqString().substring(rdmIndex, (rdmIndex + subregion_length)));
            }
        }
    }

    reader.close();
    out.close();
}

From source file:com.bc.fiduceo.matchup.MatchupToolIntegrationTest.java

private String callMatchupToolMain_wrappedWithSystemErrSpy(String[] args)
        throws ParseException, IOException, SQLException, InvalidRangeException {
    final PrintStream err = System.err;
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final PrintStream printStream = new PrintStream(out);

    try {//from   ww w.  jav  a2s. c  o  m
        System.setErr(printStream);

        MatchupToolMain.main(args);
    } finally {
        System.setErr(err);
    }
    printStream.close();
    return out.toString();
}

From source file:com.sap.prd.mobile.ios.mios.ForkerTest.java

@Test(expected = IllegalArgumentException.class)
public void testMissingArguments_2() throws Exception {

    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final PrintStream log = new PrintStream(out, true);

    try {/*w ww .j  a  v  a 2 s  .  co m*/

        Forker.forkProcess(log, new File(".").getAbsoluteFile(), new String[0]);

    } finally {
        log.close();
    }
}

From source file:com.sap.prd.mobile.ios.mios.ForkerTest.java

@Test(expected = IllegalArgumentException.class)
public void testMissingArguments_1() throws Exception {

    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final PrintStream log = new PrintStream(out, true);

    try {//from   w w  w .  jav  a  2 s .  co  m

        Forker.forkProcess(log, new File(".").getAbsoluteFile(), (String[]) null);

    } finally {
        log.close();
    }

}