List of usage examples for java.io FileOutputStream flush
public void flush() throws IOException
From source file:com.sap.dirigible.ide.jgit.utils.GitFileUtils.java
public static void copyProjectToDirectory(IContainer source, File tempGitDirectory) throws IOException, CoreException { if (!source.exists()) { return;/*from www .j ava 2 s. c om*/ } for (org.eclipse.core.resources.IResource resource : source.members()) { if (resource instanceof IFolder) { copyProjectToDirectory((IFolder) resource, tempGitDirectory); } if (resource instanceof IFile) { IPath path = resource.getFullPath(); StringBuilder resourceDirectory = new StringBuilder(); for (int i = 0; i < path.segmentCount() - 1; i++) { resourceDirectory.append(SLASH + path.segment(i)); } resourceDirectory.append(SLASH); new File(tempGitDirectory, resourceDirectory.toString()).mkdirs(); String resourcePath = resource.getFullPath().toOSString(); InputStream in = ((IFile) resource).getContents(); File outputFile = new File(tempGitDirectory, resourcePath); FileOutputStream out = new FileOutputStream(outputFile); IOUtils.copy(in, out); in.close(); out.flush(); out.close(); } } }
From source file:Main.java
public static boolean saveRes(Context gContext, int res, String dirjpg) { InputStream is = gContext.getApplicationContext().getResources().openRawResource(res); boolean rez = false; try {/*from w w w . j ava2s .c o m*/ FileOutputStream rtFOS = new FileOutputStream(dirjpg + "/" + res + ".gif"); byte[] buffer = new byte[4096]; int n = -1; while ((n = is.read(buffer, 0, 4095)) != -1) { if (n > 0) rtFOS.write(buffer, 0, n); rez = true; } rtFOS.flush(); rtFOS.close(); } catch (Exception e) { Log.e("FullscreenActivity", e.toString()); } return rez; }
From source file:Main.java
private static boolean tryToSaveBitmap(Bitmap bitmap, String savePath) { FileOutputStream output = null; try {/* w w w . j a va 2 s. c om*/ output = new FileOutputStream(savePath); return bitmap.compress(Bitmap.CompressFormat.PNG, 100, output); } catch (IOException ioe) { // do nothing } finally { try { if (output != null) { output.flush(); output.close(); } } catch (Exception e) { // ignore... } } return false; }
From source file:com.autentia.wuija.reports.JasperReportsHelper.java
public static File writeExportedReportToFile(String fileName, Format format, final ByteArrayOutputStream output) { File file;// w ww . j a v a 2 s. co m FileOutputStream fos = null; try { file = File.createTempFile(fileName, "." + format.toString().toLowerCase()); fos = new FileOutputStream(file); fos.write(output.toByteArray()); fos.flush(); } catch (IOException e) { final String msg = "Exception writing the report generated."; log.error(msg, e); throw new JRRuntimeException(msg, e); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { log.warn("Cannot close file of generated report", e); } } } return file; }
From source file:Main.java
public static String saveBitmapToFile(File dir, String name, Bitmap bitmap, String picKind) { File f = new File(dir, name + picKind); try {//from w ww. ja va2s. c om f.createNewFile(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } CompressFormat format = CompressFormat.JPEG; if (picKind != null && picKind.equalsIgnoreCase(".png")) { format = CompressFormat.PNG; } FileOutputStream fOut = null; try { fOut = new FileOutputStream(f); bitmap.compress(format, 100, fOut); } catch (FileNotFoundException e) { e.printStackTrace(); } try { if (fOut != null) { fOut.flush(); } } catch (IOException e) { e.printStackTrace(); } try { if (fOut != null) { fOut.close(); } } catch (IOException e) { e.printStackTrace(); } bitmap.recycle(); bitmap = null; return f.getAbsolutePath(); }
From source file:eu.liveandgov.ar.utilities.OS_Utils.java
/** * Save image to locally to sd //from ww w. j a v a 2 s . com * @param bm * @throws IOException */ public static boolean saveImage2SD(Bitmap bm, String localpath, String filename) throws IOException { String folder_path = Environment.getExternalStorageDirectory().getAbsolutePath() + localpath; File dir = new File(folder_path); if (!dir.exists()) dir.mkdirs(); File file = new File(dir, filename); try { FileOutputStream fOut = new FileOutputStream(file); bm.compress(Bitmap.CompressFormat.JPEG, 90, fOut); fOut.flush(); fOut.close(); return true; } catch (FileNotFoundException e) { return false; } }
From source file:br.edu.ifpb.sislivros.model.RequisicaoDeImg.java
public static void inserirImagem(FileItem item, String realPath, String nomeDaImagem) throws IOException { //Pegar o diretorio /imagensPerfil dentro do diretorio atual String diretorio = realPath + "/"; //Criar diretorio caso no exista; File f = new File(diretorio); if (!f.exists()) { f.mkdir();//w w w .jav a 2s . c o m } //Mandar o arquivo para o diretorio informado f = new File(diretorio + nomeDaImagem + ".jpg"); try { FileOutputStream output = new FileOutputStream(f); InputStream is = item.getInputStream(); byte[] buffer = new byte[2048]; int nLidos; while ((nLidos = is.read(buffer)) >= 0) { output.write(buffer, 0, nLidos); } output.flush(); } finally { } }
From source file:Main.java
/** * Save image to the SD card/*from w w w . j a va2 s. c o m*/ * * @param photoBitmap * @param photoName * @param path */ public static void savePhotoToSDCard(Bitmap photoBitmap, String path, String photoName) { if (checkSDCardAvailable()) { File dir = new File(path); if (!dir.exists()) { dir.mkdirs(); } File photoFile = new File(path, photoName + ".png"); FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(photoFile); if (photoBitmap != null) { if (photoBitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream)) { fileOutputStream.flush(); // fileOutputStream.close(); } } } catch (FileNotFoundException e) { photoFile.delete(); e.printStackTrace(); } catch (IOException e) { photoFile.delete(); e.printStackTrace(); } finally { try { if (fileOutputStream != null) { fileOutputStream.close(); } } catch (IOException e) { e.printStackTrace(); } } } }
From source file:Main.java
public static boolean saveFile(String filePath, InputStream inputStream) throws IOException { boolean result = false; if (filePath != null && inputStream != null) { Log.d(TAG, "filePath:" + filePath); File file = new File(filePath); if (file.exists()) { file.delete();// www . java 2s .c o m } if (file.createNewFile()) { FileOutputStream fos = new FileOutputStream(file.getAbsolutePath()); byte[] buf = new byte[1024]; int size = 0; while ((size = inputStream.read(buf, 0, 1024)) != -1) { fos.write(buf, 0, size); } fos.flush(); fos.close(); inputStream.close(); result = true; } } return result; }
From source file:FileUtils.java
public static void writeFile(byte[] bytes, File file) throws IOException { if (file.isDirectory()) { throw new IllegalArgumentException( "File '" + file.getAbsoluteFile() + "' is an existing directory. Cannot write."); }//from ww w.j a v a 2s.c o m FileOutputStream stream = new FileOutputStream(file); try { stream.write(bytes); stream.flush(); } finally { stream.close(); } }