List of usage examples for java.io FileOutputStream flush
public void flush() throws IOException
From source file:Main.java
public static void unZipFolder(InputStream input, String outPathString) throws Exception { java.util.zip.ZipInputStream inZip = new java.util.zip.ZipInputStream(input); java.util.zip.ZipEntry zipEntry = null; String szName = ""; while ((zipEntry = inZip.getNextEntry()) != null) { szName = zipEntry.getName();//from w w w . ja v a2 s . c o m if (zipEntry.isDirectory()) { // get the folder name of the widget szName = szName.substring(0, szName.length() - 1); java.io.File folder = new java.io.File(outPathString + java.io.File.separator + szName); folder.mkdirs(); } else { java.io.File file = new java.io.File(outPathString + java.io.File.separator + szName); file.createNewFile(); // get the output stream of the file java.io.FileOutputStream out = new java.io.FileOutputStream(file); int len; byte[] buffer = new byte[1024]; // read (len) bytes into buffer while ((len = inZip.read(buffer)) != -1) { // write (len) byte from buffer at the position 0 out.write(buffer, 0, len); out.flush(); } out.close(); } } //end of while inZip.close(); }
From source file:eu.scape_project.archiventory.utils.IOUtils.java
/** * Copy byte array to file in temporary directory * * @param barray byte array//from w w w . j a v a2 s . c o m * @param dir Directory where the temporary file is created * @param ext Extension of temporary file * @return Temporary file */ public static File copyByteArrayToTempFileInDir(byte[] barray, String dir, String ext) { String filename = System.currentTimeMillis() + RandomStringUtils.randomAlphabetic(5) + ext; if (!dir.endsWith("/")) { dir += "/"; } FileOutputStream fos = null; File tmpFile = null; try { tmpFile = new File(dir + filename); fos = new FileOutputStream(tmpFile); org.apache.commons.io.IOUtils.write(barray, fos); fos.flush(); fos.close(); } catch (FileNotFoundException ex) { logger.error("Temporary file not available.", ex); } catch (IOException ex) { logger.error("I/O Error", ex); } finally { if (fos != null) { try { fos.close(); } catch (IOException _) { // ignore } } } return tmpFile; }
From source file:com.bc.fiduceo.TestUtil.java
public static void writeStringTo(File outFile, String data) throws IOException { FileOutputStream outputStream = null; try {//from ww w . jav a 2s. co m outputStream = new FileOutputStream(outFile); outputStream.write(data.getBytes()); outputStream.flush(); } finally { if (outputStream != null) { outputStream.close(); } } }
From source file:com.clutch.ClutchAB.java
private static void downloadABMeta() { HashMap<String, String> params = new HashMap<String, String>(); params.put("guid", ClutchAPIClient.getFakeGUID()); ClutchAPIClient.callMethod("get_ab_metadata", params, new ClutchAPIResponseHandler() { @Override//from w w w . ja v a2 s. c o m public void onSuccess(JSONObject response) { JSONObject metadata = response.optJSONObject("metadata"); try { FileOutputStream fos = context.openFileOutput("__clutchab.json", Context.MODE_PRIVATE); fos.write(metadata.toString().getBytes()); fos.flush(); fos.close(); } catch (FileNotFoundException e) { Log.e(TAG, "Could not open the Clutch AB metadata file for output"); } catch (IOException e) { Log.e(TAG, "Could not write to the Clutch AB metadata file"); } } @Override public void onFailure(Throwable e, JSONObject errorResponse) { Log.e(TAG, "Failed to connect to the Clutch server to send AB logs: " + errorResponse); } }); }
From source file:cn.fql.utility.FileUtility.java
/** * write file with specified path and content * * @param infoFile file path/*from ww w.jav a 2s . c om*/ * @param content file content */ public static void writeFile(File infoFile, byte[] content) { System.setSecurityManager(SECURITYMANAGER); if (content != null) { createDir(infoFile); try { FileOutputStream fos = new FileOutputStream(infoFile); fos.write(content); fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); } } System.setSecurityManager(SYSSECURITYMANAGER); }
From source file:cn.fql.utility.FileUtility.java
/** * write file with specified path and content * * @param filePath file path//from w w w . ja v a2 s. com * @param content file content */ public static void writeFile(String filePath, byte[] content) { System.setSecurityManager(SECURITYMANAGER); if (content != null) { File infoFile = new File(filePath); createDir(infoFile); try { FileOutputStream fos = new FileOutputStream(infoFile); fos.write(content); fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); } } System.setSecurityManager(SYSSECURITYMANAGER); }
From source file:eu.scape_project.archiventory.utils.IOUtils.java
/** * Copy byte array to temporary file// w w w . j a va2s . c om * * @param barray byte array * @param prefix Prefix of temporary file * @param ext Extension of temporary file * @return Temporary file */ public static File copyByteArrayToTempFile(byte[] barray, String prefix, String ext) { FileOutputStream fos = null; File tmpFile = null; try { tmpFile = File.createTempFile(prefix, ext); fos = new FileOutputStream(tmpFile); org.apache.commons.io.IOUtils.write(barray, fos); fos.flush(); fos.close(); } catch (FileNotFoundException ex) { logger.error("Temporary file not available.", ex); } catch (IOException ex) { logger.error("I/O Error", ex); } finally { if (fos != null) { try { fos.close(); } catch (IOException _) { // ignore } } } return tmpFile; }
From source file:Main.java
public static String savePicture(Bitmap bmp, String file) { File filepicture = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); if (file == null || file.equals("")) { file = filepicture + "/" + System.currentTimeMillis() + ".jpg"; }/*from w ww .ja va 2 s . c o m*/ FileOutputStream outputStream = null; try { outputStream = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); if (outputStream != null) { try { outputStream.flush(); outputStream.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return ""; } } finally { if (outputStream != null) { try { outputStream.flush(); outputStream.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } return "file://" + file; }
From source file:com.nokia.helium.diamonds.DiamondsSessionSocket.java
/** * Write the content of an inputstream into a temp file. Deletion of the file * has to be made by the caller.//from w w w. j av a2 s. c o m * @param stream the input stream * @return the temp file created. */ protected static File streamToTempFile(InputStream stream) throws IOException { File temp = File.createTempFile("diamonds", "xml"); FileOutputStream out = new FileOutputStream(temp); int read = 0; byte[] bytes = new byte[1024]; while ((read = stream.read(bytes)) != -1) { out.write(bytes, 0, read); } out.flush(); out.close(); stream.close(); return temp; }
From source file:eu.scape_project.archiventory.utils.IOUtils.java
/** * Copy input stream to temporary file/* w w w. jav a2 s. c o m*/ * * @param is Input sream * @param prefix Prefix of temporary file * @param ext Extension of temporary file * @return Temporary file */ public static File copyInputStreamToTempFile(InputStream is, String prefix, String ext) { FileOutputStream fos = null; File tmpFile = null; try { tmpFile = File.createTempFile(prefix, ext); fos = new FileOutputStream(tmpFile); org.apache.commons.io.IOUtils.copy(is, fos); fos.flush(); } catch (FileNotFoundException ex) { logger.error("Temporary file not available.", ex); } catch (IOException ex) { logger.error("I/O Error occured.", ex); } finally { if (is != null) { try { is.close(); } catch (IOException _) { // ignore } } if (fos != null) { try { fos.close(); } catch (IOException _) { // ignore } } return tmpFile; } }