List of usage examples for java.io PrintStream PrintStream
public PrintStream(File file) throws FileNotFoundException
From source file:au.com.rayh.XCodeBuildOutputParserTest.java
@Before public void setUp() throws IOException, InterruptedException { XCodeBuildOutputParser parser = new XCodeBuildOutputParser(new File("."), new PrintStream("test-output.txt")); test = new OutputParserTests(parser); }
From source file:PatchyMIDlet.java
public void run() { try {/*w w w. j a v a 2 s .c o m*/ mServerSocketConnection = (ServerSocketConnection) Connector.open("socket://:80"); SocketConnection sc = null; while (mTrucking) { sc = (SocketConnection) mServerSocketConnection.acceptAndOpen(); Reader in = new InputStreamReader(sc.openInputStream()); PrintStream out = new PrintStream(sc.openOutputStream()); out.print("HTTP/1.1 200 OK\r\n\r\n"); out.print("Message"); out.close(); in.close(); sc.close(); } } catch (Exception e) { } }
From source file:com.iblsoft.iwxxm.webservice.Main.java
private static void runAsService() throws Exception { Configuration configuration = ConfigManager.getConfiguration(); File logFilePath = new File(configuration.getLogDir(), configuration.getLogFileNamePattern()); RolloverFileOutputStream os = new RolloverFileOutputStream(logFilePath.getAbsolutePath(), true, configuration.getLogRetainInDays(), TimeZone.getTimeZone("UTC")); PrintStream logStream = new PrintStream(os); Handler handler = createValidationServletHandler(configuration); if (configuration.isAccessLogEnabled()) { handler = createAccessLogHandler(configuration, handler); }/*from w w w . ja v a 2 s . c o m*/ printServiceHelp(configuration); Server server = new Server(configuration.getServerPort()); server.setHandler(handler); System.setOut(logStream); System.setErr(logStream); server.start(); Log.INSTANCE.info("IBL IWXXM Web Service started [{}]", configuration.getServerPort()); server.join(); }
From source file:com.meetingninja.csse.database.AgendaDatabaseAdapter.java
public static Agenda createAgenda(Agenda create) throws IOException { Agenda newAgenda = new Agenda(create); // Server URL setup String _url = getBaseUri().build().toString(); // Establish connection URL url = new URL(_url); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // add request header conn.setRequestMethod(IRequest.POST); addRequestHeader(conn, true);/*w w w . j av a 2s . 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(); // start agenda jgen.writeStringField(Keys.Agenda.TITLE, create.getTitle()); jgen.writeStringField(Keys.Agenda.MEETING, create.getAttachedMeetingID()); jgen.writeArrayFieldStart(Keys.Agenda.TOPIC); // start topics MAPPER.writeValue(jgen, create.getTopics()); // recursively does // subtopics jgen.writeEndArray(); // end topics jgen.writeEndObject(); // end agenda 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); newAgenda = parseAgenda(MAPPER.readTree(response)); return newAgenda; }
From source file:net.sf.taverna.raven.helloworld.HelloWorld.java
public int launch(String[] args) throws IOException { if (args.length == 0) { run(System.out);/* w w w .jav a 2s. c o m*/ } else { PrintStream outStream = new PrintStream(args[0]); try { run(outStream); } finally { outStream.close(); } } return 0; }
From source file:org.kordamp.javatrove.example04.util.ApplicationEventHandler.java
@Handler public void handleThrowable(ThrowableEvent event) { Platform.runLater(() -> {// w w w . j ava 2 s .co m TitledPane pane = new TitledPane(); pane.setCollapsible(false); pane.setText("Stacktrace"); TextArea textArea = new TextArea(); textArea.setEditable(false); pane.setContent(textArea); ByteArrayOutputStream baos = new ByteArrayOutputStream(); event.getThrowable().printStackTrace(new PrintStream(baos)); textArea.setText(baos.toString()); Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("Error"); alert.setHeaderText("An unexpected error occurred"); alert.getDialogPane().setContent(pane); alert.showAndWait(); }); }
From source file:de.haber.xmind2latex.XMindToLatexExporterTest.java
/** * Tests the showHelp() method. Additionally exports the help message into file * target/app/doc/commands.txt that is used in the documentation. * // www .ja va 2 s.com * @throws IOException */ @Test public void testShowHelp() throws IOException { File result = new File("target/app/doc/commands.txt"); result.delete(); result.getParentFile().mkdirs(); result.createNewFile(); FileOutputStream os = new FileOutputStream(result); PrintStream out = new PrintStream(os); PrintStream old_out = System.out; System.setOut(out); CliParameters.showHelp(); String resultContent = FileUtils.readFileToString(result); assertFalse(resultContent.isEmpty()); System.setOut(old_out); os.close(); }
From source file:Client.java
public void run() { if (clientSocket == null) { return;//from w w w .ja va 2 s.co m } PrintStream out = null; Utilities.printMsg("creating output stream"); try { out = new PrintStream(clientSocket.getOutputStream()); } catch (IOException e) { System.err.println("Error binding output to socket, " + e); System.exit(1); } Utilities.printMsg("writing current date"); Date d = new Date(); out.println(d); try { out.close(); clientSocket.close(); } catch (IOException e) { } }
From source file:org.esupportail.dining.web.controllers.AbstractExceptionController.java
@ExceptionHandler(Exception.class) public final ModelAndView handleException(final Exception ex) { logger.error("Exception catching in spring mvc controller ... ", ex); ModelMap model = new ModelMap(); ByteArrayOutputStream output = new ByteArrayOutputStream(); PrintStream print = new PrintStream(output); ex.printStackTrace(print);//from www .java2s . c o m String exceptionStackTrace = new String(output.toByteArray()); model.put("exceptionStackTrace", exceptionStackTrace); model.put("exceptionMessage", ex.getMessage()); return new ModelAndView("exception", model); }
From source file:com.splunk.shuttl.testutil.TUtilsFile.java
/** * Writes random alphanumeric content to specified file. * /* w w w.java 2 s.co m*/ * @param file */ public static void populateFileWithRandomContent(File file) { PrintStream printStream = null; try { printStream = new PrintStream(file); printStream.println(RandomStringUtils.randomAlphanumeric(1000)); printStream.flush(); } catch (FileNotFoundException e) { TUtilsTestNG.failForException("Failed to write random content", e); } finally { IOUtils.closeQuietly(printStream); } }