List of usage examples for java.io FileOutputStream flush
public void flush() throws IOException
From source file:com.bean.ImagenLogica.java
public String guardarImagen() { File archivo = null;//from w ww . ja v a 2 s .c om InputStream in = null; String codUsuario = ""; String extension = ""; int i = 0; extension = "." + FilenameUtils.getExtension(this.getObjImagen().getImagen().getFileName()); codUsuario = String.valueOf(new SessionLogica().obtenerUsuarioSession().getCodUsuario()); try { in = this.getObjImagen().getImagen().getInputstream(); byte[] data = new byte[in.available()]; in.read(data); archivo = new File(this.rutaImgPerfil + codUsuario + extension); FileOutputStream out = new FileOutputStream(archivo); out.write(data); System.out.println("Ruta de Path Absolute"); System.out.println(archivo.getAbsolutePath()); in.close(); out.flush(); out.close(); Usuario obj = new SessionLogica().obtenerUsuarioSession(); obj.getObjPerfil().setImagenPer(codUsuario + extension); new SessionLogica().setUsuarioSession(obj); new PerfilLogica().actualizarImagenPerfil(obj); } catch (IOException ex) { System.out.println(ex.getMessage()); return "none.jpg"; } return codUsuario + extension; }
From source file:gr.forth.ics.isl.webservice.XPathsWebservice.java
/** * Write the file/*from www .j av a 2 s .c o m*/ * * @param content * @param filePath * @throws IOException */ private void writeFile(byte[] content, String filePath) throws IOException { File file = new File(filePath); if (!file.exists()) { file.createNewFile(); } FileOutputStream fop = new FileOutputStream(file); fop.write(content); fop.flush(); fop.close(); }
From source file:com.clough.android.adbv.manager.ADBManager.java
/** * Copying the file by the given file name from the source directory * to application's directory// ww w . ja v a2 s.c o m * @param sourceFilePath Source file path depending on the OS * @param fileName Name of the file in the sourceFilePath to be copied * @return Absolute file path to the copied file * @throws IOException * @throws ADBManagerException */ private String copyAssets(String sourceFilePath, String fileName) throws IOException, ADBManagerException { File out = new File(APPLICATION_FILE, fileName); if (!out.exists()) { InputStream fis = Launcher.class.getResourceAsStream(sourceFilePath + fileName); if (fis != null) { FileOutputStream fos = new FileOutputStream(out); int read; while ((read = fis.read()) != -1) { fos.write(read); } fos.flush(); fis.close(); fos.close(); } } if (!out.setExecutable(true)) { throw new ADBManagerException("Copied ADB file couldn't make executable"); } return out.getAbsolutePath(); }
From source file:com.mvdb.etl.actions.ActionUtils.java
public static void zipFullDirectory(String sourceDir, String targetZipFile) { FileOutputStream fos = null; BufferedOutputStream bos = null; ZipOutputStream zos = null;//from ww w . j ava 2 s.c o m try { fos = new FileOutputStream(targetZipFile); bos = new BufferedOutputStream(fos); zos = new ZipOutputStream(bos); zipDir(sourceDir, new File(sourceDir), zos); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (zos != null) { try { zos.flush(); zos.close(); } catch (IOException e) { e.printStackTrace(); } } if (bos != null) { try { bos.flush(); bos.close(); } catch (IOException e) { e.printStackTrace(); } } if (fos != null) { try { fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.bskyb.cg.environments.hash.PersistentHash.java
private synchronized void appendEntryToStore(Message message) throws IOException { String filename = message.getKey(); File file = new File(dirname, filename); FileOutputStream fos = new FileOutputStream(file, true); BufferedOutputStream bos = new BufferedOutputStream(fos); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(message);// w w w . ja v a2 s . co m oos.flush(); oos.close(); fos.flush(); fos.close(); }
From source file:com.tesshu.subsonic.client.sample4_music_andmovie.BinaryDownloadApplication.java
@Bean protected CommandLineRunner run(RestTemplate restTemplate) throws Exception { return args -> { File tmpDirectory = new File(tmpPath); tmpDirectory.mkdir();// w w w . j a va2s . c om Optional<SearchResult2> result2 = search2.getOf("e", null, null, null, null, 1, null, null); result2.ifPresent(result -> result.getSongs().forEach(song -> { download.download(song, (subject, inputStream) -> { File dir = new File(tmpPath + "/" + song.getPath().replaceAll("([^/]+?)?$", StringUtils.EMPTY)); dir.mkdirs(); File file = new File(tmpPath + "/" + song.getPath()); try { FileOutputStream fos = new FileOutputStream(file); BufferedInputStream reader = new BufferedInputStream(inputStream); byte buf[] = new byte[256]; int len; while ((len = reader.read(buf)) != -1) { fos.write(buf, 0, len); } fos.flush(); fos.close(); reader.close(); inputStream.close(); } catch (IOException e) { e.printStackTrace(); } LOG.info(file.getAbsolutePath()); }, callback); })); tmpDirectory.deleteOnExit(); }; }
From source file:fr.simon.marquis.secretcodes.util.ExportContentProvider.java
private void saveImageFiles(ArrayList<SecretCode> secretCodes) { for (SecretCode secretCode : secretCodes) { try {/* ww w . j a v a 2 s . co m*/ if (secretCode.getDrawableResource() == 0) { continue; } Drawable drawable = getContext().getPackageManager().getDrawable(secretCode.getPackageManager(), secretCode.getDrawableResource(), null); if (drawable == null) { continue; } int height = drawable.getIntrinsicHeight(); int width = drawable.getIntrinsicWidth(); Bitmap createBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); if (createBitmap == null) { continue; } Canvas canvas = new Canvas(createBitmap); drawable.setBounds(0, 0, width, height); drawable.draw(canvas); FileOutputStream openFileOutput = getContext().openFileOutput(secretCode.getCode() + ".png", Context.MODE_PRIVATE); createBitmap.compress(Bitmap.CompressFormat.PNG, 100, openFileOutput); openFileOutput.flush(); openFileOutput.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.atomspace.pi2c.runtime.Server.java
/** * Unzip a InputStream to a File-Destination * @param src// ww w .j a v a2s . c o m * @param destination * @throws IOException */ private void unzip(InputStream src, File destination) throws IOException { FileOutputStream fos = new FileOutputStream(destination); int len = 0; byte[] buffer = new byte[16384]; while ((len = src.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.flush(); fos.close(); }
From source file:any.servable.VsetServable.java
@Override public void process(Message cmd, BlockingQueue<Message> outQueue) { if (cmd == null) { loopqueue = outQueue;/*from w ww . j av a2 s. c o m*/ } else { String filename = cmd.getContent(); currentfile = new File(res, filename); logger.debug(currentfile.getAbsolutePath()); FileOutputStream fw; try { fw = new FileOutputStream(currentfile); fw.write(cmd.getData()); fw.flush(); fw.close(); } catch (IOException e) { e.printStackTrace(); final Writer result = new StringWriter(); final PrintWriter printWriter = new PrintWriter(result); e.printStackTrace(printWriter); outQueue.add(new Message("vset", "_error", "text/plain", "YES", result.toString().getBytes())); } if (cmd.getFullContent().contains("show=YES")) { Display display = Display.getDefault(); display.syncExec(new Runnable() { public void run() { URL pageUrl = null; try { pageUrl = currentfile.toURI().toURL(); browser.setUrl(pageUrl.toString()); blockpage = false; } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } } }
From source file:eu.europa.ec.markt.dss.signature.StreamDocument.java
private void createTemporaryFileOfStream(InputStream stream) { logger.debug(""); byte[] bytes = new byte[MAX_SIZE_IN_MEMORY]; FileOutputStream out = null; try {/*from w ww . j a v a 2s . c o m*/ temporaryFile = File.createTempFile("digidoc4j", ".tmp"); out = new FileOutputStream(temporaryFile); int result; while ((result = stream.read(bytes)) > 0) { out.write(bytes, 0, result); } out.flush(); } catch (IOException e) { logger.error(e.getMessage()); throw new DSSException(e); } finally { IOUtils.closeQuietly(out); } }