List of usage examples for java.io PrintStream flush
public void flush()
From source file:org.moe.gradle.remote.AbstractServerTask.java
private void printTaskEnd(@NotNull PrintStream stream, TermColor color, String message, int sepWidth) { final int size = sepWidth - message.length(); final int size_2 = size / 2; stream.println(color.toString() + StringUtils.rightPad("", size_2, "<") + message + StringUtils.rightPad("", size - size_2, ">") + FM_RES_ALL); stream.flush(); }
From source file:org.apache.any23.extractor.microdata.MicrodataParserTest.java
@Ignore("TODO: Determine the cause of this") @Test//www . jav a 2 s . c om public void testMicrodataJSONSerialization() throws IOException { final Document document = getMicrodataDom("microdata-nested"); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PrintStream ps = new PrintStream(baos); MicrodataParser.getMicrodataAsJSON(document, ps); ps.flush(); final String expected = StreamUtils .asString(this.getClass().getResourceAsStream("/microdata/microdata-json-serialization.json")); Assert.assertEquals("Unexpected serialization for Microdata file.", expected, baos.toString()); }
From source file:com.alvermont.javascript.tools.shell.ShellMain.java
/** * Evaluate JavaScript source.//www.j av a 2 s . c om * * @param cx the current context * @param filename the name of the file to compile, or null * for interactive mode. */ public static void processSource(Context cx, String filename) { if (filename == null || filename.equals("-")) { final PrintStream ps = GLOBAL.getErr(); if (filename == null) { // print implementation version ps.println(cx.getImplementationVersion()); } // Use the interpreter for interactive input cx.setOptimizationLevel(-1); final BufferedReader in = new BufferedReader(new InputStreamReader(GLOBAL.getIn())); int lineno = 1; boolean hitEOF = false; while (!hitEOF) { final int startline = lineno; if (filename == null) { ps.print("js> "); } ps.flush(); String source = ""; // Collect lines of source to compile. while (true) { String newline; try { newline = in.readLine(); } catch (IOException ioe) { ps.println(ioe.toString()); break; } if (newline == null) { hitEOF = true; break; } source = source + newline + "\n"; ++lineno; if (cx.stringIsCompilableUnit(source)) { break; } } final Script script = loadScriptFromSource(cx, source, "<stdin>", lineno, null); if (script != null) { final Object result = evaluateScript(script, cx, GLOBAL); if (result != Context.getUndefinedValue()) { try { ps.println(Context.toString(result)); } catch (RhinoException rex) { ToolErrorReporter.reportException(cx.getErrorReporter(), rex); } } final NativeArray h = GLOBAL.getHistory(); h.put((int) h.getLength(), h, source); } } ps.println(); } else { processFile(cx, GLOBAL, filename); } System.gc(); }
From source file:org.apache.hadoop.util.TestFindClass.java
@SuppressWarnings("UseOfSystemOutOrSystemErr") @Test//from www .j ava 2 s. c om public void testPrintLog4J() throws Throwable { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream out = new PrintStream(baos); FindClass.setOutputStreams(out, System.err); run(FindClass.SUCCESS, FindClass.A_PRINTRESOURCE, LOG4J_PROPERTIES); //here the content should be done out.flush(); String body = baos.toString("UTF8"); LOG.info(LOG4J_PROPERTIES + " =\n" + body); assertTrue(body.contains("Apache")); }
From source file:org.cloudifysource.restDoclet.generation.Utils.java
@SuppressWarnings("unused") private static void printMethodsToFile(final List<DocController> controllers, final String fileName) throws IOException { PrintStream print = null; try {//from w w w . j a va 2 s .c om print = new PrintStream(new File(fileName)); for (DocController docController : controllers) { Collection<DocMethod> methods = docController.getMethods().values(); print.println("*****************************************"); print.println("Controller " + docController.getName()); print.println("*****************************************"); for (DocMethod docMethod : methods) { List<DocHttpMethod> httpMethods = docMethod.getHttpMethods(); for (DocHttpMethod docHttpMethod : httpMethods) { print.println("method " + docHttpMethod.getMethodSignatureName()); // print.println(" uri " + docMethod.getUri()); // print.println(" request method " + // docHttpMethod.getHttpMethodName()); } } } } finally { if (print != null) { print.flush(); print.close(); } } }
From source file:com.bigdata.dastor.tools.SSTableExport.java
static void export(SSTableReader reader, PrintStream outs, String[] excludes) throws IOException { SSTableScanner scanner = reader.getScanner(INPUT_FILE_BUFFER_SIZE); Set<String> excludeSet = new HashSet(); if (excludes != null) excludeSet = new HashSet<String>(Arrays.asList(excludes)); outs.println("{"); while (scanner.hasNext()) { IteratingRow row = scanner.next(); if (excludeSet.contains(row.getKey().key)) continue; try {//w w w . j av a 2 s . com String jsonOut = serializeRow(row); outs.print(" " + jsonOut); if (scanner.hasNext()) outs.println(","); else outs.println(); } catch (IOException ioexcep) { System.err.println("WARNING: Corrupt row " + row.getKey().key + " (skipping)."); continue; } catch (OutOfMemoryError oom) { System.err.println("ERROR: Out of memory deserializing row " + row.getKey().key); continue; } } outs.println("}"); outs.flush(); }
From source file:org.csanchez.jenkins.plugins.kubernetes.pipeline.ContainerExecDecorator.java
private static void doExec(ExecWatch watch, PrintStream out, String... statements) { try {//from w w w .j a v a 2 s .c o m out.print("Executing command: "); StringBuilder sb = new StringBuilder(); for (String stmt : statements) { String s = String.format("\"%s\" ", stmt); sb.append(s); out.print(s); watch.getInput().write(s.getBytes(StandardCharsets.UTF_8)); } sb.append(NEWLINE); out.println(); watch.getInput().write(NEWLINE.getBytes(StandardCharsets.UTF_8)); // get the command exit code and print it padded so it is easier to parse in ConatinerExecProc // We need to exit so that we know when the command has finished. sb.append(ExitCodeOutputStream.EXIT_COMMAND); out.print(ExitCodeOutputStream.EXIT_COMMAND); LOGGER.log(Level.FINEST, "Executing command: {0}", sb.toString()); watch.getInput().write(ExitCodeOutputStream.EXIT_COMMAND.getBytes(StandardCharsets.UTF_8)); out.flush(); watch.getInput().flush(); } catch (IOException e) { e.printStackTrace(out); throw new RuntimeException(e); } }
From source file:org.opendatakit.common.android.utilities.WebLogger.java
public void printStackTrace(Throwable e) { e.printStackTrace();/*from w w w.java 2s. c o m*/ ByteArrayOutputStream ba = new ByteArrayOutputStream(); PrintStream w; try { w = new PrintStream(ba, false, "UTF-8"); e.printStackTrace(w); w.flush(); w.close(); log(ba.toString("UTF-8")); } catch (UnsupportedEncodingException e1) { // error if it ever occurs throw new IllegalStateException("unable to specify UTF-8 Charset!"); } catch (IOException e1) { e1.printStackTrace(); } }
From source file:org.apache.carbondata.tool.CarbonCli.java
private static void runCli(PrintStream out, Options options, CommandLine line) { if (outPuts == null) { outPuts = new ArrayList<>(); }// www. j a v a 2 s . c om if (line.hasOption("h")) { collectHelpInfo(options); for (String output : outPuts) { out.println(output); } return; } String path = ""; if (line.hasOption("p")) { path = line.getOptionValue("path"); } outPuts.add("Input Folder: " + path); String cmd = line.getOptionValue("cmd"); Command command; if (cmd.equalsIgnoreCase("summary")) { command = new DataSummary(path, outPuts); } else if (cmd.equalsIgnoreCase("benchmark")) { command = new ScanBenchmark(path, outPuts); } else { out.println("command " + cmd + " is not supported"); outPuts.add("command " + cmd + " is not supported"); collectHelpInfo(options); for (String output : outPuts) { out.println(output); } return; } try { command.run(line); if (isPrintInConsole) { for (String output : outPuts) { out.println(output); } } out.flush(); } catch (IOException | MemoryException e) { e.printStackTrace(); } finally { out.close(); } }
From source file:org.samcrow.ridgesurvey.data.UploadService.java
/** * Uploads an observation/*from w w w . j a v a2s .com*/ * * @param observation the observation to upload */ private void upload(@NonNull URL url, @NonNull Observation observation) throws IOException, ParseException, UploadException { Objects.requireNonNull(observation); final Map<String, String> formData = formatObservation(observation); Log.v(TAG, "Formatted observation: " + formData); final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); try { // Disable response compression, which might be causing problems connection.setRequestProperty("Accept-Encoding", "identity"); // POST connection.setUseCaches(false); connection.setDoOutput(true); connection.setChunkedStreamingMode(0); final PrintStream out = new PrintStream(connection.getOutputStream()); writeFormEncodedData(formData, out); out.flush(); final String response = IOUtils.toString(connection.getInputStream()); Log.v(TAG, response); // Check status final int status = connection.getResponseCode(); if (status == 200) { // Check for valid JSON final JSONObject json = new JSONObject(response); final String result = json.optString("result", ""); if (!result.equals("success")) { final String message = json.optString("message", null); if (message != null) { throw new UploadException(message); } else { throw new UploadException("Unknown server error"); } } } else if (status == 301 || status == 302) { // Handle redirect and add cookies final String location = connection.getHeaderField("Location"); if (location != null) { final URL redirectUrl = new URL(location); Log.i(TAG, "Following redirect to " + redirectUrl); upload(redirectUrl, observation); } else { throw new UploadException("Got a 301 or 302 response with no Location header"); } } else { throw new UploadException("Unexpected HTTP status " + status); } } catch (JSONException e) { final ParseException e1 = new ParseException("Failed to parse response JSON", 0); e1.initCause(e); throw e1; } finally { connection.disconnect(); } }