List of usage examples for java.io PrintStream close
public void close()
From source file:CustomSubmitter.java
/** * Submits the specified PBS job to the PBS queue using the {@code qsub} * program./*from w w w.ja v a 2s.co m*/ * * @param job the PBS job to be submitted * @throws IOException if an error occurred while invoking {@code qsub} */ public void submit(PBSJob job) throws IOException { Process process = new ProcessBuilder("qsub").start(); RedirectStream.redirect(process.getInputStream(), System.out); RedirectStream.redirect(process.getErrorStream(), System.err); String script = toPBSScript(job); System.out.println(script); PrintStream ps = new PrintStream(process.getOutputStream()); ps.print(script); ps.close(); try { int exitStatus = process.waitFor(); if (exitStatus != 0) { throw new IOException("qsub terminated with exit status " + exitStatus); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } }
From source file:com.yahoo.storm.yarn.LaunchCommand.java
@Override public void process(CommandLine cl) throws Exception { String config_file = null;/* w w w .j a v a 2 s.c o m*/ List remaining_args = cl.getArgList(); if (remaining_args != null && !remaining_args.isEmpty()) { config_file = (String) remaining_args.get(0); } Map stormConf = Config.readStormConfig(config_file); String appName = cl.getOptionValue("appname", "Storm-on-Yarn"); String queue = cl.getOptionValue("queue", "default"); String storm_zip_location = cl.getOptionValue("stormZip"); Integer amSize = (Integer) stormConf.get(Config.MASTER_SIZE_MB); StormOnYarn storm = null; try { storm = StormOnYarn.launchApplication(appName, queue, amSize, stormConf, storm_zip_location); LOG.debug("Submitted application's ID:" + storm.getAppId()); //download storm.yaml file String storm_yaml_output = cl.getOptionValue("stormConfOutput"); if (storm_yaml_output != null && storm_yaml_output.length() > 0) { //try to download storm.yaml StormMaster.Client client = storm.getClient(); if (client != null) StormMasterCommand.downloadStormYaml(client, storm_yaml_output); else LOG.warn("No storm.yaml is downloaded"); } //store appID to output String output = cl.getOptionValue("output"); if (output == null) System.out.println(storm.getAppId()); else { PrintStream os = new PrintStream(output); os.println(storm.getAppId()); os.flush(); os.close(); } } finally { if (storm != null) { storm.stop(); } } }
From source file:com.jonathan.android.httpcache.HttpRequest.java
public boolean writeFileWithString(String d, File f) { try {/*from w ww. ja v a 2s. com*/ f.createNewFile(); } catch (IOException e1) { return false; } if (f.exists()) { OutputStream fo; try { fo = new FileOutputStream(f); final PrintStream printStream = new PrintStream(fo); printStream.print(d); printStream.close(); return true; } catch (FileNotFoundException e) { return false; } } return false; }
From source file:com.adaptris.util.stream.Slf4jLoggingOutputStreamTest.java
@Test public void testLogTrace() throws Exception { PrintStream out = new PrintStream(new Slf4jLoggingOutputStream("TRACE")); out.println(TEXT);//from www . j a v a2s. c o m out.flush(); out.close(); }
From source file:com.adaptris.mail.TestEmailSending.java
@Test public void testSmtpSendAttachment() throws Exception { if (!testsEnabled()) return;/*from ww w. j av a 2 s. co m*/ GreenMail gm = JunitMailHelper.startServer(); try { SmtpClient smtp = createClient(gm); ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream print = new PrintStream(out); print.print(XML_DOCUMENT); print.close(); out.close(); smtp.addAttachment(out.toByteArray(), "filename.xml", null); smtp.send(); gm.waitForIncomingEmail(1); MimeMessage[] msgs = gm.getReceivedMessages(); assertEquals(1, msgs.length); JunitMailHelper.assertFrom(msgs[0], DEFAULT_SENDER); JunitMailHelper.assertTo(msgs[0], DEFAULT_RECEIVER); } finally { JunitMailHelper.stopServer(gm); } }
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 ww . j av a2 s. c o m*/ out.flush(); out.close(); }
From source file:com.adaptris.util.stream.Slf4jLoggingOutputStreamTest.java
@Test public void testLogWarn() throws Exception { PrintStream out = new PrintStream(new Slf4jLoggingOutputStream(LogLevel.WARN)); out.println(TEXT);// w w w. java2 s . c o m out.flush(); out.close(); }
From source file:com.adaptris.mail.TestEmailSending.java
@Test public void testSmtpSendAttachmentBase64Encoded() throws Exception { if (!testsEnabled()) return;// w w w .j av a 2 s . c om GreenMail gm = JunitMailHelper.startServer(); try { SmtpClient smtp = createClient(gm); ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream print = new PrintStream(out); print.print(XML_DOCUMENT); print.close(); out.close(); smtp.addAttachment(out.toByteArray(), "filename.xml", "text/plain"); smtp.setEncoding("base64"); smtp.send(); gm.waitForIncomingEmail(1); MimeMessage[] msgs = gm.getReceivedMessages(); assertEquals(1, msgs.length); JunitMailHelper.assertFrom(msgs[0], DEFAULT_SENDER); JunitMailHelper.assertTo(msgs[0], DEFAULT_RECEIVER); } finally { JunitMailHelper.stopServer(gm); } }
From source file:com.adaptris.mail.TestEmailSending.java
@Test public void testSmtpSendAttachmentUUEncoded() throws Exception { if (!testsEnabled()) return;// w ww . j a v a2 s. c o m GreenMail gm = JunitMailHelper.startServer(); try { SmtpClient smtp = createClient(gm); ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream print = new PrintStream(out); print.print(XML_DOCUMENT); print.close(); out.close(); smtp.addAttachment(out.toByteArray(), "filename.xml", null); smtp.setEncoding("uuencode"); smtp.send(); gm.waitForIncomingEmail(1); MimeMessage[] msgs = gm.getReceivedMessages(); assertEquals(1, msgs.length); JunitMailHelper.assertFrom(msgs[0], DEFAULT_SENDER); JunitMailHelper.assertTo(msgs[0], DEFAULT_RECEIVER); } finally { JunitMailHelper.stopServer(gm); } }
From source file:com.adaptris.util.stream.Slf4jLoggingOutputStreamTest.java
@Test public void testLogDebug() throws Exception { PrintStream out = new PrintStream(new Slf4jLoggingOutputStream(LogLevel.DEBUG)); out.println(TEXT);//w w w. ja v a 2s . c om out.flush(); out.close(); }