List of usage examples for java.io FileOutputStream close
public void close() throws IOException
From source file:Main.java
public static boolean saveFile(Bitmap bitmap, String filename) { File sd = Environment.getExternalStorageDirectory(); File dest = new File(sd, filename); try {/*from w w w . java 2 s .co m*/ FileOutputStream out = new FileOutputStream(dest); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:net.ontopia.utils.EncryptionUtils.java
/** * INTERNAL: Reads in the infile and writes the encrypted result * into the outfile./*from w w w . j a v a 2s .co m*/ */ public static void encrypt(File infile, File outfile) throws IOException { FileInputStream in = new FileInputStream(infile); FileOutputStream out = new FileOutputStream(outfile); encrypt(in, out); in.close(); out.close(); }
From source file:Main.java
public static void saveBitmap(Bitmap bitmap, String filePath) { File f = new File(filePath); if (f.exists()) { return;//from w w w .j a va2s . c om } try { FileOutputStream out = new FileOutputStream(f); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); out.flush(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
/** Writes the given DOM to the specified file on disk. */ public static void writeXML(final File file, final Document doc) { try {//from w w w . ja v a 2 s . c o m final FileOutputStream out = new FileOutputStream(file); writeXML(out, doc); out.close(); } catch (final IOException exc) { exc.printStackTrace(); } }
From source file:Main.java
public static boolean compress(Bitmap bitmap, File outFile) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 35, baos); try {/* www . jav a2s . co m*/ FileOutputStream fileOutputStream = new FileOutputStream(outFile); fileOutputStream.write(baos.toByteArray()); fileOutputStream.close(); } catch (Exception e) { return false; } return true; }
From source file:ju.ehealthservice.graphs.RespRateGraphImage.java
public static boolean save(String fileName, String img) { try {//from w w w.j av a 2s . c o m StringBuffer data = new StringBuffer(img); data = new StringBuffer(data.substring(23)); int c = 0; for (int i = 0; i < data.length(); i++) { if (data.charAt(i) == ' ') { c++; data.setCharAt(i, '+'); } } byte[] imageByteArray = Base64.decodeBase64(data.toString()); String ID = fileName.substring(0, fileName.indexOf('_')); String path = Constants.GRAPH_REPOSITORY_PATH + ID + "\\RespRate\\"; fileName = fileName + ".jpg"; FileOutputStream imageOutFile = new FileOutputStream(path + fileName); imageOutFile.write(imageByteArray); imageOutFile.close(); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:Main.java
private static InputStream bitmap2InputStream(Context context, Bitmap bitmap) throws IOException { File file = new File(context.getFilesDir(), "wallpaper.jpg"); if (file.exists()) { file.delete();//from w ww.j a v a 2 s. com } file.createNewFile(); FileOutputStream fileOutputStream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fileOutputStream); fileOutputStream.close(); return filePath2InputStream(file.getAbsolutePath()); }
From source file:Main.java
public static void saveImage(String imagePath, byte[] buffer) throws IOException { File f = new File(imagePath); if (f.exists()) { return;//from w w w . j a v a2 s. c o m } else { File parentFile = f.getParentFile(); if (!parentFile.exists()) { parentFile.mkdirs(); } f.createNewFile(); FileOutputStream fos = new FileOutputStream(imagePath); fos.write(buffer); fos.flush(); fos.close(); } }
From source file:ju.ehealthservice.graphs.ECGGraphImage.java
public static boolean save(String fileName, String img) { try {//w w w . ja va2s . c om StringBuffer data = new StringBuffer(img); data = new StringBuffer(data.substring(23)); int c = 0; for (int i = 0; i < data.length(); i++) { if (data.charAt(i) == ' ') { c++; data.setCharAt(i, '+'); } } byte[] imageByteArray = Base64.decodeBase64(data.toString()); String ID = fileName.substring(0, fileName.indexOf('_')); String path = Constants.GRAPH_REPOSITORY_PATH + ID + "\\ECG\\"; fileName = fileName + ".jpg"; FileOutputStream imageOutFile = new FileOutputStream(path + fileName); imageOutFile.write(imageByteArray); imageOutFile.close(); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:org.apache.camel.example.SpringJmsClientServerTest.java
@BeforeClass public static void setupFreePort() throws Exception { // find a free port number, and write that in the custom.properties file // which we will use for the unit tests, to avoid port number in use problems int port = AvailablePortFinder.getNextAvailable(); String bank1 = "tcp.port=" + port; File custom = new File("target/custom.properties"); FileOutputStream fos = new FileOutputStream(custom); fos.write(bank1.getBytes());/*from w w w . j ava 2s.co m*/ fos.close(); }