List of usage examples for java.io PrintStream flush
public void flush()
From source file:org.jcodec.codecs.h264.decode.resilence.Painter.java
public static void savePGM(String string, int[] y, int width, int height) { OutputStream out = null;/* w w w. ja v a 2s. c om*/ try { out = new BufferedOutputStream(new FileOutputStream(string)); PrintStream ps = new PrintStream(out); ps.println("P5"); ps.println(width + " " + height); ps.println("255"); ps.flush(); for (int i = 0; i < y.length; i++) out.write(y[i]); out.flush(); } catch (IOException e) { IOUtils.closeQuietly(out); } }
From source file:com.ikon.util.ExecutionUtils.java
/** * Execute script/* w ww . j ava 2 s.c o m*/ * * @return 0 - Return * 1 - StdOut * 2 - StdErr */ public static Object[] runScript(String script) throws EvalError { Object[] ret = new Object[3]; ByteArrayOutputStream baosOut = new ByteArrayOutputStream(); PrintStream out = new PrintStream(baosOut); ByteArrayOutputStream baosErr = new ByteArrayOutputStream(); PrintStream err = new PrintStream(baosErr); Interpreter i = new Interpreter(null, out, err, false); ret[0] = i.eval(script); out.flush(); ret[1] = baosOut.toString(); err.flush(); ret[2] = baosErr.toString(); log.debug("runScript: {}", Arrays.toString(ret)); return ret; }
From source file:edu.byu.softwareDist.manager.impl.SendEmailImpl.java
private static File saveTemplateToDisk(final FileSet fileSet) { File f = null;/* w w w . j a v a2s .c o m*/ PrintStream out = null; try { f = File.createTempFile("software-distribution-email-content." + fileSet.getFileSetId() + "-", ".vm"); out = new PrintStream(new FileOutputStream(f)); out.print(fileSet.getEmailContent()); out.flush(); return f; } catch (IOException e) { LOG.error("Error writing template to temporary file.", e); return null; } finally { if (f != null) { f.deleteOnExit(); } if (out != null) { out.close(); } } }
From source file:it.mb.whatshare.PairOutboundActivity.java
/** * Saves the argument <tt>device</tt> as the (only) configured outbound * device.//from w ww. j a v a 2 s. co m * * <p> * If <tt>device</tt> is <code>null</code>, the currently configured device * is deleted. * * @param device * the device to be stored, or <code>null</code> if the current * association must be discarded * @param context * the application's context (used to open the association file * with) * @throws IOException * in case something is wrong with the file * @throws JSONException * in case something is wrong with the argument <tt>device</tt> */ public static void savePairing(PairedDevice device, Context context) throws IOException, JSONException { if (device == null) { Utils.debug("deleting outbound device... %s", context.deleteFile(PAIRING_FILE_NAME) ? "success" : "fail"); } else { FileOutputStream fos = context.openFileOutput(PAIRING_FILE_NAME, Context.MODE_PRIVATE); // @formatter:off JSONObject json = new JSONObject().put("name", device.name).put("type", device.type).put("assignedID", device.id); // @formatter:on PrintStream writer = new PrintStream(fos); writer.append(json.toString()); writer.flush(); writer.close(); } }
From source file:com.adaptris.util.text.mime.MultiPartOutput.java
/** * Write the internet headers out to the supplied outputstream *//*from ww w .j av a 2 s .co m*/ private static void writeHeaders(InternetHeaders header, OutputStream out) throws IOException, MessagingException { Enumeration e = header.getAllHeaderLines(); PrintStream p = new PrintStream(out); while (e.hasMoreElements()) { p.println(e.nextElement().toString()); } p.println(""); p.flush(); }
From source file:com.sap.prd.mobile.ios.mios.EffectiveBuildSettings.java
private static Properties extractBuildSettings(final IXCodeContext context) throws XCodeException { List<String> buildActions = Collections.emptyList(); IOptions options = context.getOptions(); Map<String, String> managedOptions = new HashMap<String, String>(options.getManagedOptions()); managedOptions.put(Options.ManagedOption.SHOWBUILDSETTINGS.getOptionName(), null); XCodeContext showBuildSettingsContext = new XCodeContext(buildActions, context.getProjectRootDirectory(), context.getOut(),//from w w w. j a va 2s.co m new Settings(context.getSettings().getUserSettings(), context.getSettings().getManagedSettings()), new Options(options.getUserOptions(), managedOptions)); final CommandLineBuilder cmdLineBuilder = new CommandLineBuilder(showBuildSettingsContext); PrintStream out = null; ByteArrayOutputStream os = null; try { os = new ByteArrayOutputStream(); out = new PrintStream(os, true, Charset.defaultCharset().name()); final int returnValue = Forker.forkProcess(out, context.getProjectRootDirectory(), cmdLineBuilder.createBuildCall()); if (returnValue != 0) { if (out != null) out.flush(); throw new XCodeException( "Could not execute xcodebuild -showBuildSettings command for configuration " + context.getConfiguration() + " and sdk " + context.getSDK() + ": " + new String(os.toByteArray(), Charset.defaultCharset().name())); } out.flush(); Properties prop = new Properties(); prop.load(new ByteArrayInputStream(os.toByteArray())); return prop; } catch (IOException ex) { throw new XCodeException("Cannot extract build properties: " + ex.getMessage(), ex); } finally { IOUtils.closeQuietly(out); } }
From source file:org.apache.airavata.common.utils.StringUtil.java
/** * @param throwable/*w w w. j a v a 2 s. c om*/ * @return The stackTrace in String */ public static String getStackTraceInString(Throwable throwable) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(byteArrayOutputStream); throwable.printStackTrace(printStream); printStream.flush(); return byteArrayOutputStream.toString(); }
From source file:com.sap.prd.mobile.ios.mios.Forker.java
private static void handleLog(final InputStream is, final PrintStream out) throws IOException { if (out.checkError()) throw new IOException( "Cannot handle log output. PrintStream that should be used for log handling is damaged."); byte[] buff = new byte[1024]; for (int i; (i = is.read(buff)) != -1;) { out.write(buff, 0, i);//from ww w . jav a 2 s .c o m if (out.checkError()) throw new IOException( "Cannot handle log output from xcodebuild. Underlying PrintStream indicates problems."); } out.flush(); }
From source file:com.ikon.util.ExecutionUtils.java
/** * Execute script from file/*from w w w.ja va2 s . c o m*/ * * @return 0 - Return * 1 - StdOut * 2 - StdErr */ public static Object[] runScript(File script) throws EvalError { Object[] ret = new Object[3]; FileReader fr = null; try { if (script.exists() && script.canRead()) { ByteArrayOutputStream baosOut = new ByteArrayOutputStream(); PrintStream out = new PrintStream(baosOut); ByteArrayOutputStream baosErr = new ByteArrayOutputStream(); PrintStream err = new PrintStream(baosErr); Interpreter i = new Interpreter(null, out, err, false); fr = new FileReader(script); ret[0] = i.eval(fr); out.flush(); ret[1] = baosOut.toString(); err.flush(); ret[2] = baosErr.toString(); } else { log.warn("Unable to read script: {}", script.getPath()); } } catch (IOException e) { log.warn(e.getMessage(), e); } finally { IOUtils.closeQuietly(fr); } log.debug("runScript: {}", Arrays.toString(ret)); return ret; }
From source file:Main.java
public static int saveToSdCard(String fileName, Bitmap bitmap) { int ret = 0;// w ww .j a v a 2 s . c om PrintStream out = null; if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { return -1; } File file = new File(Environment.getExternalStorageDirectory().toString() + File.separator + fileName); if (!file.getParentFile().exists()) { file.getParentFile().mkdir(); } try { out = new PrintStream(new FileOutputStream(file)); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); } catch (FileNotFoundException e) { // TODO Auto-generated catch block ret = -2; } finally { out.flush(); out.close(); if (!bitmap.isRecycled()) bitmap.recycle(); } return ret; }