List of usage examples for java.io PrintStream print
public void print(Object obj)
From source file:com.adaptris.http.HttpResponse.java
/** Write the request line to the supplied outputstream. * @param out the outputstream//from w ww . jav a 2s. c o m * @throws HttpException on error. * @see DataTransfer#writeTo(OutputStream) */ public void writeTo(OutputStream out) throws HttpException { try { logR.trace("Writing Response:- " + toString()); PrintStream p = new PrintStream(out); p.print(toString()); p.print(Http.CRLF); p.flush(); } catch (Exception e) { throw new HttpException(e); } }
From source file:org.codice.ddf.migration.commands.MigrationCommand.java
private void outputMessageWithColor(String message, Ansi.Color color) { final String colorAsString = Ansi.ansi().a(Attribute.RESET).fg(color).toString(); final PrintStream console = getConsole(); console.print(colorAsString); console.print(message);// w w w . ja va 2 s . co m console.println(Ansi.ansi().a(Attribute.RESET).toString()); }
From source file:org.eclipse.xtend.util.uml2ecore.Uml2EcoreXmiWriter.java
private void removeAbsoluteFileRefs(XmiWriterURIConverter uriConverter, Resource r, String filename) { try {//from www .jav a 2 s . c om StringBuffer newFile = new StringBuffer(); InputStream stream = uriConverter.createInputStream(r.getURI()); BufferedReader br = new BufferedReader(new InputStreamReader(stream)); while (br.ready()) { String s = br.readLine(); s = s.replaceAll(filename + "#//", "#//"); newFile.append(s + "\n"); } br.close(); stream.close(); OutputStream s = uriConverter.createOutputStream(r.getURI()); PrintStream ps = new PrintStream(s); ps.print(newFile); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.jonathan.android.httpcache.HttpRequest.java
public boolean writeFileWithString(String d, File f) { try {//from w ww . j a va 2 s . c o m 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:CustomSubmitter.java
/** * Submits the specified PBS job to the PBS queue using the {@code qsub} * program.// www. j a 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:fungus.FluctuationObserver.java
@SuppressWarnings("unchecked") public boolean execute() { if (CDState.getCycle() % period != 0) return false; updateStats();/*w w w . ja v a2 s . c o m*/ if (fluctuations.isEmpty()) return false; StringBuilder sb = new StringBuilder(); java.util.Formatter f = new java.util.Formatter(sb, Locale.US); Integer i = 0; HashMap<Integer, Integer> map = (HashMap<Integer, Integer>) fluctuations.clone(); while (!map.isEmpty()) { Integer val = map.remove(i); if (val == null) { f.format("%1d:%1d, ", i, 0); } else { f.format("%1d:%1d, ", i, val); } i++; } // ah: remove last commaspace and add a newline sb.delete(sb.length() - 2, sb.length()); sb.append("\n"); // ah: TODO: copy experiment writer to get this writing to // a file, too, so i can make a graph out of it. try { FileOutputStream out = new FileOutputStream(filename, true); PrintStream p = new PrintStream(out); p.print(sb.toString()); out.close(); } catch (IOException e) { log.severe("Error writing fluctuation data to file"); debug(e.getMessage()); } log.info("fluctuation counts " + sb.toString()); return false; }
From source file:com.adaptris.mail.TestEmailSending.java
@Test public void testSmtpSendAttachment() throws Exception { if (!testsEnabled()) return;/*from w w w. j a va2s .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", 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.mail.TestEmailSending.java
@Test public void testSmtpSendAttachmentBase64Encoded() throws Exception { if (!testsEnabled()) return;/* ww w. j a va 2 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", "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;//from w ww . java 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.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.http.HttpHeaders.java
/** Write this set of headers to the supplied outputstream. * @see DataTransfer#writeTo(OutputStream) */// w ww . j a v a 2 s. com public void writeTo(OutputStream out) throws HttpException { try { PrintStream p = new PrintStream(out); p.print(toString()); p.flush(); } catch (Exception e) { throw new HttpException(e); } }