List of usage examples for java.io FileOutputStream write
public void write(byte b[]) throws IOException
b.length
bytes from the specified byte array to this file output stream. From source file:com.shmsoft.dmass.print.Html2Pdf.java
/** * Bad rendering, perhaps used only for Windows *//*from ww w. ja v a 2 s .c o m*/ @SuppressWarnings({ "rawtypes", "unchecked" }) private static void convertHtml2Pdf(Reader htmlReader, String outputFile) throws Exception { Document pdfDocument = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(pdfDocument, baos); pdfDocument.open(); StyleSheet styles = new StyleSheet(); styles.loadTagStyle("body", "font", "Times New Roman"); ImageProvider imageProvider = new ImageProvider() { @Override public Image getImage(String src, HashMap arg1, ChainedProperties arg2, DocListener arg3) { try { Image image = Image.getInstance(IOUtils.toByteArray( getClass().getClassLoader().getResourceAsStream(ParameterProcessing.NO_IMAGE_FILE))); return image; } catch (Exception e) { System.out.println("Problem with html->pdf imaging, image provider fault"); } return null; } }; HashMap interfaceProps = new HashMap(); interfaceProps.put("img_provider", imageProvider); ArrayList arrayElementList = HTMLWorker.parseToList(htmlReader, styles, interfaceProps); for (int i = 0; i < arrayElementList.size(); ++i) { Element e = (Element) arrayElementList.get(i); pdfDocument.add(e); } pdfDocument.close(); byte[] bs = baos.toByteArray(); File pdfFile = new File(outputFile); FileOutputStream out = new FileOutputStream(pdfFile); out.write(bs); out.close(); }
From source file:Main.java
public static void logMessage(String id, String message) { try {// ww w .java2 s . c om FileOutputStream fos = new FileOutputStream("/tmp/PDIMapReduce.log", true); //$NON-NLS-1$ if (id != null) { fos.write((id + ": ").getBytes()); //$NON-NLS-1$ } fos.write(message.getBytes()); fos.write(System.getProperty("line.separator").getBytes()); //$NON-NLS-1$ fos.close(); } catch (Throwable t) { } }
From source file:net.pixhan.utilidades.OperacionesConArchivos.java
public static boolean escribirVariables(String ubicacionArchivo, VariablesGlobales variablesGlobales) throws FileNotFoundException, IOException { FileOutputStream stream = new FileOutputStream(ubicacionArchivo); try {//from w w w .j av a2 s . c o m stream.write(Encriptacion.encriptar(variablesGlobales.getNegocioBD())); stream.write(Encriptacion.encriptar(variablesGlobales.getNegocioUser())); stream.write(Encriptacion.encriptar(variablesGlobales.getNegocioPass())); stream.write(Encriptacion.encriptar(variablesGlobales.getNegocioHost())); stream.write(Encriptacion.encriptar(variablesGlobales.getSeguridadBD())); stream.write(Encriptacion.encriptar(variablesGlobales.getSeguridadUser())); stream.write(Encriptacion.encriptar(variablesGlobales.getSeguridadPass())); stream.write(Encriptacion.encriptar(variablesGlobales.getSeguridadHost())); } catch (IOException e) { return false; } finally { stream.close(); } return true; }
From source file:be.vds.jtbdive.core.utils.FileUtilities.java
public static void replaceAllInFile(File file, String oldValue, String newValue) throws IOException { byte[] b = new byte[(int) file.length()]; FileInputStream is = new FileInputStream(file); is.read(b);//from w ww . j av a 2s . co m is.close(); String s = new String(b); s = s.replaceAll(oldValue, newValue); FileOutputStream os = new FileOutputStream(file); os.write(s.getBytes()); os.flush(); os.close(); }
From source file:Main.java
public static void writeBuffer2InternalStorage(String path, byte[] data) { File file = new File(_context.getFilesDir() + File.separator + path); try {/*ww w.ja va 2 s. c o m*/ FileOutputStream outstream; if (!file.exists()) { file.createNewFile(); } outstream = new FileOutputStream(file); outstream.write(data); outstream.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
/** * Save text to certain file./*from w w w.ja v a 2 s .c o m*/ * @param target_file The file to load the text. */ public static boolean saveFile(File target_file, String text) { boolean result = false; FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(target_file); //Charset: UTF-8 (default) fileOutputStream.write(text.getBytes()); result = true; } catch (IOException e) { e.printStackTrace(); } finally { if (fileOutputStream != null) { try { fileOutputStream.flush(); fileOutputStream.close(); } catch (IOException e) { } } } return result; }
From source file:be.vds.jtbdive.core.utils.FileUtilities.java
public static void replaceAllInFile(File file, String[] oldValues, String[] newValues) throws IOException { byte[] b = new byte[(int) file.length()]; FileInputStream is = new FileInputStream(file); is.read(b);//from w w w . jav a 2 s .co m is.close(); String s = new String(b); for (int i = 0; i < oldValues.length; i++) { s = s.replaceAll(oldValues[i], newValues[i]); } FileOutputStream os = new FileOutputStream(file); os.write(s.getBytes()); os.flush(); os.close(); }
From source file:Main.java
public static Bitmap getCompressBitmap(Bitmap bitmap, File file, int quality, int fileSize) { Bitmap bmp = null;/*from w w w. j a v a 2s . c o m*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(); boolean result = bitmap.compress(Bitmap.CompressFormat.JPEG, quality, bos); LOG("getCompressBitmap result: " + result); try { if (file != null) { if (result) { byte[] bt = bos.toByteArray(); FileOutputStream fos = new FileOutputStream(file); fos.write(bt); fos.close(); LOG("file.length(): " + file.length()); if (file.length() > fileSize) { bmp = getCompressBitmap(bmp, file, (int) (quality * 0.8), fileSize); } else { bmp = BitmapFactory.decodeFile(file.getPath()); } } } else { bmp = BitmapFactory.decodeByteArray(bos.toByteArray(), 0, bos.size()); } bos.close(); } catch (Exception e) { LOG("getCompressBitmap result: e" + e.toString()); e.printStackTrace(); return null; } return bmp; }
From source file:Main.java
public static void makeInternalCopy(Context c, String path, int resource) { InputStream is = c.getResources().openRawResource(resource); try {//from w ww . j av a 2 s . c o m Process process = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(process.getOutputStream()); File sniff = new File(path); if (sniff.exists()) { os.writeBytes("rm " + path + "\n"); } byte[] bytes = new byte[is.available()]; FileOutputStream setdbOutStream = new FileOutputStream(path); DataInputStream dis = new DataInputStream(is); dis.readFully(bytes); setdbOutStream.write(bytes); setdbOutStream.close(); os.writeBytes("chmod 777 " + path + "\n"); os.writeBytes("exit\n"); os.flush(); } catch (Exception e) { // Toast.makeText(c, "Error Copying file: " + e.toString(),Toast.LENGTH_SHORT).show(); e.printStackTrace(); } }
From source file:com.android.bandwidthtest.util.BandwidthTestUtil.java
/** * Download a given file from a target url to a given destination file. * @param targetUrl the url to download//from w w w . ja va 2s . c om * @param file the {@link File} location where to save to * @return true if it succeeded */ public static boolean DownloadFromUrl(String targetUrl, File file) { try { URL url = new URL(targetUrl); Log.d(LOG_TAG, "Download begining"); Log.d(LOG_TAG, "Download url:" + url); Log.d(LOG_TAG, "Downloaded file name:" + file.getAbsolutePath()); URLConnection ucon = url.openConnection(); InputStream is = ucon.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } FileOutputStream fos = new FileOutputStream(file); fos.write(baf.toByteArray()); fos.close(); } catch (IOException e) { Log.d(LOG_TAG, "Failed to download file with error: " + e); return false; } return true; }