List of usage examples for java.io PrintStream flush
public void flush()
From source file:com.linkedin.bowser.tool.REPLServer.java
@Override public void messageReceived(IoSession session, Object message) throws Exception { final String line = message.toString(); if (line.trim().equalsIgnoreCase("quit")) { session.close();/*from w w w. jav a 2 s . c om*/ return; } REPL repl = (REPL) session.getAttribute(REPL.class.getName()); if (repl != null) { ByteArrayOutputStream ous = new ByteArrayOutputStream(); PrintStream out = new PrintStream(ous); try { repl.execute(line, new PrintStream(ous)); } catch (QueryRuntimeException e) { out.println(e.getMessage()); } catch (QueryFormatException e) { out.println(e.getMessage()); } out.flush(); session.write(ous.toString()); } }
From source file:com.taobao.adfs.util.Utilities.java
public static String getThrowableStackTrace(Throwable t) { PrintStream printStream = null; try {/*www . ja v a 2s.c om*/ OutputStream outputStream = null; outputStream = new ByteArrayOutputStream(1024); printStream = new PrintStream(outputStream); t.printStackTrace(printStream); printStream.flush(); return outputStream.toString(); } catch (Exception e) { return "unknow"; } finally { if (printStream != null) printStream.close(); } }
From source file:org.codehaus.enunciate.modules.php.PHPDeploymentModule.java
/** * Reads a resource into string form.// w ww.ja v a2 s . com * * @param resource The resource to read. * @return The string form of the resource. */ protected String readResource(String resource) throws IOException, EnunciateException { HashMap<String, Object> model = new HashMap<String, Object>(); model.put("sample_resource", getModelInternal().findExampleResourceMethod()); URL res = PHPDeploymentModule.class.getResource(resource); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); PrintStream out = new PrintStream(bytes); try { processTemplate(res, model, out); out.flush(); bytes.flush(); return bytes.toString("utf-8"); } catch (TemplateException e) { throw new EnunciateException(e); } }
From source file:org.codehaus.enunciate.modules.ruby.RubyDeploymentModule.java
/** * Reads a resource into string form./*ww w.j ava 2s . c o m*/ * * @param resource The resource to read. * @return The string form of the resource. */ protected String readResource(String resource) throws IOException, EnunciateException { HashMap<String, Object> model = new HashMap<String, Object>(); model.put("sample_resource", getModelInternal().findExampleResourceMethod()); URL res = RubyDeploymentModule.class.getResource(resource); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); PrintStream out = new PrintStream(bytes); try { processTemplate(res, model, out); out.flush(); bytes.flush(); return bytes.toString("utf-8"); } catch (TemplateException e) { throw new EnunciateException(e); } }
From source file:cn.com.sinosoft.util.exception.ExceptionUtils.java
/** * <p>//from w w w .j a v a 2 s .c o m * Prints a compact stack trace for the root cause of a throwable. * </p> * * <p> * The compact stack trace starts with the root cause and prints stack * frames up to the place where it was caught and wrapped. Then it prints * the wrapped exception and continues with stack frames until the wrapper * exception is caught and wrapped again, etc. * </p> * * <p> * The output of this method is consistent across JDK versions. Note that * this is the opposite order to the JDK1.4 display. * </p> * * <p> * The method is equivalent to <code>printStackTrace</code> for throwables * that don't have nested causes. * </p> * * @param throwable * the throwable to output, may be null * @param stream * the stream to output to, may not be null * @throws IllegalArgumentException * if the stream is <code>null</code> * @since 2.0 */ public static void printRootCauseStackTrace(Throwable throwable, PrintStream stream) { if (throwable == null) { return; } if (stream == null) { throw new IllegalArgumentException("The PrintStream must not be null"); } String trace[] = getRootCauseStackTrace(throwable); for (int i = 0; i < trace.length; i++) { stream.println(trace[i]); } stream.flush(); }
From source file:org.ejbca.core.model.ca.catoken.BaseCAToken.java
private void testKey(KeyPair pair) throws Exception { if (log.isDebugEnabled()) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PrintStream ps = new PrintStream(baos); KeyTools.printPublicKeyInfo(pair.getPublic(), ps); ps.flush(); log.debug("Using of " + baos.toString()); }//from www . j a va2 s .c o m if (!doPermitExtractablePrivateKey() && KeyTools.isPrivateKeyExtractable(pair.getPrivate())) { String msg = intres.getLocalizedMessage("catoken.extractablekey", EjbcaConfiguration.doPermitExtractablePrivateKeys()); if (!EjbcaConfiguration.doPermitExtractablePrivateKeys()) { throw new InvalidKeyException(msg); } log.info(msg); } KeyTools.testKey(pair.getPrivate(), pair.getPublic(), getProvider()); }
From source file:org.apache.taverna.commandline.TavernaCommandLineTest.java
private synchronized void runWorkflow(String command, String workflow, File outputsDirectory, boolean inputValues, boolean secure, boolean database) throws Exception { ProcessBuilder processBuilder = new ProcessBuilder("sh", command); processBuilder.redirectErrorStream(true); processBuilder.directory(buildDirectory); List<String> args = processBuilder.command(); for (File input : inputs) { if (inputValues) { args.add("-inputvalue"); args.add(input.getName());/*from w w w . j a v a 2 s . co m*/ args.add(IOUtils.toString(new FileReader(input))); } else { args.add("-inputfile"); args.add(input.getName()); args.add(input.getAbsolutePath()); } } args.add("-outputdir"); args.add(outputsDirectory.getPath()); if (secure) { args.add("-cmdir"); args.add(getClass().getResource("/security").getFile()); args.add("-cmpassword"); } if (database) { args.add("-embedded"); } args.add(workflow); Process process = processBuilder.start(); if (secure) { PrintStream outputStream = new PrintStream(process.getOutputStream()); outputStream.println("test"); outputStream.flush(); } waitFor(process); }
From source file:org.codehaus.enunciate.modules.c.CDeploymentModule.java
/** * Reads a resource into string form./* w ww. j ava 2 s .c om*/ * * @param resource The resource to read. * @return The string form of the resource. */ protected String readResource(String resource) throws IOException, EnunciateException { HashMap<String, Object> model = new HashMap<String, Object>(); ResourceMethod exampleResource = getModelInternal().findExampleResourceMethod(); model.put("filename", getSourceFileName()); String label = getLabel() == null ? getEnunciate().getConfig() == null ? "enunciate" : getEnunciate().getConfig().getLabel() : getLabel(); NameForTypeDefinitionMethod nameForTypeDefinition = new NameForTypeDefinitionMethod( getTypeDefinitionNamePattern(), label, getModelInternal().getNamespacesToPrefixes()); if (exampleResource != null) { if (exampleResource.getEntityParameter() != null && exampleResource.getEntityParameter().getXmlElement() != null) { ElementDeclaration el = exampleResource.getEntityParameter().getXmlElement(); TypeDefinition typeDefinition = null; if (el instanceof RootElementDeclaration) { typeDefinition = getModelInternal().findTypeDefinition((RootElementDeclaration) el); } else if (el instanceof LocalElementDeclaration && ((LocalElementDeclaration) el).getElementTypeDeclaration() instanceof ClassDeclaration) { typeDefinition = getModelInternal().findTypeDefinition( (ClassDeclaration) ((LocalElementDeclaration) el).getElementTypeDeclaration()); } if (typeDefinition != null) { model.put("input_element_name", nameForTypeDefinition.calculateName(typeDefinition)); } } if (exampleResource.getRepresentationMetadata() != null && exampleResource.getRepresentationMetadata().getXmlElement() != null) { ElementDeclaration el = exampleResource.getRepresentationMetadata().getXmlElement(); TypeDefinition typeDefinition = null; if (el instanceof RootElementDeclaration) { typeDefinition = getModelInternal().findTypeDefinition((RootElementDeclaration) el); } else if (el instanceof LocalElementDeclaration && ((LocalElementDeclaration) el).getElementTypeDeclaration() instanceof ClassDeclaration) { typeDefinition = getModelInternal().findTypeDefinition( (ClassDeclaration) ((LocalElementDeclaration) el).getElementTypeDeclaration()); } if (typeDefinition != null) { model.put("output_element_name", nameForTypeDefinition.calculateName(typeDefinition)); } } } URL res = CDeploymentModule.class.getResource(resource); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); PrintStream out = new PrintStream(bytes); try { processTemplate(res, model, out); out.flush(); bytes.flush(); return bytes.toString("utf-8"); } catch (TemplateException e) { throw new EnunciateException(e); } }
From source file:org.debian.paulliu.kajiradoubra.controller.KajiraDouBraController.java
public void sendBluetoothData(String s) { java.io.PrintStream outputStream = null; try {// ww w.ja va2 s. c om outputStream = new java.io.PrintStream(mBluetoothSocket.getOutputStream()); } catch (java.io.IOException e) { Log.w(LOGTAG, "Cannot get outputStream from BluetoothSocket"); } if (outputStream != null) { outputStream.print(s); outputStream.flush(); } else { Log.w(LOGTAG, "Bluetooth outputStream is null"); } }
From source file:org.openmrs.module.pacsintegration.component.HL7ListenerComponentTest.java
@Test public void shouldCreateTwoReportsIfBodyDifferent() throws Exception { ModuleActivator activator = new PacsIntegrationActivator(); activator.started();// w w w .j av a 2 s. c om Context.getService(PacsIntegrationService.class).initializeHL7Listener(); List<Patient> patients = patientService.getPatients(null, "101-6", Collections.singletonList(emrApiProperties.getPrimaryIdentifierType()), true); assertThat(patients.size(), is(1)); // sanity check Patient patient = patients.get(0); List<Encounter> encounters = encounterService.getEncounters(patient, null, null, null, null, Collections.singletonList(radiologyProperties.getRadiologyReportEncounterType()), null, null, null, false); assertThat(encounters.size(), is(0)); // sanity check try { String message1 = "MSH|^~\\&|HMI|Mirebalais Hospital|RAD|REPORTS|20130228174549||ORU^R01|RTS01CE16055AAF5290|P|2.3|\r" + "PID|1||101-6||Patient^Test^||19770222|M||||||||||\r" + "PV1|1||||||||||||||||||\r" + "OBR|1||0000001297|127689^SOME_X-RAY|||20130228170556||||||||||||MBL^CR||||||F|||||||Test&Goodrich&Mark&&&&||||20130228170556\r" + "OBX|1|TX|127689^SOME_X-RAY||Clinical Indication: ||||||F\r"; String message2 = "MSH|^~\\&|HMI|Mirebalais Hospital|RAD|REPORTS|20130228174549||ORU^R01|RTS01CE16055AAF5290|P|2.3|\r" + "PID|1||101-6||Patient^Test^||19770222|M||||||||||\r" + "PV1|1||||||||||||||||||\r" + "OBR|1||0000001297|127689^SOME_X-RAY|||20130228170556||||||||||||MBL^CR||||||F|||||||Test&Goodrich&Mark&&&&||||20130228170556\r" + "OBX|1|TX|127689^SOME_X-RAY||Another Clinical Indication: ||||||F\r"; Thread.sleep(2000); // give the simple server time to start Socket socket = new Socket("127.0.0.1", 6665); PrintStream writer = new PrintStream(socket.getOutputStream()); writer.print(header); writer.print(message1); writer.print(trailer + "\r"); writer.flush(); writer.print(header); writer.print(message2); writer.print(trailer + "\r"); writer.flush(); Thread.sleep(2000); encounters = encounterService.getEncounters(patient, null, null, null, null, Collections.singletonList(radiologyProperties.getRadiologyReportEncounterType()), null, null, null, false); assertThat(encounters.size(), is(2)); } finally { activator.stopped(); } }