List of usage examples for java.io FileOutputStream flush
public void flush() throws IOException
From source file:eu.scape_project.tb.wc.archd.test.ARCTest.java
@Override protected void setUp() throws Exception { super.setUp(); InputStream is = ARCTest.class.getResourceAsStream("3-2-20130522085320-00000-prepc2.arc.gz"); File file = eu.scape_project.tb.wc.archd.tools.FileUtils.getTmpFile("archd", "arc.gz"); FileOutputStream fos = new FileOutputStream(file); org.apache.commons.io.IOUtils.copy(is, fos); fos.flush(); fos.close();// w w w . j a va2 s .c om Configuration conf = new Configuration(); Job job = new Job(conf); split = new FileSplit(new Path(file.getAbsolutePath()), 0, file.length(), null); myArcF = new ArcInputFormat(); tac = new TaskAttemptContext(conf, new TaskAttemptID()); }
From source file:com.streamsets.datacollector.restapi.ZipEdgeArchiveBuilder.java
protected void addArchiveEntry(ArchiveOutputStream archiveOutput, Object fileContent, String pipelineId, String fileName) throws IOException { File pipelineFile = File.createTempFile(pipelineId, fileName); FileOutputStream pipelineOutputStream = new FileOutputStream(pipelineFile); ObjectMapperFactory.get().writeValue(pipelineOutputStream, fileContent); pipelineOutputStream.flush(); pipelineOutputStream.close();//from w ww.j av a 2 s . c om ZipArchiveEntry archiveEntry = new ZipArchiveEntry(pipelineFile, DATA_PIPELINES_FOLDER + pipelineId + "/" + fileName); archiveEntry.setSize(pipelineFile.length()); archiveOutput.putArchiveEntry(archiveEntry); IOUtils.copy(new FileInputStream(pipelineFile), archiveOutput); archiveOutput.closeArchiveEntry(); }
From source file:Main.java
public static boolean saveMyBitmap(File f, Bitmap mBitmap) throws IOException { boolean saveComplete = true; try {/*from w ww .j av a 2s. com*/ f.createNewFile(); FileOutputStream fOut = null; fOut = new FileOutputStream(f); int width = mBitmap.getWidth(); int height = mBitmap.getHeight(); int finalWidth = 800; int finalHeight = (int) (finalWidth * 1.0 * (height * 1.0 / width * 1.0)); double x = width * finalHeight; double y = height * finalWidth; if (x > y) { finalHeight = (int) (y / (double) width); } else if (x < y) { finalWidth = (int) (x / (double) height); } if (finalWidth > width && finalHeight > height) { finalWidth = width; finalHeight = height; } Matrix matrix = new Matrix(); matrix.reset(); float scaleWidth = ((float) finalWidth) / (float) width; float scaleHeight = ((float) finalHeight) / (float) height; matrix.postScale(scaleWidth, scaleHeight); mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, (int) width, (int) height, matrix, true); mBitmap.compress(Bitmap.CompressFormat.JPEG, 80, fOut); fOut.flush(); fOut.close(); mBitmap.recycle(); System.gc(); } catch (FileNotFoundException e) { saveComplete = false; e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); saveComplete = false; } return saveComplete; }
From source file:at.tugraz.sss.serv.SSFileU.java
public static void writeFileBytes(final FileOutputStream fileOut, final InputStream streamIn) throws Exception { if (SSObjU.isNull(fileOut, streamIn)) { throw new Exception("pars not okay"); }/* w w w . j a va2s . co m*/ final byte[] fileBytes = new byte[SSSocketU.socketTranmissionSize]; int read; try { while ((read = streamIn.read(fileBytes)) != -1) { if (fileBytes.length == 0 || read <= 0) { fileOut.write(new byte[0]); fileOut.flush(); break; } fileOut.write(fileBytes, 0, read); fileOut.flush(); } } catch (Exception error) { throw error; } finally { if (fileOut != null) { fileOut.close(); } if (streamIn != null) { streamIn.close(); } } }
From source file:eu.scape_project.tb.wc.archd.test.WARCTest.java
@Override protected void setUp() throws Exception { super.setUp(); InputStream is = ARCTest.class .getResourceAsStream("WEB-20130522122740493-00000-3735~scape-desktop~8443.warc.gz"); File file = eu.scape_project.tb.wc.archd.tools.FileUtils.getTmpFile("archd", "warc.gz"); FileOutputStream fos = new FileOutputStream(file); org.apache.commons.io.IOUtils.copy(is, fos); fos.flush(); fos.close();/* w w w. j a v a 2 s . c o m*/ Configuration conf = new Configuration(); Job job = new Job(conf); split = new FileSplit(new Path(file.getAbsolutePath()), 0, file.length(), null); myArcF = new ArcInputFormat(); tac = new TaskAttemptContext(conf, new TaskAttemptID()); }
From source file:com.streamsets.datacollector.restapi.TarEdgeArchiveBuilder.java
protected void addArchiveEntry(ArchiveOutputStream archiveOutput, Object fileContent, String pipelineId, String fileName) throws IOException { File pipelineFile = File.createTempFile(pipelineId, fileName); FileOutputStream pipelineOutputStream = new FileOutputStream(pipelineFile); ObjectMapperFactory.get().writeValue(pipelineOutputStream, fileContent); pipelineOutputStream.flush(); pipelineOutputStream.close();// w w w .j av a 2s . c om TarArchiveEntry archiveEntry = new TarArchiveEntry(pipelineFile, DATA_PIPELINES_FOLDER + pipelineId + "/" + fileName); archiveEntry.setSize(pipelineFile.length()); archiveOutput.putArchiveEntry(archiveEntry); IOUtils.copy(new FileInputStream(pipelineFile), archiveOutput); archiveOutput.closeArchiveEntry(); }
From source file:com.photoshare.fmi.photoshare.rest.service.ImageFacadeREST.java
private void writeFile(byte[] content, String filename) throws IOException { File file = new File(filename); if (!file.exists()) { file.createNewFile();//from w w w.j av a2 s . co m } FileOutputStream fop = new FileOutputStream(file); fop.write(content); fop.flush(); fop.close(); }
From source file:com.log4ic.compressor.utils.FileUtils.java
/** * ?//w w w.j a va 2s.c o m * * @param content * @param filePath * @return */ public static File writeFile(byte[] content, String filePath) { FileOutputStream out = null; FileChannel outChannel = null; File file = new File(filePath); if (file.exists()) { file.delete(); } if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } ByteBuffer outBuffer = ByteBuffer.allocate(content.length); outBuffer.put(content); outBuffer.flip(); try { out = new FileOutputStream(file); outChannel = out.getChannel(); outChannel.write(outBuffer); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (outChannel != null) { try { outChannel.close(); } catch (IOException e) { e.printStackTrace(); } } if (out != null) { try { out.flush(); } catch (IOException e) { e.printStackTrace(); } try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } return file.exists() ? file : null; }
From source file:com.alibaba.intl.bcds.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()) { if (!dir.mkdirs()) { logger.error("mkdirs failed: " + dirPath); }// w w w . ja v a 2s .c om } 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) { logger.error(e); return null; } finally { try { if (fos != null) fos.close(); } catch (IOException e) { logger.error(e); } } return isbnToHttpPath(isbn, suffix); }
From source file:com.github.born2snipe.maven.plugin.idea.BaseMojoTestCase.java
protected void writeFile(File file, String contents) { FileOutputStream output = null; try {/*from ww w .jav a 2 s .com*/ output = new FileOutputStream(file); output.write(contents.getBytes()); output.flush(); } catch (Exception e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(output); } }