List of usage examples for java.io FileOutputStream flush
public void flush() throws IOException
From source file:com.meltmedia.cadmium.core.FileSystemManager.java
public static void copyAllContent(final String source, final String target, final boolean ignoreHidden) throws Exception { File sourceFile = new File(source); File targetFile = new File(target); if (!targetFile.exists()) { targetFile.mkdirs();/*from w ww . j ava 2s. co m*/ } if (sourceFile.exists() && sourceFile.canRead() && sourceFile.isDirectory() && targetFile.exists() && targetFile.canWrite() && targetFile.isDirectory()) { List<File> copyList = new ArrayList<File>(); FilenameFilter filter = new FilenameFilter() { @Override public boolean accept(File file, String name) { return !ignoreHidden || !name.startsWith("."); } }; File files[] = sourceFile.listFiles(filter); if (files.length > 0) { copyList.addAll(Arrays.asList(files)); } for (int index = 0; index < copyList.size(); index++) { File aFile = copyList.get(index); String relativePath = aFile.getAbsoluteFile().getAbsolutePath() .replaceFirst(sourceFile.getAbsoluteFile().getAbsolutePath(), ""); if (aFile.isDirectory()) { File newDir = new File(target, relativePath); if (newDir.mkdir()) { newDir.setExecutable(aFile.canExecute(), false); newDir.setReadable(aFile.canRead(), false); newDir.setWritable(aFile.canWrite(), false); newDir.setLastModified(aFile.lastModified()); files = aFile.listFiles(filter); if (files.length > 0) { copyList.addAll(index + 1, Arrays.asList(files)); } } else { log.warn("Failed to create new subdirectory \"{}\" in the target path \"{}\".", relativePath, target); } } else { File newFile = new File(target, relativePath); if (newFile.createNewFile()) { FileInputStream inStream = null; FileOutputStream outStream = null; try { inStream = new FileInputStream(aFile); outStream = new FileOutputStream(newFile); streamCopy(inStream, outStream); } finally { if (inStream != null) { try { inStream.close(); } catch (Exception e) { } } if (outStream != null) { try { outStream.flush(); } catch (Exception e) { } try { outStream.close(); } catch (Exception e) { } } } newFile.setExecutable(aFile.canExecute(), false); newFile.setReadable(aFile.canRead(), false); newFile.setWritable(aFile.canWrite(), false); newFile.setLastModified(aFile.lastModified()); } } } } }
From source file:com.lohika.alp.reporter.fe.logs.LogStorageFS.java
@Override public void saveLog(long testMethodId, String name, InputStream is) throws IOException { File testMethodDir = getTestMethodDir(testMethodId); if (!testMethodDir.exists()) testMethodDir.mkdirs();/*from www .j a v a2 s .co m*/ File logfile = new File(testMethodDir, name); FileOutputStream os = new FileOutputStream(logfile); int c; while ((c = is.read()) != -1) os.write(c); os.flush(); os.close(); }
From source file:be.ehb.restservermetdatabase.webservice.GameController.java
public String setImg(String img, String name) { try {//from ww w . j a va 2 s . co m byte[] btDataFile = new sun.misc.BASE64Decoder().decodeBuffer(img.split(",")[1]); File of = new File("game_" + name + ".png"); FileOutputStream osf = new FileOutputStream(of); osf.write(btDataFile); osf.flush(); osf.close(); return of.getPath(); } catch (IOException ex) { Logger.getLogger(GameController.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:com.baidu.rigel.biplatform.tesseract.util.FileUtils.java
/** * ???//www . j ava 2s . c om * * @param oldFile * * @param newFile * * @return * @throws IOException */ public static boolean copyFile(File oldFile, File newFile) { FileInputStream fileInputStream = null; FileOutputStream fileOutputStream = null; try { fileInputStream = new FileInputStream(oldFile); fileOutputStream = new FileOutputStream(newFile); byte[] buf = new byte[1024]; int len = 0; // ?? while ((len = fileInputStream.read(buf)) != -1) { fileOutputStream.write(buf, 0, len); fileOutputStream.flush(); } return true; } catch (IOException e) { LOGGER.error(e.getMessage(), e); return false; } finally { try { if (fileInputStream != null) { fileInputStream.close(); } if (fileOutputStream != null) { fileOutputStream.close(); } } catch (IOException e) { LOGGER.error(e.getMessage(), e); } } }
From source file:com.ikon.extractor.OOTextExtractor.java
/** * {@inheritDoc}/*www . j a v a 2 s . c om*/ */ public Reader extractText(InputStream stream, String type, String encoding) throws IOException { String ret = ""; File fIn = File.createTempFile("okm", ".doc"); File fOut = File.createTempFile("okm", ".txt"); try { FileOutputStream fos = new FileOutputStream(fIn); IOUtils.copy(stream, fos); fos.flush(); fos.close(); // Convert to text DocConverter.getInstance().convert(fIn, type, fOut); ret = FileUtils.readFileToString(fOut); log.debug("TEXT: " + ret); return new StringReader(ret); } catch (ConversionException e) { log.warn("Failed to extract text", e); return new StringReader(""); } finally { stream.close(); fIn.delete(); fOut.delete(); } }
From source file:be.ehb.restservermetdatabase.webservice.AchievementController.java
public String setImg(String img, String name) { try {/*from w ww. j a va2 s .com*/ byte[] btDataFile = new sun.misc.BASE64Decoder().decodeBuffer(img.split(",")[1]); File of = new File("achievement_" + name + ".png"); FileOutputStream osf = new FileOutputStream(of); osf.write(btDataFile); osf.flush(); osf.close(); return of.getPath(); } catch (IOException ex) { Logger.getLogger(GameController.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:be.ehb.restservermetdatabase.webservice.AvatarController.java
public String setImg(String img, String name) { try {/*from w w w . j av a 2s . c o m*/ byte[] btDataFile = new sun.misc.BASE64Decoder().decodeBuffer(img.split(",")[1]); File of = new File("avatar_" + name + ".png"); FileOutputStream osf = new FileOutputStream(of); osf.write(btDataFile); osf.flush(); osf.close(); return of.getPath(); } catch (IOException ex) { Logger.getLogger(GameController.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:gate.CorpusExporter.java
/** * Equivalent to {@link #export(Corpus,OutputStream,FeatureMap)} using a * FileOutputStream instance constructed from the File param. */// w ww . j a v a 2s .c om public void export(Corpus corpus, File file, FeatureMap options) throws IOException { FileOutputStream out = null; try { out = new FileOutputStream(file); export(corpus, new FileOutputStream(file), options); out.flush(); } finally { IOUtils.closeQuietly(out); } }
From source file:com.alibaba.intl.goldroom.util.ImageUtilImpl.java
public String save(String isbn, String suffix, byte[] body) { String dirPath = uploadPath + isbnTopath(isbn); File dir = new File(dirPath); if (!dir.exists()) dir.mkdirs();/*from w w w.j a va 2 s.c o m*/ StringBuilder imgPath = new StringBuilder(dirPath); imgPath.append(isbn).append(suffix); File imageFile = new File(imgPath.toString()); FileOutputStream fos = null; try { fos = new FileOutputStream(imageFile); fos.write(body); fos.flush(); } catch (IOException e) { return null; } finally { try { if (fos != null) fos.close(); } catch (IOException e) { } } return isbnToHttpPath(isbn, suffix); }
From source file:net.sourceforge.floggy.persistence.pool.DirectoryOutputPool.java
private void write(InputStream in, File file) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(in, baos);/*from ww w . j ava 2 s . c o m*/ baos.flush(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); FileOutputStream out = new FileOutputStream(file); IOUtils.copy(bais, out); out.flush(); out.close(); in.close(); }