PrintStream close - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for PrintStream close method.

This code example shows how to use the following methods:close, println
This code example shows how to use the following methods:close, println
 
  @Before 
  public void setUp() throws Exception {
    String passwordFilename = "testpasswd";
    passwd = new File(passwordFilename);
    PrintStream ps = new PrintStream(new FileOutputStream(passwd));
    ps.println("uncle:bob");
    ps.println("micah:boy");
    ps.close();
    a = new MultiUserAuthenticator(passwordFilename);
  } 
 
  @After 
  public void tearDown() throws Exception {
    passwd.delete();
  } 
 
  @Test
  public void testBuildAuthenticator() throws Exception {
    assertEquals(2, a.userCount());
7
CodeRank
This code example shows how to use the following methods:close
    return hasErrors;
  } 
 
  private void initBeeLine() throws Exception {
    beeLine = new BeeLine();
    beelineOutputStream = new PrintStream(new File(outputDirectory, qFileName + ".beeline"));
    beeLine.setOutputStream(beelineOutputStream);
    beeLine.setErrorStream(beelineOutputStream);
    beeLine.runCommands(new String[] {
        "!set verbose true", 
        "!set shownestederrs true", 
        "!set showwarnings true", 
        "!set showelapsedtime false", 
        "!set maxwidth -1", 
        "!connect " + jdbcUrl + " " + username + " " + password + " " + jdbcDriver,
    }); 
  } 
 
  private void setUp() { 
    beeLine.runCommands(new String[] {

7
CodeRank
This code example shows how to use the following methods:close
    public void testGo() { 
        Weld w = new Weld();
        WeldContainer wc = w.initialize();
 
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(baos);
 
        CDIInstanceExample bean = wc.instance().select(CDIInstanceExample.class).get();
        bean.go(ps);
 
        ps.close();
 
        String actual = new String(baos.toByteArray());
        String expected = "" +
                          "Dave: Hello, HAL. Do you read me, HAL?" + NL +
                          "HAL: Dave. I read you." + NL;
        assertEquals(expected, actual);
 
        w.shutdown();
    } 
7
CodeRank
This code example shows how to use the following methods:close, print
  private File writeTestLog(String id, String content) throws IOException {
    // Put the script content in a temp file 
    File scriptFile = File.createTempFile(getClass().getName() + "-" + id + "-", ".log");
    scriptFile.deleteOnExit();
    toBeDeletedList.add(scriptFile);
    PrintStream os = new PrintStream(new FileOutputStream(scriptFile));
    try { 
      os.print(content);
    } finally { 
      os.close();
    } 
    return scriptFile;
  } 
   
  private String toString(Throwable t) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw, false); 
    t.printStackTrace(pw);
    pw.close();
    return sw.toString();
6
CodeRank
This code example shows how to use the following methods:close, println
		try { 
			fileOut = new FileOutputStream("build.properties", true);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} 
		ps = new PrintStream(fileOut);
 
		ps.println("buildnumber=" + BUILD_NUM);
		ps.println("tag=" + getTag());
		ps.println("versionnumber=" + V_NUM);
		ps.println("milestone=" + MILESTONE);
		ps.println("productversion=" + VERSION);
 
		ps.close();
	} 
 
	@Override 
	public String getTag() {
		DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);
		String date = dateFormat.format(new Date());
7
CodeRank
This code example shows how to use the following methods:close
   
  /** Output directory structure to a file, each line of the file 
   * contains the directory name. Only empty directory names are printed. */ 
  private void output(File outFile) throws FileNotFoundException {
    System.out.println("Printing to " + outFile.toString());
    PrintStream out = new PrintStream(outFile);
    root.output(out, null);
    out.close();
  } 
   
  /** Output all files' attributes to a file, each line of the output file 
   * contains a file name and its length. */ 
  private void outputFiles(File outFile) throws FileNotFoundException {
    System.out.println("Printing to " + outFile.toString());
    PrintStream out = new PrintStream(outFile);
    root.outputFiles(out, null);
    out.close();
  } 
   
  /** 
6
CodeRank
This code example shows how to use the following methods:close
 
    @Test 
    @Ignore 
    public void testGo() { 
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(baos);
        new KieModuleModelExample().go(ps);
        ps.close();
 
        String actual = new String(baos.toByteArray());
        String expected = "" +
                          "Dave: Hello, HAL. Do you read me, HAL?\n" + 
                          "HAL: Dave. I read you.\n" + 
                          "Dave: Open the pod bay doors, HAL.\n" + 
                          "HAL: I'm sorry, Dave. I'm afraid I can't do that.\n" + 
                          "Dave: What's the problem?\n" + 
                          "HAL: I think you know what the problem is just as well as I do.\n"; 
        assertEquals(expected, actual);
    } 
} 
8
CodeRank
This code example shows how to use the following methods:close, print
 
        if (sOutputFile == null) {
            System.out.println(json);
        } else { 
            try { 
                PrintStream stream = new PrintStream(new FileOutputStream(sOutputFile, true));
                try { 
                    stream.print(json);
                } finally { 
                    try { 
                        stream.close();
                    } catch (Exception ex) {
                        Log.e("PerfTraceEvent", "Unable to close perf trace output file.");
                    } 
                } 
            } catch (FileNotFoundException ex) {
                Log.e("PerfTraceEvent", "Unable to dump perf trace data to output file.");
            } 
        } 
    } 
6
CodeRank
This code example shows how to use the following methods:close, println
    PrintStream out = null;
    FileOutputStream fileOutputStream = null;
 
    try { 
      fileOutputStream = new FileOutputStream(f);
      out = new PrintStream(fileOutputStream);
      out.println("<script language=\"JavaScript\">\n" +
          "    location = \"" + url + "\"\n" +
          "</script>\n"); 
    } catch (FileNotFoundException e) {
      throw new RuntimeException("troublemaking redirection HTML: " + e);
    } finally { 
      if (null != out) {
        out.close();
      } 
      if (null != fileOutputStream) {
        try { 
          fileOutputStream.close();
        } catch (IOException e) {
          log.log(Level.WARNING, "Ignoring exception while closing HTML redirection stream", e);
7
CodeRank

Related PrintStream close Questions & Answers:

close Method Overview
Closes the stream.
See Code Examples for other Java 8 PrintStream Methods: