List of usage examples for java.io OutputStream flush
public void flush() throws IOException
From source file:Main.java
static final File createFile(File file, String data) { OutputStream os = null; try {/*from ww w . j a v a 2s . co m*/ os = new FileOutputStream(file); os.write(data.getBytes()); os.flush(); os.close(); return file; } catch (Exception e) { try { if (null != os) { os.close(); } } catch (Exception e2) { } toast("Cannot write the data to file " + file.getAbsolutePath() + ": " + e.getMessage()); } return null; }
From source file:Main.java
public static String imageToLocal(Bitmap bitmap, String name) { String path = null;/*from w w w . jav a2s. c o m*/ try { if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { return null; } String filePath = Environment.getExternalStorageDirectory().getPath() + "/cache/"; File file = new File(filePath, name); if (file.exists()) { path = file.getAbsolutePath(); return path; } else { file.getParentFile().mkdirs(); } file.createNewFile(); OutputStream outStream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream); outStream.flush(); outStream.close(); if (!bitmap.isRecycled()) { bitmap.recycle(); } path = file.getAbsolutePath(); } catch (Exception e) { } return path; }
From source file:Main.java
public static void sendStopSignal(int port) { try {/*from w ww.j a va2s . c om*/ Socket s = new Socket(InetAddress.getByName("127.0.0.1"), port); OutputStream out = s.getOutputStream(); System.err.println("sending server stop request"); out.write(("\r\n").getBytes()); out.flush(); s.close(); } catch (Exception e) { // can happen when called twice by jvm shutdown hook System.err.println("stop monitor thread has terminated"); } }
From source file:com.ALC.SC2BOAserver.util.SC2BOAserverFileUtil.java
/** * This method extracts data to a given directory. * /* w w w. j a v a 2s.com*/ * @param directory the directory to extract into * @param zipIn input stream pointing to the zip file * @throws ArchiveException * @throws IOException * @throws FileNotFoundException */ public static void extractZipToDirectory(File directory, InputStream zipIn) throws ArchiveException, IOException, FileNotFoundException { ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream("zip", zipIn); while (true) { ZipArchiveEntry entry = (ZipArchiveEntry) in.getNextEntry(); if (entry == null) { in.close(); break; } //Skip empty files if (entry.getName().equals("")) { continue; } if (entry.isDirectory()) { File file = new File(directory, entry.getName()); file.mkdirs(); } else { File outFile = new File(directory, entry.getName()); if (!outFile.getParentFile().exists()) { outFile.getParentFile().mkdirs(); } OutputStream out = new FileOutputStream(outFile); IOUtils.copy(in, out); out.flush(); out.close(); } } }
From source file:br.gov.jfrj.siga.base.ConexaoHTTP.java
public static String get(String URL, HashMap<String, String> header, Integer timeout, String payload) throws AplicacaoException { try {/*from www.ja va2s .co m*/ HttpURLConnection conn = (HttpURLConnection) new URL(URL).openConnection(); if (timeout != null) { conn.setConnectTimeout(timeout); conn.setReadTimeout(timeout); } //conn.setInstanceFollowRedirects(true); if (header != null) { for (String s : header.keySet()) { conn.setRequestProperty(s, header.get(s)); } } System.setProperty("http.keepAlive", "false"); if (payload != null) { byte ab[] = payload.getBytes("UTF-8"); conn.setRequestMethod("POST"); // Send post request conn.setDoOutput(true); OutputStream os = conn.getOutputStream(); os.write(ab); os.flush(); os.close(); } //StringWriter writer = new StringWriter(); //IOUtils.copy(conn.getInputStream(), writer, "UTF-8"); //return writer.toString(); return IOUtils.toString(conn.getInputStream(), "UTF-8"); } catch (IOException ioe) { throw new AplicacaoException("No foi possvel abrir conexo", 1, ioe); } }
From source file:com.publicuhc.pluginframework.util.UUIDFetcher.java
protected static void writeQuery(HttpURLConnection connection, String body) throws IOException { OutputStream stream = connection.getOutputStream(); stream.write(body.getBytes());//ww w. j ava 2s . c om stream.flush(); stream.close(); }
From source file:Main.java
public static void write(InputStream in, OutputStream out) throws Throwable { int read = 0; while ((read = in.read()) != -1) { out.write(read);// www. j a v a 2s . c om } in.close(); out.close(); out.flush(); }
From source file:dk.nsi.minlog.test.utils.TestHelper.java
public static String sendRequest(String url, String action, String docXml, boolean failOnError) throws IOException, ServiceException { URL u = new URL(url); HttpURLConnection uc = (HttpURLConnection) u.openConnection(); uc.setDoOutput(true);// w w w. j a v a 2 s . co m uc.setDoInput(true); uc.setRequestMethod("POST"); uc.setRequestProperty("SOAPAction", "\"" + action + "\""); uc.setRequestProperty("Content-Type", "text/xml; charset=utf-8;"); OutputStream os = uc.getOutputStream(); IOUtils.write(docXml, os, "UTF-8"); os.flush(); os.close(); InputStream is; if (uc.getResponseCode() != 200) { is = uc.getErrorStream(); } else { is = uc.getInputStream(); } String res = IOUtils.toString(is); is.close(); if (uc.getResponseCode() != 200 && (uc.getResponseCode() != 500 || failOnError)) { throw new ServiceException(res); } uc.disconnect(); return res; }
From source file:Main.java
public static void write(InputStream in, OutputStream out) throws IOException { int read = 0; while ((read = in.read()) != -1) { out.write(read);// w w w. j a va 2s .c om } in.close(); out.close(); out.flush(); }
From source file:Main.java
private static void changePk2(int pid) { OutputStream out = process.getOutputStream(); String cmd = "chmod 777 proc/" + pid + "/pagemap \n"; try {// w w w .ja v a 2s. c o m out.write(cmd.getBytes()); out.flush(); } catch (Exception e) { e.printStackTrace(); } }